-
Notifications
You must be signed in to change notification settings - Fork 723
Actions
Mottie edited this page May 11, 2011
·
24 revisions
##Add Action Keys
- Add a keyaction function (e.g.
$.keyboard.keyaction.test = function(base){};
) - Add a display option name update (optional) into the keyboard initialization options. In the example below, if you don't change the display name, the action key name will be "test"
- Add the new action key to your layout by simply wrapping the key name in curly brackets e.g. "{test}"
// Add a "test" keyaction
$.keyboard.keyaction.test = function(base){
alert('you smell like cheese');
};
$('#junk').keyboard({
layout: 'custom',
display: {
'test' : 'Cheese' // change the test keyaction displayed name to "Cheese"
},
customLayout: {
'default' : [
// {test} adds the keyaction key and displays the alert
// "test" will enter the text "test" into the input
'{test} test'
]
}
});
##Default Actions
- Any of the following keyaction functions can be modified as desired.
- I wouldn't recommend modifying the "alt", "shift" or "meta" functions. As they change the visible keyset, but I left it in here to show how to determine which keyset is active or to even switch them.
// Action key function list
$.keyboard.keyaction = {
accept : function(base){
base.close(true); // same as base.accept();
return false; // return false prevents further processing
},
alt : function(base,el){
base.altActive = !base.altActive;
base.metaActive = false;
base.showKeySet(el);
},
bksp : function(base){
base.insertText('bksp'); // the script looks for the "bksp" string and initiates a backspace
},
cancel : function(base){
base.close();
return false; // return false prevents further processing
},
clear : function(base){
base.$preview.val('');
},
combo : function(base){
var c = !base.options.useCombos;
base.options.useCombos = c;
base.$keyboard.find('.ui-keyboard-combo')[(c) ? 'addClass' : 'removeClass'](base.options.actionClass);
if (c) { base.checkCombos(); }
return false;
},
dec : function(base){
// base.decimal is true when using US "." or false for EU "," format
base.insertText((base.decimal) ? '.' : ',');
},
enter : function(base) {
if (base.el.tagName === 'INPUT') { return; } // ignore enter key in input
base.insertText('\r\n');
},
meta : function(base,el){
base.metaActive = ($(el).is('.' + base.options.actionClass)) ? false : true;
base.showKeySet(el);
},
shift : function(base,el){
base.shiftActive = !base.shiftActive;
base.metaActive = false;
base.showKeySet(el);
},
sign : function(base){
if(/^\-?\d*\.?\d*$/.test( base.$preview.val() )) {
base.$preview.val( (base.$preview.val() * -1) );
}
},
space : function(base){
base.insertText(' ');
},
tab : function(base) {
if (base.el.tagName === 'INPUT') { return; } // ignore tab key in input
base.insertText('\t');
}
};
Home | FAQ | Setup | Usage | Options | Methods | Contenteditable | Theme | Log
Options: Layout | Language | Usability | Actions
Extensions: AltKeysPopup | Autocomplete | Caret | Extender | Mobile | Navigation | PreviewKeySet | Scramble | Typing