This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
jqbtk.min.js
1 lines (1 loc) · 3.85 KB
/
jqbtk.min.js
1
(function(a){a.fn.keyboard=function(d){var f=a.extend({keyboardLayout:[[["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"],["7","7"],["8","8"],["9","9"],["0","0"],["del","del"]],[["q","Q"],["w","W"],["e","E"],["r","R"],["t","T"],["y","Y"],["u","U"],["i","I"],["o","O"],["p","P"],["-","="],["_","+"]],[["a","A"],["s","S"],["d","D"],["f","F"],["g","G"],["h","H"],["j","J"],["k","K"],["l","L"],["'",":"],["@",";"],["#","~"]],[["z","Z"],["x","X"],["c","C"],["v","V"],["b","B"],["n","N"],["m","M"],[",",","],[".","."],["?","!"]],[["shift","shift"],["space","space"],["shift","shift"]]],numpadLayout:[[["7"],["8"],["9"]],[["4"],["5"],["6"]],[["1"],["2"],["3"]],[["del"],["0"],["."]]],telLayout:[[["1"],["2"],["3"]],[["4"],["5"],["6"]],[["7"],["8"],["9"]],[["del"],["0"],["."]]],layout:false,type:false,btnTpl:'<button type="button" tabindex="-1">',btnClasses:"btn btn-default",btnActiveClasses:"active btn-primary",initCaps:false,placement:"bottom",container:"body",trigger:"focus"},d);if(!f.layout){if((a(this).attr("type")==="tel"&&a(this).hasClass("keyboard-numpad"))||f.type==="numpad"){f.layout=f.numpadLayout}else{if((a(this).attr("type")==="tel")||f.type==="tel"){f.layout=f.telLayout}else{f.layout=f.keyboardLayout}}}var b=false;var g=function(j){a(this).addClass(f.btnActiveClasses);var k=a(this).attr("data-value"+(b?"-alt":""));var i=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");var h=i.val();switch(k){case"space":h+=" ";break;case"shift":b=!b;e();break;case"del":h=h.substr(0,h.length-1);break;case"enter":i.closest("form").submit();break;default:h+=k;b=false}i.val(h);e();i.focus()};a(document).off("touchstart",".jqbtk-row .btn");a(document).on("touchstart",".jqbtk-row .btn",g);a(document).off("mousedown",".jqbtk-row .btn");a(document).on("mousedown",".jqbtk-row .btn",function(i){g.bind(this,i)();var h=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");h.focus();i.preventDefault()});a(document).off("mouseup",".jqbtk-row .btn");a(document).on("mouseup",".jqbtk-row .btn",function(i){a(this).removeClass(f.btnActiveClasses);var h=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");h.focus()});a(document).on("click",".jqbtk-row .btn",function(i){var h=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");h.focus()});a(document).on("touchend",".jqbtk-row .btn",function(){a(this).removeClass(f.btnActiveClasses);var h=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");h.focus()});a(document).on("touchend",".jqbtk-row",function(i){i.preventDefault();var h=a("[aria-describedby="+a(this).closest(".popover").attr("id")+"]");h.focus()});var e=function(){a(".jqbtk-container .btn").each(function(){switch(a(this).attr("data-value")){case"shift":case"del":case"space":case"enter":break;default:a(this).text(a(this).attr("data-value"+(b?"-alt":"")))}})};var c=this.data("container");if(c!=undefined){c="#"+c;f.container=c;f.placement="in";f.trigger="manual";a(c).addClass("keyboard-container")}return this.each(function(){a(this).popover({content:function(){if(f.initCaps&&a(this).val().length===0){b=true}var h=a('<div class="jqbtk-container" tabIndex="-1">');a.each(f.layout,function(){var i=this;var j=a('<div class="jqbtk-row">');a.each(i,function(){var k=a(f.btnTpl).addClass(f.btnClasses);k.attr("data-value",this[0]).attr("data-value-alt",this[1]);switch(this[0]){case"shift":k.addClass("jqbtk-shift").html('<span class="glyphicon glyphicon-arrow-up"></span>');break;case"space":k.addClass("jqbtk-space").html(" ");break;case"del":k.addClass("jqbtk-del").html('<span class="glyphicon glyphicon-arrow-left"></span>');break;case"enter":k.addClass("jqbtk-enter").html("Enter");break;default:k.text(k.attr("data-value"+(b?"-alt":"")))}j.append(k)});h.append(j)});return h},html:true,placement:f.placement,trigger:f.trigger,container:f.container,viewport:f.container});if(f.trigger=="manual"){a(this).popover("show")}})}}(jQuery));