diff --git a/Gruntfile.js b/Gruntfile.js index ea6c186..7eb6e1c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -45,4 +45,5 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-include-replace'); grunt.registerTask('build', ['includereplace', 'sass', 'uglify']); + grunt.registerTask('default', ['includereplace', 'sass', 'uglify']); }; diff --git a/demo.js b/demo.js index 10084bf..53c5b14 100644 --- a/demo.js +++ b/demo.js @@ -13,3 +13,11 @@ $(document).ready(function(){ $(document).ready(function(){ $('input#example-4').mlKeyboard({layout: 'it_IT', trigger: '#example-4-btn'}); }); + +$(document).ready(function(){ + $('input#example-5').mlKeyboard({layout: 'fr_FR', trigger: '#example-5-btn'}); +}); + +$(document).ready(function(){ + $('textarea#example-6').mlKeyboard({layout: 'pt_PT', trigger: '#example-6-btn'}); +}); diff --git a/docs/advanced_tutorial.md b/docs/advanced_tutorial.md index e112526..cf3d91c 100644 --- a/docs/advanced_tutorial.md +++ b/docs/advanced_tutorial.md @@ -128,6 +128,7 @@ From command line perform ```bash grunt ``` +> Remember to execute npm install after cloned the repository and now you can use your layout with diff --git a/index.html b/index.html index cf9e4e8..12d8c83 100644 --- a/index.html +++ b/index.html @@ -69,7 +69,8 @@

-

Cusom keyboard trigger button

+

Italian + (click vowels to select accents)

@@ -84,6 +85,41 @@

Cusom keyboard trigger button

+
+
+

French + (click vowels to select accents)

+ + +
+ + $('input#example-5').mlKeyboard({
+   layout: 'fr_FR',
+   trigger: '#example-5-btn'
+ }); +
+
+
+
+ +
+
+

Text Area + (click vowels to select accents)

+ + +
+ + $('textarea#example-6').mlKeyboard({
+   layout: 'pt_PT',
+   trigger: '#example-6-btn'
+ }); +
+
+
+
+
+
diff --git a/jquery.ml-keyboard.js b/jquery.ml-keyboard.js index f77f91b..920bf22 100644 --- a/jquery.ml-keyboard.js +++ b/jquery.ml-keyboard.js @@ -109,9 +109,10 @@ KeyTab.prototype = new Key(); KeyTab.prototype.constructor = KeyTab; KeyTab.prototype.defaultClickAction = function() { - // TODO: It's doesn't work if inputs has different parents - this.keyboard.$current_input.next(":input").focus(); + this.keyboard.hideKeyboard(); + $(":input").eq($(":input").index(this.keyboard.$current_input)+1).focus(); }; + function KeyCapsLock() { Key.call(this, arguments); @@ -174,7 +175,7 @@ KeySpace.prototype = new Key(); KeySpace.prototype.constructor = KeySpace; var KEYS_COUNT = 53; -function Keyboard(options){ +function Keyboard(selector, options){ this.defaults = { layout: 'en_US', active_shift: true, @@ -195,7 +196,7 @@ function Keyboard(options){ this.$keyboard = $("
").attr("id", "mlkeyboard"); this.$modifications_holder = $("
    ").addClass('mlkeyboard-modifications'); - this.$current_input = $("input[type='text']").first(); + this.$current_input = $(selector); } Keyboard.prototype.init = function() { @@ -350,15 +351,26 @@ Keyboard.prototype.inputLocalOptions = function() { }; Keyboard.prototype.printChar = function(char) { - var current_val = this.$current_input.val(); - this.$current_input.val(current_val + char); - this.$current_input.focus().trigger("input"); + var selStart = this.$current_input[0].selectionStart; + var selEnd = this.$current_input[0].selectionEnd; + var textAreaStr = this.$current_input.val(); + var value = textAreaStr.substring(0, selStart) + char + textAreaStr.substring(selEnd); + + this.$current_input.val(value).focus(); + this.$current_input[0].selectionStart = selStart+1, this.$current_input[0].selectionEnd = selStart+1; + }; Keyboard.prototype.deleteChar = function() { - var current_val = this.$current_input.val(); - this.$current_input.val(current_val.slice(0,-1)); - this.$current_input.focus().trigger("input"); + var selStart = this.$current_input[0].selectionStart; + var selEnd = this.$current_input[0].selectionEnd; + + var textAreaStr = this.$current_input.val(); + var after = textAreaStr.substring(0, selStart-1); + var value = after + textAreaStr.substring(selEnd); + this.$current_input.val(value).focus(); + this.$current_input[0].selectionStart = selStart-1, this.$current_input[0].selectionEnd = selStart-1; + }; Keyboard.prototype.showModifications = function(caller) { @@ -416,7 +428,7 @@ Keyboard.prototype.changeKeysState = function() { $.fn.mlKeyboard = function(options) { - var keyboard = new Keyboard(options); + var keyboard = new Keyboard(this.selector, options); keyboard.init(); this.each(function(){ @@ -641,7 +653,8 @@ mlKeyboard.layouts.pt_PT = [ {d: 'w',u: 'W'}, {d: 'e',u: 'E', m: [ {d: 'e', u: 'E'}, - {d: 'é', u: 'É'} + {d: 'é', u: 'É'}, + {d: 'ê', u: 'Ê'} ]}, {d: 'r',u: 'R'}, {d: 't',u: 'T'}, @@ -773,3 +786,120 @@ mlKeyboard.layouts.it_IT = [ {} // Space ]; +var mlKeyboard = mlKeyboard || {layouts: {}}; + +mlKeyboard.layouts.fr_FR = [ + {d: '\/', u: '|'}, + {d: '1',u: '&'}, + {d: '2',u: 'é', m:[ + {d: '2', u:'é'}, + {d:'~', u:'É'} + ]}, + {d: '3',u: '#', m: [ + {d:'3', u:'#'}, + {d:'"', u: '#'} + ]}, + {d: '4',u: '{', m:[ + {d: '4', u:'{'}, + {d: '\'', u:'{'} + ]}, + {d: '5',u: '(', m:[ + {d: '5', u:'('}, + {d: '[', u:'('} + ]}, + {d: '6',u: '-', m:[ + {d: '6', u:'-'}, + {d: '|', u:'-'} + ]}, + {d: '7',u: 'è', m:[ + {d: '7', u:'è'}, + {d: '`', u:'è'} + ]}, + {d: '8',u: '_', m:[ + {d: '8', u:'_'}, + {d: '\/', u:'_'} + ]}, + {d: '9',u: '', m:[ + {d: '9', u:'ç'}, + {d: '^', u:'Ç'} + ]}, + {d: '0',u: 'à', m:[ + {d: '0', u:'à'}, + {d: '@', u:'À'} + ]}, + {d: '°',u: ')', m:[ + {d: '°', u:')'}, + {d: ']', u:')'} + ]}, + {d: '+',u: '=', m:[ + {d: '+', u:'='}, + {d: '}', u:'='} + ]}, + {}, // Delete + {}, // Tab + {d: 'q',u: 'Q'}, + {d: 'w',u: 'W'}, + {d: 'e',u: 'E', m: [ + {d: 'e', u: 'E'}, + {d: 'é', u: 'É'}, + {d: 'ê', u: 'Ê'} + ]}, + {d: 'r',u: 'R'}, + {d: 't',u: 'T'}, + {d: 'y',u: 'Y'}, + {d: 'u',u: 'U', m: [ + {d: 'u', u: 'U'}, + {d: 'ú', u: 'Ú'}, + {d: 'ü', u: 'Ü'} + ]}, + {d: 'i',u: 'I', m: [ + {d: 'i', u: 'I'}, + {d: 'í', u: 'Í'} + ]}, + {d: 'o',u: 'O', m: [ + {d: 'o', u: 'O'}, + {d: 'ó', u: 'Ó'}, + {d: 'õ', u: 'Õ'}, + {d: 'ô', u: 'Ô'} + ]}, + {d: 'p',u: 'P'}, + {d: '^',u: 'º'}, + {d: '`',u: '¨'}, + {d: '\'',u: '"'}, + {}, // Caps lock + {d: 'a',u: 'A', m: [ + {d: 'a', u: 'A'}, + {d: 'á', u: 'Á'}, + {d: 'à', u: 'À'}, + {d: 'ã', u: 'Ã'}, + {d: 'â', u: 'Â'} + ]}, + {d: 's',u: 'S'}, + {d: 'd',u: 'D'}, + {d: 'f',u: 'F'}, + {d: 'g',u: 'G'}, + {d: 'h',u: 'H'}, + {d: 'j',u: 'J'}, + {d: 'k',u: 'K'}, + {d: 'l',u: 'L'}, + {d: 'ñ',u: 'Ñ'}, + {d: ';',u: ':'}, + {}, // Return + {}, // Left shift + {d: 'z',u: 'Z'}, + {d: 'x',u: 'X'}, + {d: 'c',u: 'C', m: [ + {d: 'c', u: 'C'}, + {d: 'ç', u: 'Ç'} + ]}, + {d: 'v',u: 'V'}, + {d: 'b',u: 'B'}, + {d: 'n',u: 'N'}, + {d: 'm',u: 'M'}, + {d: ',',u: '¿'}, + {d: '.',u: '?'}, + {d: 'ç',u: 'Ç'}, + {}, // Right shift + {} // Space +]; + diff --git a/jquery.ml-keyboard.min.js b/jquery.ml-keyboard.min.js index 6f553b4..4a99336 100644 --- a/jquery.ml-keyboard.min.js +++ b/jquery.ml-keyboard.min.js @@ -1,2 +1,2 @@ -/*! jquery.ml-keyboard (http://mbut.github.io/jquery.mlkeyboard/) 2015-04-27 */ -!function($){function Key(params){this.keyboard="[object Arguments]"==Object.prototype.toString.call(params)?params[0]:params,this.$key=$("
  • "),this.current_value=null}function KeyDelete(){Key.call(this,arguments),this.id="mlkeyboard-backspace",this.default_value="delete"}function KeyTab(){Key.call(this,arguments),this.id="mlkeyboard-tab",this.default_value="tab"}function KeyCapsLock(){Key.call(this,arguments),this.id="mlkeyboard-capslock",this.default_value="caps lock"}function KeyReturn(){Key.call(this,arguments),this.id="mlkeyboard-return",this.default_value="return"}function KeyShift(){Key.call(this,arguments),this.id="mlkeyboard-"+arguments[1]+"-shift",this.default_value="shift"}function KeySpace(){Key.call(this,arguments),this.id="mlkeyboard-space",this.default_value=" "}function Keyboard(options){this.defaults={layout:"en_US",active_shift:!0,active_caps:!1,is_hidden:!0,open_speed:300,close_speed:100,show_on_focus:!0,hide_on_blur:!0,trigger:void 0,enabled:!0},this.global_options=$.extend({},this.defaults,options),this.options=$.extend({},{},this.global_options),this.keys=[],this.$keyboard=$("
    ").attr("id","mlkeyboard"),this.$modifications_holder=$("
      ").addClass("mlkeyboard-modifications"),this.$current_input=$("input[type='text']").first()}Key.prototype.render=function(){return this.id&&this.$key.attr("id",this.id),this.$key},Key.prototype.setCurrentValue=function(){this.current_value=this.keyboard.upperRegister()?this.preferences.u?this.preferences.u:this.default_value:this.preferences.d?this.preferences.d:this.default_value,this.$key.text(this.current_value)},Key.prototype.setCurrentAction=function(){var _this=this;this.$key.unbind("click.mlkeyboard"),this.$key.bind("click.mlkeyboard",function(){_this.keyboard.keep_focus=!0,"function"==typeof _this.preferences.onClick?_this.preferences.onClick(_this):_this.defaultClickAction()})},Key.prototype.defaultClickAction=function(){this.keyboard.destroyModifications(),this.is_modificator?(this.keyboard.deleteChar(),this.keyboard.printChar(this.current_value)):this.keyboard.printChar(this.current_value),this.preferences.m&&"[object Array]"===Object.prototype.toString.call(this.preferences.m)&&this.showModifications(),this.keyboard.active_shift&&this.keyboard.toggleShift(!1)},Key.prototype.showModifications=function(){var _this=this;this.keyboard.modifications=[],$.each(this.preferences.m,function(i,modification){var key=new Key(_this.keyboard);key.is_modificator=!0,key.preferences=modification,_this.keyboard.modifications.push(key)}),this.keyboard.showModifications(this)},Key.prototype.toggleActiveState=function(){this.isActive()?this.$key.addClass("active"):this.$key.removeClass("active")},Key.prototype.isActive=function(){return!1},KeyDelete.prototype=new Key,KeyDelete.prototype.constructor=KeyDelete,KeyDelete.prototype.defaultClickAction=function(){this.keyboard.deleteChar()},KeyTab.prototype=new Key,KeyTab.prototype.constructor=KeyTab,KeyTab.prototype.defaultClickAction=function(){this.keyboard.$current_input.next(":input").focus()},KeyCapsLock.prototype=new Key,KeyCapsLock.prototype.constructor=KeyCapsLock,KeyCapsLock.prototype.isActive=function(){return this.keyboard.active_caps},KeyCapsLock.prototype.defaultClickAction=function(){this.keyboard.toggleCaps()},KeyReturn.prototype=new Key,KeyReturn.prototype.constructor=KeyReturn,KeyReturn.prototype.defaultClickAction=function(){var e=$.Event("keypress",{which:13,keyCode:13});this.keyboard.$current_input.trigger(e)},KeyShift.prototype=new Key,KeyShift.prototype.constructor=KeyShift,KeyShift.prototype.isActive=function(){return this.keyboard.active_shift},KeyShift.prototype.defaultClickAction=function(){this.keyboard.toggleShift()},KeySpace.prototype=new Key,KeySpace.prototype.constructor=KeySpace;var KEYS_COUNT=53;Keyboard.prototype.init=function(){this.$keyboard.append(this.renderKeys()),this.$keyboard.append(this.$modifications_holder),$("body").append(this.$keyboard),this.options.is_hidden&&this.$keyboard.hide(),this.setUpKeys()},Keyboard.prototype.setUpKeys=function(){var _this=this;this.active_shift=this.options.active_shift,this.active_caps=this.options.active_caps,$.each(this.keys,function(i,key){key.preferences=mlKeyboard.layouts[_this.options.layout][i],key.setCurrentValue(),key.setCurrentAction(),key.toggleActiveState()})},Keyboard.prototype.renderKeys=function(){for(var $keys_holder=$("
        "),i=0;KEYS_COUNT>=i;i++){var key;switch(i){case 13:key=new KeyDelete(this);break;case 14:key=new KeyTab(this);break;case 28:key=new KeyCapsLock(this);break;case 40:key=new KeyReturn(this);break;case 41:key=new KeyShift(this,"left");break;case 52:key=new KeyShift(this,"right");break;case 53:key=new KeySpace(this);break;default:key=new Key(this)}this.keys.push(key),$keys_holder.append(key.render())}return $keys_holder},Keyboard.prototype.setUpFor=function($input){var _this=this;if(this.options.show_on_focus&&$input.bind("focus",function(){_this.showKeyboard($input)}),this.options.hide_on_blur&&$input.bind("blur",function(){var VERIFY_STATE_DELAY=500;clearTimeout(_this.blur_timeout),_this.blur_timeout=setTimeout(function(){_this.keep_focus?_this.keep_focus=!1:_this.hideKeyboard()},VERIFY_STATE_DELAY)}),this.options.trigger){var $trigger=$(this.options.trigger);$trigger.bind("click",function(e){e.preventDefault(),_this.isVisible?_this.hideKeyboard():(_this.showKeyboard($input),$input.focus())})}},Keyboard.prototype.showKeyboard=function($input){var input_changed=!this.$current_input||$input[0]!==this.$current_input[0];if(!this.keep_focus||input_changed){if(input_changed&&(this.keep_focus=!0),this.$current_input=$input,this.options=$.extend({},this.global_options,this.inputLocalOptions()),!this.options.enabled)return void(this.keep_focus=!1);""!==this.$current_input.val()&&(this.options.active_shift=!1),this.setUpKeys(),this.options.is_hidden&&(this.isVisible=!0,this.$keyboard.slideDown(this.options.openSpeed))}},Keyboard.prototype.hideKeyboard=function(){this.options.is_hidden&&(this.isVisible=!1,this.$keyboard.slideUp(this.options.closeSpeed))},Keyboard.prototype.inputLocalOptions=function(){var options={};for(var key in this.defaults){var input_option=this.$current_input.attr("data-mlkeyboard-"+key);"false"==input_option?input_option=!1:"true"==input_option&&(input_option=!0),"undefined"!=typeof input_option&&(options[key]=input_option)}return options},Keyboard.prototype.printChar=function(char){var current_val=this.$current_input.val();this.$current_input.val(current_val+char),this.$current_input.focus().trigger("input")},Keyboard.prototype.deleteChar=function(){var current_val=this.$current_input.val();this.$current_input.val(current_val.slice(0,-1)),this.$current_input.focus().trigger("input")},Keyboard.prototype.showModifications=function(caller){var top,left,width,_this=this,holder_padding=parseInt(_this.$modifications_holder.css("padding"),10);$.each(this.modifications,function(i,key){_this.$modifications_holder.append(key.render()),key.setCurrentValue(),key.setCurrentAction()}),width=caller.$key.width()*_this.modifications.length+6*_this.modifications.length,top=caller.$key.position().top-holder_padding,left=caller.$key.position().left-_this.modifications.length*caller.$key.width()/2,this.$modifications_holder.one("mouseleave",function(){_this.destroyModifications()}),this.$modifications_holder.css({width:width,top:top,left:left}).show()},Keyboard.prototype.destroyModifications=function(){this.$modifications_holder.empty().hide()},Keyboard.prototype.upperRegister=function(){return this.active_shift&&!this.active_caps||!this.active_shift&&this.active_caps},Keyboard.prototype.toggleShift=function(state){this.active_shift=state?state:!this.active_shift,this.changeKeysState()},Keyboard.prototype.toggleCaps=function(state){this.active_caps=state?state:!this.active_caps,this.changeKeysState()},Keyboard.prototype.changeKeysState=function(){$.each(this.keys,function(_,key){key.setCurrentValue(),key.toggleActiveState()})},$.fn.mlKeyboard=function(options){var keyboard=new Keyboard(options);keyboard.init(),this.each(function(){keyboard.setUpFor($(this))})}}(jQuery);var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.en_US=[{d:"`",u:"~"},{d:"1",u:"!"},{d:"2",u:"@"},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"^"},{d:"7",u:"&"},{d:"8",u:"*"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E"},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U"},{d:"i",u:"I"},{d:"o",u:"O"},{d:"p",u:"P"},{d:"]",u:"}"},{d:"[",u:"{"},{d:"\\",u:"|"},{},{d:"a",u:"A"},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:";",u:":"},{d:"'",u:'"'},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"<"},{d:".",u:">"},{d:"/",u:"?"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.ru_RU=[{d:"ё",u:"Ё"},{d:"1",u:"!"},{d:"2",u:"'"},{d:"3",u:"№"},{d:"4",u:"%"},{d:"5",u:":"},{d:"6",u:","},{d:"7",u:"."},{d:"8",u:";"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"й",u:"Й"},{d:"ц",u:"Ц"},{d:"у",u:"У"},{d:"к",u:"К"},{d:"е",u:"Е"},{d:"н",u:"Н"},{d:"г",u:"Г"},{d:"ш",u:"Ш"},{d:"щ",u:"Щ"},{d:"з",u:"З"},{d:"х",u:"Х"},{d:"ъ",u:"Ъ"},{d:"|",u:"\\"},{},{d:"ф",u:"Ф"},{d:"ы",u:"Ы"},{d:"в",u:"В"},{d:"а",u:"А"},{d:"п",u:"П"},{d:"р",u:"Р"},{d:"о",u:"О"},{d:"л",u:"Л"},{d:"д",u:"Д"},{d:"ж",u:"Ж"},{d:"э",u:"Э"},{},{},{d:"я",u:"Я"},{d:"ч",u:"Ч"},{d:"с",u:"С"},{d:"м",u:"М"},{d:"и",u:"И"},{d:"т",u:"Т"},{d:"ь",u:"Ь"},{d:"б",u:"Б"},{d:"ю",u:"Ю"},{d:".",u:","},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.es_ES=[{d:"<",u:">"},{d:"1",u:"¡"},{d:"2",u:"!"},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"/"},{d:"7",u:"&"},{d:"8",u:"*"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E",m:[{d:"e",u:"E"},{d:"é",u:"É"}]},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U",m:[{d:"u",u:"U"},{d:"ú",u:"Ú"},{d:"ü",u:"Ü"}]},{d:"i",u:"I",m:[{d:"i",u:"I"},{d:"í",u:"Í"}]},{d:"o",u:"O",m:[{d:"o",u:"O"},{d:"ó",u:"Ó"}]},{d:"p",u:"P"},{d:"´",u:"º"},{d:"`",u:"¨"},{d:"'",u:'"'},{},{d:"a",u:"A",m:[{d:"a",u:"A"},{d:"á",u:"Á"}]},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ñ",u:"Ñ"},{d:";",u:":"},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"¿"},{d:".",u:"?"},{d:"ç",u:"Ç"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.pt_PT=[{d:"/",u:"|"},{d:"1",u:"!"},{d:"2",u:'"'},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"&"},{d:"7",u:"/"},{d:"8",u:"("},{d:"9",u:")"},{d:"0",u:"="},{d:"-",u:"?"},{d:"~",u:"^"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E",m:[{d:"e",u:"E"},{d:"é",u:"É"}]},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U",m:[{d:"u",u:"U"},{d:"ú",u:"Ú"}]},{d:"i",u:"I",m:[{d:"i",u:"I"},{d:"í",u:"Í"}]},{d:"o",u:"O",m:[{d:"o",u:"O"},{d:"ó",u:"Ó"},{d:"õ",u:"Õ"},{d:"ô",u:"Ô"}]},{d:"p",u:"P"},{d:"´",u:"º"},{d:"`",u:"¨"},{d:"'",u:'"'},{},{d:"a",u:"A",m:[{d:"a",u:"A"},{d:"á",u:"Á"},{d:"à",u:"À"},{d:"ã",u:"Ã"},{d:"â",u:"Â"}]},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ñ",u:"Ñ"},{d:";",u:":"},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C",m:[{d:"c",u:"C"},{d:"ç",u:"Ç"}]},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"¿"},{d:".",u:"?"},{d:"ç",u:"Ç"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.it_IT=[{d:"\\",u:"|"},{d:"1",u:"!"},{d:"2",u:'"'},{d:"3",u:"£"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"&"},{d:"7",u:"/"},{d:"8",u:"("},{d:"9",u:")"},{d:"0",u:"="},{d:"'",u:"?"},{d:"ì",u:"^"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E"},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U"},{d:"i",u:"I"},{d:"o",u:"O"},{d:"p",u:"P"},{d:"e",u:"é",m:[{d:"e",u:"é"},{d:"[",u:"{"}]},{d:"+",u:"*",m:[{d:"+",u:"*"},{d:"]",u:"}"}]},{},{d:"a",u:"A"},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ò",u:"ç",m:[{d:"ò",u:"ç"},{d:"@",u:"Ç"}]},{d:"à",u:"°",m:[{d:"à",u:"°"},{d:"#",u:"∞"}]},{d:"ù",u:"§"},{},{},{d:"<",u:">"},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:";"},{d:".",u:":"},{d:"-",u:"_"},{},{}]; \ No newline at end of file +/*! jquery.ml-keyboard (http://mbut.github.io/jquery.mlkeyboard/) 2016-08-30 */ +!function($){function Key(params){"[object Arguments]"==Object.prototype.toString.call(params)?this.keyboard=params[0]:this.keyboard=params,this.$key=$("
      • "),this.current_value=null}function KeyDelete(){Key.call(this,arguments),this.id="mlkeyboard-backspace",this.default_value="delete"}function KeyTab(){Key.call(this,arguments),this.id="mlkeyboard-tab",this.default_value="tab"}function KeyCapsLock(){Key.call(this,arguments),this.id="mlkeyboard-capslock",this.default_value="caps lock"}function KeyReturn(){Key.call(this,arguments),this.id="mlkeyboard-return",this.default_value="return"}function KeyShift(){Key.call(this,arguments),this.id="mlkeyboard-"+arguments[1]+"-shift",this.default_value="shift"}function KeySpace(){Key.call(this,arguments),this.id="mlkeyboard-space",this.default_value=" "}function Keyboard(selector,options){this.defaults={layout:"en_US",active_shift:!0,active_caps:!1,is_hidden:!0,open_speed:300,close_speed:100,show_on_focus:!0,hide_on_blur:!0,trigger:void 0,enabled:!0},this.global_options=$.extend({},this.defaults,options),this.options=$.extend({},{},this.global_options),this.keys=[],this.$keyboard=$("
        ").attr("id","mlkeyboard"),this.$modifications_holder=$("
          ").addClass("mlkeyboard-modifications"),this.$current_input=$(selector)}Key.prototype.render=function(){return this.id&&this.$key.attr("id",this.id),this.$key},Key.prototype.setCurrentValue=function(){this.keyboard.upperRegister()?this.current_value=this.preferences.u?this.preferences.u:this.default_value:this.current_value=this.preferences.d?this.preferences.d:this.default_value,this.$key.text(this.current_value)},Key.prototype.setCurrentAction=function(){var _this=this;this.$key.unbind("click.mlkeyboard"),this.$key.bind("click.mlkeyboard",function(){_this.keyboard.keep_focus=!0,"function"==typeof _this.preferences.onClick?_this.preferences.onClick(_this):_this.defaultClickAction()})},Key.prototype.defaultClickAction=function(){this.keyboard.destroyModifications(),this.is_modificator?(this.keyboard.deleteChar(),this.keyboard.printChar(this.current_value)):this.keyboard.printChar(this.current_value),this.preferences.m&&"[object Array]"===Object.prototype.toString.call(this.preferences.m)&&this.showModifications(),this.keyboard.active_shift&&this.keyboard.toggleShift(!1)},Key.prototype.showModifications=function(){var _this=this;this.keyboard.modifications=[],$.each(this.preferences.m,function(i,modification){var key=new Key(_this.keyboard);key.is_modificator=!0,key.preferences=modification,_this.keyboard.modifications.push(key)}),this.keyboard.showModifications(this)},Key.prototype.toggleActiveState=function(){this.isActive()?this.$key.addClass("active"):this.$key.removeClass("active")},Key.prototype.isActive=function(){return!1},KeyDelete.prototype=new Key,KeyDelete.prototype.constructor=KeyDelete,KeyDelete.prototype.defaultClickAction=function(){this.keyboard.deleteChar()},KeyTab.prototype=new Key,KeyTab.prototype.constructor=KeyTab,KeyTab.prototype.defaultClickAction=function(){this.keyboard.hideKeyboard(),$(":input").eq($(":input").index(this.keyboard.$current_input)+1).focus()},KeyCapsLock.prototype=new Key,KeyCapsLock.prototype.constructor=KeyCapsLock,KeyCapsLock.prototype.isActive=function(){return this.keyboard.active_caps},KeyCapsLock.prototype.defaultClickAction=function(){this.keyboard.toggleCaps()},KeyReturn.prototype=new Key,KeyReturn.prototype.constructor=KeyReturn,KeyReturn.prototype.defaultClickAction=function(){var e=$.Event("keypress",{which:13,keyCode:13});this.keyboard.$current_input.trigger(e)},KeyShift.prototype=new Key,KeyShift.prototype.constructor=KeyShift,KeyShift.prototype.isActive=function(){return this.keyboard.active_shift},KeyShift.prototype.defaultClickAction=function(){this.keyboard.toggleShift()},KeySpace.prototype=new Key,KeySpace.prototype.constructor=KeySpace;var KEYS_COUNT=53;Keyboard.prototype.init=function(){this.$keyboard.append(this.renderKeys()),this.$keyboard.append(this.$modifications_holder),$("body").append(this.$keyboard),this.options.is_hidden&&this.$keyboard.hide(),this.setUpKeys()},Keyboard.prototype.setUpKeys=function(){var _this=this;this.active_shift=this.options.active_shift,this.active_caps=this.options.active_caps,$.each(this.keys,function(i,key){key.preferences=mlKeyboard.layouts[_this.options.layout][i],key.setCurrentValue(),key.setCurrentAction(),key.toggleActiveState()})},Keyboard.prototype.renderKeys=function(){for(var $keys_holder=$("
            "),i=0;KEYS_COUNT>=i;i++){var key;switch(i){case 13:key=new KeyDelete(this);break;case 14:key=new KeyTab(this);break;case 28:key=new KeyCapsLock(this);break;case 40:key=new KeyReturn(this);break;case 41:key=new KeyShift(this,"left");break;case 52:key=new KeyShift(this,"right");break;case 53:key=new KeySpace(this);break;default:key=new Key(this)}this.keys.push(key),$keys_holder.append(key.render())}return $keys_holder},Keyboard.prototype.setUpFor=function($input){var _this=this;if(this.options.show_on_focus&&$input.bind("focus",function(){_this.showKeyboard($input)}),this.options.hide_on_blur&&$input.bind("blur",function(){var VERIFY_STATE_DELAY=500;clearTimeout(_this.blur_timeout),_this.blur_timeout=setTimeout(function(){_this.keep_focus?_this.keep_focus=!1:_this.hideKeyboard()},VERIFY_STATE_DELAY)}),this.options.trigger){var $trigger=$(this.options.trigger);$trigger.bind("click",function(e){e.preventDefault(),_this.isVisible?_this.hideKeyboard():(_this.showKeyboard($input),$input.focus())})}},Keyboard.prototype.showKeyboard=function($input){var input_changed=!this.$current_input||$input[0]!==this.$current_input[0];if(!this.keep_focus||input_changed){if(input_changed&&(this.keep_focus=!0),this.$current_input=$input,this.options=$.extend({},this.global_options,this.inputLocalOptions()),!this.options.enabled)return void(this.keep_focus=!1);""!==this.$current_input.val()&&(this.options.active_shift=!1),this.setUpKeys(),this.options.is_hidden&&(this.isVisible=!0,this.$keyboard.slideDown(this.options.openSpeed))}},Keyboard.prototype.hideKeyboard=function(){this.options.is_hidden&&(this.isVisible=!1,this.$keyboard.slideUp(this.options.closeSpeed))},Keyboard.prototype.inputLocalOptions=function(){var options={};for(var key in this.defaults){var input_option=this.$current_input.attr("data-mlkeyboard-"+key);"false"==input_option?input_option=!1:"true"==input_option&&(input_option=!0),"undefined"!=typeof input_option&&(options[key]=input_option)}return options},Keyboard.prototype.printChar=function(char){var selStart=this.$current_input[0].selectionStart,selEnd=this.$current_input[0].selectionEnd,textAreaStr=this.$current_input.val(),value=textAreaStr.substring(0,selStart)+char+textAreaStr.substring(selEnd);this.$current_input.val(value).focus(),this.$current_input[0].selectionStart=selStart+1,this.$current_input[0].selectionEnd=selStart+1},Keyboard.prototype.deleteChar=function(){var selStart=this.$current_input[0].selectionStart,selEnd=this.$current_input[0].selectionEnd,textAreaStr=this.$current_input.val(),after=textAreaStr.substring(0,selStart-1),value=after+textAreaStr.substring(selEnd);this.$current_input.val(value).focus(),this.$current_input[0].selectionStart=selStart-1,this.$current_input[0].selectionEnd=selStart-1},Keyboard.prototype.showModifications=function(caller){var top,left,width,_this=this,holder_padding=parseInt(_this.$modifications_holder.css("padding"),10);$.each(this.modifications,function(i,key){_this.$modifications_holder.append(key.render()),key.setCurrentValue(),key.setCurrentAction()}),width=caller.$key.width()*_this.modifications.length+6*_this.modifications.length,top=caller.$key.position().top-holder_padding,left=caller.$key.position().left-_this.modifications.length*caller.$key.width()/2,this.$modifications_holder.one("mouseleave",function(){_this.destroyModifications()}),this.$modifications_holder.css({width:width,top:top,left:left}).show()},Keyboard.prototype.destroyModifications=function(){this.$modifications_holder.empty().hide()},Keyboard.prototype.upperRegister=function(){return this.active_shift&&!this.active_caps||!this.active_shift&&this.active_caps},Keyboard.prototype.toggleShift=function(state){this.active_shift=state?state:!this.active_shift,this.changeKeysState()},Keyboard.prototype.toggleCaps=function(state){this.active_caps=state?state:!this.active_caps,this.changeKeysState()},Keyboard.prototype.changeKeysState=function(){$.each(this.keys,function(_,key){key.setCurrentValue(),key.toggleActiveState()})},$.fn.mlKeyboard=function(options){var keyboard=new Keyboard(this.selector,options);keyboard.init(),this.each(function(){keyboard.setUpFor($(this))})}}(jQuery);var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.en_US=[{d:"`",u:"~"},{d:"1",u:"!"},{d:"2",u:"@"},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"^"},{d:"7",u:"&"},{d:"8",u:"*"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E"},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U"},{d:"i",u:"I"},{d:"o",u:"O"},{d:"p",u:"P"},{d:"]",u:"}"},{d:"[",u:"{"},{d:"\\",u:"|"},{},{d:"a",u:"A"},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:";",u:":"},{d:"'",u:'"'},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"<"},{d:".",u:">"},{d:"/",u:"?"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.ru_RU=[{d:"ё",u:"Ё"},{d:"1",u:"!"},{d:"2",u:"'"},{d:"3",u:"№"},{d:"4",u:"%"},{d:"5",u:":"},{d:"6",u:","},{d:"7",u:"."},{d:"8",u:";"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"й",u:"Й"},{d:"ц",u:"Ц"},{d:"у",u:"У"},{d:"к",u:"К"},{d:"е",u:"Е"},{d:"н",u:"Н"},{d:"г",u:"Г"},{d:"ш",u:"Ш"},{d:"щ",u:"Щ"},{d:"з",u:"З"},{d:"х",u:"Х"},{d:"ъ",u:"Ъ"},{d:"|",u:"\\"},{},{d:"ф",u:"Ф"},{d:"ы",u:"Ы"},{d:"в",u:"В"},{d:"а",u:"А"},{d:"п",u:"П"},{d:"р",u:"Р"},{d:"о",u:"О"},{d:"л",u:"Л"},{d:"д",u:"Д"},{d:"ж",u:"Ж"},{d:"э",u:"Э"},{},{},{d:"я",u:"Я"},{d:"ч",u:"Ч"},{d:"с",u:"С"},{d:"м",u:"М"},{d:"и",u:"И"},{d:"т",u:"Т"},{d:"ь",u:"Ь"},{d:"б",u:"Б"},{d:"ю",u:"Ю"},{d:".",u:","},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.es_ES=[{d:"<",u:">"},{d:"1",u:"¡"},{d:"2",u:"!"},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"/"},{d:"7",u:"&"},{d:"8",u:"*"},{d:"9",u:"("},{d:"0",u:")"},{d:"-",u:"_"},{d:"=",u:"+"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E",m:[{d:"e",u:"E"},{d:"é",u:"É"}]},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U",m:[{d:"u",u:"U"},{d:"ú",u:"Ú"},{d:"ü",u:"Ü"}]},{d:"i",u:"I",m:[{d:"i",u:"I"},{d:"í",u:"Í"}]},{d:"o",u:"O",m:[{d:"o",u:"O"},{d:"ó",u:"Ó"}]},{d:"p",u:"P"},{d:"´",u:"º"},{d:"`",u:"¨"},{d:"'",u:'"'},{},{d:"a",u:"A",m:[{d:"a",u:"A"},{d:"á",u:"Á"}]},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ñ",u:"Ñ"},{d:";",u:":"},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"¿"},{d:".",u:"?"},{d:"ç",u:"Ç"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.pt_PT=[{d:"/",u:"|"},{d:"1",u:"!"},{d:"2",u:'"'},{d:"3",u:"#"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"&"},{d:"7",u:"/"},{d:"8",u:"("},{d:"9",u:")"},{d:"0",u:"="},{d:"-",u:"?"},{d:"~",u:"^"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E",m:[{d:"e",u:"E"},{d:"é",u:"É"},{d:"ê",u:"Ê"}]},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U",m:[{d:"u",u:"U"},{d:"ú",u:"Ú"}]},{d:"i",u:"I",m:[{d:"i",u:"I"},{d:"í",u:"Í"}]},{d:"o",u:"O",m:[{d:"o",u:"O"},{d:"ó",u:"Ó"},{d:"õ",u:"Õ"},{d:"ô",u:"Ô"}]},{d:"p",u:"P"},{d:"´",u:"º"},{d:"`",u:"¨"},{d:"'",u:'"'},{},{d:"a",u:"A",m:[{d:"a",u:"A"},{d:"á",u:"Á"},{d:"à",u:"À"},{d:"ã",u:"Ã"},{d:"â",u:"Â"}]},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ñ",u:"Ñ"},{d:";",u:":"},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C",m:[{d:"c",u:"C"},{d:"ç",u:"Ç"}]},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"¿"},{d:".",u:"?"},{d:"ç",u:"Ç"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.it_IT=[{d:"\\",u:"|"},{d:"1",u:"!"},{d:"2",u:'"'},{d:"3",u:"£"},{d:"4",u:"$"},{d:"5",u:"%"},{d:"6",u:"&"},{d:"7",u:"/"},{d:"8",u:"("},{d:"9",u:")"},{d:"0",u:"="},{d:"'",u:"?"},{d:"ì",u:"^"},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E"},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U"},{d:"i",u:"I"},{d:"o",u:"O"},{d:"p",u:"P"},{d:"e",u:"é",m:[{d:"e",u:"é"},{d:"[",u:"{"}]},{d:"+",u:"*",m:[{d:"+",u:"*"},{d:"]",u:"}"}]},{},{d:"a",u:"A"},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ò",u:"ç",m:[{d:"ò",u:"ç"},{d:"@",u:"Ç"}]},{d:"à",u:"°",m:[{d:"à",u:"°"},{d:"#",u:"∞"}]},{d:"ù",u:"§"},{},{},{d:"<",u:">"},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C"},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:";"},{d:".",u:":"},{d:"-",u:"_"},{},{}];var mlKeyboard=mlKeyboard||{layouts:{}};mlKeyboard.layouts.fr_FR=[{d:"/",u:"|"},{d:"1",u:"&"},{d:"2",u:"é",m:[{d:"2",u:"é"},{d:"~",u:"É"}]},{d:"3",u:"#",m:[{d:"3",u:"#"},{d:'"',u:"#"}]},{d:"4",u:"{",m:[{d:"4",u:"{"},{d:"'",u:"{"}]},{d:"5",u:"(",m:[{d:"5",u:"("},{d:"[",u:"("}]},{d:"6",u:"-",m:[{d:"6",u:"-"},{d:"|",u:"-"}]},{d:"7",u:"è",m:[{d:"7",u:"è"},{d:"`",u:"è"}]},{d:"8",u:"_",m:[{d:"8",u:"_"},{d:"/",u:"_"}]},{d:"9",u:"",m:[{d:"9",u:"ç"},{d:"^",u:"Ç"}]},{d:"0",u:"à",m:[{d:"0",u:"à"},{d:"@",u:"À"}]},{d:"°",u:")",m:[{d:"°",u:")"},{d:"]",u:")"}]},{d:"+",u:"=",m:[{d:"+",u:"="},{d:"}",u:"="}]},{},{},{d:"q",u:"Q"},{d:"w",u:"W"},{d:"e",u:"E",m:[{d:"e",u:"E"},{d:"é",u:"É"},{d:"ê",u:"Ê"}]},{d:"r",u:"R"},{d:"t",u:"T"},{d:"y",u:"Y"},{d:"u",u:"U",m:[{d:"u",u:"U"},{d:"ú",u:"Ú"},{d:"ü",u:"Ü"}]},{d:"i",u:"I",m:[{d:"i",u:"I"},{d:"í",u:"Í"}]},{d:"o",u:"O",m:[{d:"o",u:"O"},{d:"ó",u:"Ó"},{d:"õ",u:"Õ"},{d:"ô",u:"Ô"}]},{d:"p",u:"P"},{d:"^",u:"º"},{d:"`",u:"¨"},{d:"'",u:'"'},{},{d:"a",u:"A",m:[{d:"a",u:"A"},{d:"á",u:"Á"},{d:"à",u:"À"},{d:"ã",u:"Ã"},{d:"â",u:"Â"}]},{d:"s",u:"S"},{d:"d",u:"D"},{d:"f",u:"F"},{d:"g",u:"G"},{d:"h",u:"H"},{d:"j",u:"J"},{d:"k",u:"K"},{d:"l",u:"L"},{d:"ñ",u:"Ñ"},{d:";",u:":"},{},{},{d:"z",u:"Z"},{d:"x",u:"X"},{d:"c",u:"C",m:[{d:"c",u:"C"},{d:"ç",u:"Ç"}]},{d:"v",u:"V"},{d:"b",u:"B"},{d:"n",u:"N"},{d:"m",u:"M"},{d:",",u:"¿"},{d:".",u:"?"},{d:"ç",u:"Ç"},{},{}]; \ No newline at end of file diff --git a/src/base.js b/src/base.js index cc12656..94d93bf 100644 --- a/src/base.js +++ b/src/base.js @@ -9,7 +9,7 @@ @@include('keyboard.js') $.fn.mlKeyboard = function(options) { - var keyboard = new Keyboard(options); + var keyboard = new Keyboard(this.selector, options); keyboard.init(); this.each(function(){ @@ -24,3 +24,4 @@ @@include('layouts/es_ES.js') @@include('layouts/pt_PT.js') @@include('layouts/it_IT.js') +@@include('layouts/fr_FR.js') diff --git a/src/key_tab.js b/src/key_tab.js index aaba9ba..e1f1daf 100644 --- a/src/key_tab.js +++ b/src/key_tab.js @@ -9,6 +9,6 @@ KeyTab.prototype = new Key(); KeyTab.prototype.constructor = KeyTab; KeyTab.prototype.defaultClickAction = function() { - // TODO: It's doesn't work if inputs has different parents - this.keyboard.$current_input.next(":input").focus(); -}; \ No newline at end of file + this.keyboard.hideKeyboard(); + $(":input").eq($(":input").index(this.keyboard.$current_input)+1).focus(); +}; diff --git a/src/keyboard.js b/src/keyboard.js index a506f96..cd189fc 100644 --- a/src/keyboard.js +++ b/src/keyboard.js @@ -1,6 +1,6 @@ var KEYS_COUNT = 53; -function Keyboard(options){ +function Keyboard(selector, options){ this.defaults = { layout: 'en_US', active_shift: true, @@ -21,7 +21,7 @@ function Keyboard(options){ this.$keyboard = $("
            ").attr("id", "mlkeyboard"); this.$modifications_holder = $("
              ").addClass('mlkeyboard-modifications'); - this.$current_input = $("input[type='text']").first(); + this.$current_input = $(selector); } Keyboard.prototype.init = function() { @@ -176,15 +176,26 @@ Keyboard.prototype.inputLocalOptions = function() { }; Keyboard.prototype.printChar = function(char) { - var current_val = this.$current_input.val(); - this.$current_input.val(current_val + char); - this.$current_input.focus().trigger("input"); + var selStart = this.$current_input[0].selectionStart; + var selEnd = this.$current_input[0].selectionEnd; + var textAreaStr = this.$current_input.val(); + var value = textAreaStr.substring(0, selStart) + char + textAreaStr.substring(selEnd); + + this.$current_input.val(value).focus(); + this.$current_input[0].selectionStart = selStart+1, this.$current_input[0].selectionEnd = selStart+1; + }; Keyboard.prototype.deleteChar = function() { - var current_val = this.$current_input.val(); - this.$current_input.val(current_val.slice(0,-1)); - this.$current_input.focus().trigger("input"); + var selStart = this.$current_input[0].selectionStart; + var selEnd = this.$current_input[0].selectionEnd; + + var textAreaStr = this.$current_input.val(); + var after = textAreaStr.substring(0, selStart-1); + var value = after + textAreaStr.substring(selEnd); + this.$current_input.val(value).focus(); + this.$current_input[0].selectionStart = selStart-1, this.$current_input[0].selectionEnd = selStart-1; + }; Keyboard.prototype.showModifications = function(caller) { diff --git a/src/layouts/fr_FR.js b/src/layouts/fr_FR.js new file mode 100644 index 0000000..504de84 --- /dev/null +++ b/src/layouts/fr_FR.js @@ -0,0 +1,116 @@ +var mlKeyboard = mlKeyboard || {layouts: {}}; + +mlKeyboard.layouts.fr_FR = [ + {d: '\/', u: '|'}, + {d: '1',u: '&'}, + {d: '2',u: 'é', m:[ + {d: '2', u:'é'}, + {d:'~', u:'É'} + ]}, + {d: '3',u: '#', m: [ + {d:'3', u:'#'}, + {d:'"', u: '#'} + ]}, + {d: '4',u: '{', m:[ + {d: '4', u:'{'}, + {d: '\'', u:'{'} + ]}, + {d: '5',u: '(', m:[ + {d: '5', u:'('}, + {d: '[', u:'('} + ]}, + {d: '6',u: '-', m:[ + {d: '6', u:'-'}, + {d: '|', u:'-'} + ]}, + {d: '7',u: 'è', m:[ + {d: '7', u:'è'}, + {d: '`', u:'è'} + ]}, + {d: '8',u: '_', m:[ + {d: '8', u:'_'}, + {d: '\/', u:'_'} + ]}, + {d: '9',u: '', m:[ + {d: '9', u:'ç'}, + {d: '^', u:'Ç'} + ]}, + {d: '0',u: 'à', m:[ + {d: '0', u:'à'}, + {d: '@', u:'À'} + ]}, + {d: '°',u: ')', m:[ + {d: '°', u:')'}, + {d: ']', u:')'} + ]}, + {d: '+',u: '=', m:[ + {d: '+', u:'='}, + {d: '}', u:'='} + ]}, + {}, // Delete + {}, // Tab + {d: 'q',u: 'Q'}, + {d: 'w',u: 'W'}, + {d: 'e',u: 'E', m: [ + {d: 'e', u: 'E'}, + {d: 'é', u: 'É'}, + {d: 'ê', u: 'Ê'} + ]}, + {d: 'r',u: 'R'}, + {d: 't',u: 'T'}, + {d: 'y',u: 'Y'}, + {d: 'u',u: 'U', m: [ + {d: 'u', u: 'U'}, + {d: 'ú', u: 'Ú'}, + {d: 'ü', u: 'Ü'} + ]}, + {d: 'i',u: 'I', m: [ + {d: 'i', u: 'I'}, + {d: 'í', u: 'Í'} + ]}, + {d: 'o',u: 'O', m: [ + {d: 'o', u: 'O'}, + {d: 'ó', u: 'Ó'}, + {d: 'õ', u: 'Õ'}, + {d: 'ô', u: 'Ô'} + ]}, + {d: 'p',u: 'P'}, + {d: '^',u: 'º'}, + {d: '`',u: '¨'}, + {d: '\'',u: '"'}, + {}, // Caps lock + {d: 'a',u: 'A', m: [ + {d: 'a', u: 'A'}, + {d: 'á', u: 'Á'}, + {d: 'à', u: 'À'}, + {d: 'ã', u: 'Ã'}, + {d: 'â', u: 'Â'} + ]}, + {d: 's',u: 'S'}, + {d: 'd',u: 'D'}, + {d: 'f',u: 'F'}, + {d: 'g',u: 'G'}, + {d: 'h',u: 'H'}, + {d: 'j',u: 'J'}, + {d: 'k',u: 'K'}, + {d: 'l',u: 'L'}, + {d: 'ñ',u: 'Ñ'}, + {d: ';',u: ':'}, + {}, // Return + {}, // Left shift + {d: 'z',u: 'Z'}, + {d: 'x',u: 'X'}, + {d: 'c',u: 'C', m: [ + {d: 'c', u: 'C'}, + {d: 'ç', u: 'Ç'} + ]}, + {d: 'v',u: 'V'}, + {d: 'b',u: 'B'}, + {d: 'n',u: 'N'}, + {d: 'm',u: 'M'}, + {d: ',',u: '¿'}, + {d: '.',u: '?'}, + {d: 'ç',u: 'Ç'}, + {}, // Right shift + {} // Space +]; diff --git a/src/layouts/pt_PT.js b/src/layouts/pt_PT.js index 66dc428..d7bfd75 100644 --- a/src/layouts/pt_PT.js +++ b/src/layouts/pt_PT.js @@ -20,7 +20,8 @@ mlKeyboard.layouts.pt_PT = [ {d: 'w',u: 'W'}, {d: 'e',u: 'E', m: [ {d: 'e', u: 'E'}, - {d: 'é', u: 'É'} + {d: 'é', u: 'É'}, + {d: 'ê', u: 'Ê'} ]}, {d: 'r',u: 'R'}, {d: 't',u: 'T'},