Bug 17178: (RM follow-up) Use latest version of library
[koha.git] / koha-tmpl / intranet-tmpl / lib / keyboard / js / jquery.keyboard.min.js
1 /*! jQuery UI Virtual Keyboard v1.30.1 */
2 !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&"object"==typeof module.exports?module.exports=e(require("jquery")):e(jQuery)}(function(y){"use strict";var b=y.keyboard=function(c,o){var p,h=this;h.version="1.30.1",h.$el=y(c),h.el=c,h.$el.data("keyboard",h),h.init=function(){h.initialized=!1;var e,t,a,i=b.css,n=b.events;h.settings=o||{},o&&o.position&&(t=y.extend({},o.position),o.position=null),h.options=p=y.extend(!0,{},b.defaultOptions,o),t&&(p.position=t,o.position=t),h.el.active=!0,h.namespace=".keyboard"+Math.random().toString(16).slice(2),h.extensionNamespace=[],h.shiftActive=h.altActive=h.metaActive=h.sets=h.capsLock=!1,h.rows=["","-shift","-alt","-alt-shift"],h.inPlaceholder=h.$el.attr("placeholder")||"",h.watermark=b.watermark&&""!==h.inPlaceholder,h.repeatTime=1e3/(p.repeatRate||20),p.preventDoubleEventTime=p.preventDoubleEventTime||100,h.isOpen=!1,h.wheel="function"==typeof y.fn.mousewheel,h.escapeRegex=/[-\/\\^$*+?.()|[\]{}]/g,h.isTextArea="textarea"===h.el.nodeName.toLowerCase(),h.isInput="input"===h.el.nodeName.toLowerCase(),h.isContentEditable=!h.isTextArea&&!h.isInput&&h.el.isContentEditable,e=b.keyCodes,h.alwaysAllowed=[e.capsLock,e.pageUp,e.pageDown,e.end,e.home,e.left,e.up,e.right,e.down,e.insert,e.delete],h.$keyboard=[],h.enabled=!0,h.checkCaret=p.lockInput||b.checkCaretSupport(),h.isContentEditable&&(p.usePreview=!1),h.last={start:0,end:0,key:"",val:"",preVal:"",layout:"",virtual:!0,keyset:[!1,!1,!1],wheel_$Keys:[],wheelIndex:0,wheelLayers:[]},h.temp=["",0,0],y.each([n.kbInit,n.kbBeforeVisible,n.kbVisible,n.kbHidden,n.inputCanceled,n.inputAccepted,n.kbBeforeClose,n.inputRestricted],function(e,t){"function"==typeof p[t]&&h.$el.bind(t+h.namespace+"callbacks",p[t])}),p.alwaysOpen&&(p.stayOpen=!0),a=y(document),h.el.ownerDocument!==document&&(a=a.add(h.el.ownerDocument));var s="keyup checkkeyboard mousedown touchstart ";p.closeByClickEvent&&(s+="click "),a.bind(s.split(" ").join(h.namespace+" "),function(e){clearTimeout(h.timer3),h.timer3=setTimeout(function(){h.checkClose(e)},1)}),h.$el.addClass(i.input+" "+p.css.input).attr({"aria-haspopup":"true",role:"textbox"}),(p.lockInput||h.el.readOnly)&&(p.lockInput=!0,h.$el.addClass(i.locked).attr({readonly:"readonly"})),h.isUnavailable()&&h.$el.addClass(i.noKeyboard),p.openOn&&h.bindFocus(),h.watermark||""!==h.getValue(h.$el)||""===h.inPlaceholder||""===h.$el.attr("placeholder")||(h.$el.addClass(i.placeholder),h.setValue(h.inPlaceholder,h.$el)),h.$el.trigger(n.kbInit,[h,h.el]),p.alwaysOpen&&h.reveal(),h.initialized=!0},h.toggle=function(){if(h.hasKeyboard()){var e=h.$keyboard.find("."+b.css.keyToggle),t=!h.enabled;return h.preview.readonly=t||h.options.lockInput,h.$keyboard.toggleClass(b.css.keyDisabled,t).find("."+b.css.keyButton).not(e).attr("aria-disabled",t).each(function(){this.disabled=t}),e.toggleClass(b.css.keyDisabled,t),t&&h.typing_options&&(h.typing_options.text=""),h}},h.setCurrent=function(){var e=b.css,t=y("."+e.isCurrent),a=t.data("keyboard");y.isEmptyObject(a)||a.el===h.el||a.close(!!a.options.autoAccept&&"true"),t.removeClass(e.isCurrent),y("."+e.hasFocus).removeClass(e.hasFocus),h.$el.addClass(e.isCurrent),h.$preview.focus(),h.$keyboard.addClass(e.hasFocus),h.isCurrent(!0),h.isOpen=!0},h.isUnavailable=function(){return h.$el.is(":disabled")||!h.options.activeOnReadonly&&h.$el.attr("readonly")&&!h.$el.hasClass(b.css.locked)},h.isCurrent=function(e){var t=b.currentKeyboard||!1;return e?t=b.currentKeyboard=h.el:!1===e&&t===h.el&&(t=b.currentKeyboard=""),t===h.el},h.hasKeyboard=function(){return h.$keyboard&&0<h.$keyboard.length},h.isVisible=function(){return!!h.hasKeyboard()&&h.$keyboard.is(":visible")},h.setFocus=function(){var e=h.$preview||h.$el;p.noFocus||e.focus(),h.isContentEditable?b.setEditableCaret(e,h.last.start,h.last.end):b.caret(e,h.last)},h.focusOn=function(){!h&&h.el.active||(h.isVisible()?h.setCurrent():(clearTimeout(h.timer),h.reveal()))},h.redraw=function(e){return e&&(h.options.layout=e),h.$keyboard.length&&(h.last.preVal=""+h.last.val,h.saveLastChange(),h.setValue(h.last.val,h.$el),h.removeKeyboard(),h.shiftActive=h.altActive=h.metaActive=!1),h.isOpen=p.alwaysOpen,h.reveal(!0),h},h.reveal=function(e){var t,a=h.isOpen,i=b.css;if(h.opening=!a,y("."+i.keyboard).not("."+i.alwaysOpen).each(function(){var e=y(this).data("keyboard");y.isEmptyObject(e)||e.close(!!e.options.autoAccept&&"true")}),!h.isUnavailable())return h.$el.removeClass(i.noKeyboard),p.openOn&&h.$el.unbind(y.trim((p.openOn+" ").split(/\s+/).join(h.namespace+" "))),h.$keyboard&&(!h.$keyboard||h.$keyboard.length&&!y.contains(h.el.ownerDocument.body,h.$keyboard[0]))||h.startup(),h.watermark||h.getValue()!==h.inPlaceholder||(h.$el.removeClass(i.placeholder),h.setValue("",h.$el)),h.originalContent=h.isContentEditable?h.$el.html():h.getValue(h.$el),h.el===h.preview||h.isContentEditable||h.setValue(h.originalContent),p.acceptValid&&p.checkValidOnInit&&h.checkValid(),p.resetDefault&&(h.shiftActive=h.altActive=h.metaActive=!1),h.showSet(),h.isVisible()||h.$el.trigger(b.events.kbBeforeVisible,[h,h.el]),(h.initialized||p.initialFocus||!p.initialFocus&&h.$el.hasClass(b.css.initialFocus))&&h.setCurrent(),h.toggle(),h.$keyboard.show(),p.usePreview&&b.msie&&(void 0===h.width&&(h.$preview.hide(),h.width=Math.ceil(h.$keyboard.width()),h.$preview.show()),h.$preview.width(h.width)),h.reposition(),h.checkDecimal(),h.lineHeight=parseInt(h.$preview.css("lineHeight"),10)||parseInt(h.$preview.css("font-size"),10)+4,p.caretToEnd&&(t=h.isContentEditable?b.getEditableLength(h.el):h.originalContent.length,h.saveCaret(t,t)),b.allie&&(0===h.last.end&&0<h.last.start&&(h.last.end=h.last.start),h.last.start<0&&(h.last.start=h.last.end=h.originalContent.length)),a||e?(b.caret(h.$preview,h.last),h.opening=!1):h.timer2=setTimeout(function(){var e;h.opening=!1,/(number|email)/i.test(h.el.type)||p.caretToEnd||h.saveCaret(e,e,h.$el),(p.initialFocus||h.$el.hasClass(b.css.initialFocus))&&b.caret(h.$preview,h.last),h.last.eventTime=(new Date).getTime(),h.$el.trigger(b.events.kbVisible,[h,h.el]),h.timer=setTimeout(function(){h&&h.saveCaret()},200)},10),h},h.updateLanguage=function(){var e=b.layouts,t=p.language||e[p.layout]&&e[p.layout].lang&&e[p.layout].lang||[p.language||"en"],a=b.language;t="[object Array]"===Object.prototype.toString.call(t)?t[0]:t,t=(h.language=t).split("-")[0],p.display=y.extend(!0,{},a.en.display,a[t]&&a[t].display||{},h.settings.display),p.combos=y.extend(!0,{},a.en.combos,a[t]&&a[t].combos||{},h.settings.combos),p.wheelMessage=a[t]&&a[t].wheelMessage||a.en.wheelMessage,p.rtl=e[p.layout]&&e[p.layout].rtl||a[t]&&a[t].rtl||!1,a[t]&&a[t].comboRegex&&(h.regex=a[t].comboRegex),h.decimal=/^\./.test(p.display.dec),h.$el.toggleClass("rtl",p.rtl).css("direction",p.rtl?"rtl":"")},h.startup=function(){var e=b.css;(p.alwaysOpen||p.userClosed)&&h.$preview||h.makePreview(),h.hasKeyboard()||("custom"===p.layout&&(p.layoutHash="custom"+h.customHash()),h.layout="custom"===p.layout?p.layoutHash:p.layout,h.last.layout=h.layout,h.updateLanguage(),void 0===b.builtLayouts[h.layout]&&("function"==typeof p.create?h.$keyboard=p.create(h):h.$keyboard.length||h.buildKeyboard(h.layout,!0)),h.$keyboard=b.builtLayouts[h.layout].$keyboard.clone(),h.$keyboard.data("keyboard",h),""!==(h.el.id||"")&&h.$keyboard.attr("id",h.el.id+b.css.idSuffix),h.makePreview()),h.$keyboard.attr("data-"+e.keyboard+"-layout",p.layout).attr("data-"+e.keyboard+"-language",h.language),h.$decBtn=h.$keyboard.find("."+e.keyPrefix+"dec"),(p.enterNavigation||h.isTextArea)&&h.alwaysAllowed.push(b.keyCodes.enter),h.bindKeyboard(),h.$keyboard.appendTo(p.appendLocally?h.$el.parent():p.appendTo||"body"),h.bindKeys(),p.reposition&&y.ui&&y.ui.position&&"body"===p.appendTo&&y(window).bind("resize"+h.namespace,function(){h.reposition()})},h.reposition=function(){return h.position=!y.isEmptyObject(p.position)&&p.position,y.ui&&y.ui.position&&h.position&&(h.position.of=h.position.of||h.$el.data("keyboardPosition")||h.$el,h.position.collision=h.position.collision||"flipfit flipfit",h.position.at=p.usePreview?p.position.at:p.position.at2,h.isVisible()&&h.$keyboard.position(h.position)),h},h.makePreview=function(){if(p.usePreview){var e,t,a,i,n=b.css;for(h.$preview=h.$el.clone(!1).data("keyboard",h).removeClass(n.placeholder+" "+n.input).addClass(n.preview+" "+p.css.input).attr("tabindex","-1").show(),h.preview=h.$preview[0],"number"===h.preview.type&&(h.preview.type="text"),i=/^(data-|id|aria-haspopup)/i,e=(t=h.$preview.get(0).attributes).length-1;0<=e;e--)a=t[e]&&t[e].name,i.test(a)&&h.preview.removeAttribute(a);y("<div />").addClass(n.wrapper).append(h.$preview).prependTo(h.$keyboard)}else h.$preview=h.$el,h.preview=h.el},h.caret=function(e,t){var a=b.caret(h.$preview,e,t);return a instanceof y?(h.saveCaret(a.start,a.end),h):a},h.saveCaret=function(e,t,a){var i;h.isCurrent()&&(i=void 0===e?b.caret(a||h.$preview):b.caret(a||h.$preview,e,t),h.last.start=void 0===e?i.start:e,h.last.end=void 0===t?i.end:t)},h.saveLastChange=function(e){h.last.val=e||h.getValue(h.$preview||h.$el),h.isContentEditable&&(h.last.elms=h.el.cloneNode(!0))},h.setScroll=function(){if(!h.isContentEditable&&h.last.virtual){var e,t,a,i,n=h.last.val.substring(0,Math.max(h.last.start,h.last.end));h.$previewCopy||(h.$previewCopy=h.$preview.clone().removeAttr("id").css({position:"absolute",left:0,zIndex:-10,visibility:"hidden"}).addClass(b.css.inputClone),h.$previewCopy[0].disabled=!0,h.isTextArea||h.$previewCopy.css({"white-space":"pre",width:0}),p.usePreview?h.$preview.after(h.$previewCopy):h.$keyboard.prepend(h.$previewCopy)),h.isTextArea?(h.$previewCopy.height(h.lineHeight).val(n),h.preview.scrollTop=h.lineHeight*(Math.floor(h.$previewCopy[0].scrollHeight/h.lineHeight)-1)):(h.$previewCopy.val(n.replace(/\s/g," ")),a=/c/i.test(p.scrollAdjustment)?h.preview.clientWidth/2:p.scrollAdjustment,e=h.$previewCopy[0].scrollWidth-1,void 0===h.last.scrollWidth&&(h.last.scrollWidth=e,h.last.direction=!0),i=h.last.scrollWidth===e?h.last.direction:h.last.scrollWidth<e,t=h.preview.clientWidth-a,i?h.preview.scrollLeft=e<t?0:e-t:e>=h.preview.scrollWidth-t?h.preview.scrollLeft=h.preview.scrollWidth-a:h.preview.scrollLeft=0<e-a?e-a:0,h.last.scrollWidth=e,h.last.direction=i)}},h.bindFocus=function(){p.openOn&&h&&h.el.active&&(h.$el.bind(p.openOn+h.namespace,function(){h.focusOn()}),y(":focus")[0]===h.el&&h.$el.blur())},h.bindKeyboard=function(){var s,o=b.keyCodes,r=b.builtLayouts[h.layout],e=h.namespace+"keybindings";h.$preview.unbind(h.namespace).bind("click"+e+" touchstart"+e,function(){p.alwaysOpen&&!h.isCurrent()&&h.reveal(),h.timer2=setTimeout(function(){h&&h.saveCaret()},150)}).bind("keypress"+e,function(e){if(p.lockInput)return!1;if(h.isCurrent()){var t=e.charCode||e.which,a=t>=o.A&&t<=o.Z,i=t>=o.a&&t<=o.z,n=h.last.key=String.fromCharCode(t);if(!(t<o.space)){if(h.last.virtual=!1,h.last.event=e,h.last.$key=[],h.checkCaret&&h.saveCaret(),t!==o.capsLock&&(a||i)&&(h.capsLock=a&&!e.shiftKey||i&&e.shiftKey,h.capsLock&&!h.shiftActive&&(h.shiftActive=!0,h.showSet())),p.restrictInput){if((e.which===o.backSpace||0===e.which)&&y.inArray(e.keyCode,h.alwaysAllowed))return;-1===y.inArray(n,r.acceptedKeys)&&(e.preventDefault(),(s=y.extend({},e)).type=b.events.inputRestricted,h.$el.trigger(s,[h,h.el]))}else if((e.ctrlKey||e.metaKey)&&(e.which===o.A||e.which===o.C||e.which===o.V||e.which>=o.X&&e.which<=o.Z))return;r.hasMappedKeys&&r.mappedKeys.hasOwnProperty(n)&&(h.last.key=r.mappedKeys[n],h.insertText(h.last.key),e.preventDefault()),"function"==typeof p.beforeInsert&&(h.insertText(h.last.key),e.preventDefault()),h.checkMaxLength()}}}).bind("keyup"+e,function(e){if(h.isCurrent()){switch(h.last.virtual=!1,e.which){case o.tab:if(h.tab&&!p.lockInput){h.shiftActive=e.shiftKey;var t=b.keyaction.tab(h);if(h.tab=!1,!t)return!1}else e.preventDefault();break;case o.escape:return p.ignoreEsc||h.close(!(!p.autoAccept||!p.autoAcceptOnEsc)&&"true"),!1}clearTimeout(h.throttled),h.throttled=setTimeout(function(){h&&h.isVisible()&&h.checkCombos()},100),h.checkMaxLength(),h.last.preVal=""+h.last.val,h.saveLastChange();var a=y.Event(b.events.kbChange);if(a.action=h.last.key,h.$el.trigger(a,[h,h.el]),"function"==typeof p.change)return a.type=b.events.inputChange,p.change(a,h,h.el),!1;p.acceptValid&&p.autoAcceptOnValid&&"function"==typeof p.validate&&p.validate(h,h.getValue(h.$preview))&&(h.$preview.blur(),h.accept())}}).bind("keydown"+e,function(e){if(h.last.keyPress=e.which,p.alwaysOpen&&!h.isCurrent()&&h.reveal(),e.which===o.tab)return!(h.tab=!0);if(p.lockInput||e.timeStamp===h.last.timeStamp)return!p.lockInput;switch(h.last.timeStamp=e.timeStamp,h.last.virtual=!1,e.which){case o.backSpace:b.keyaction.bksp(h,null,e),e.preventDefault();break;case o.enter:b.keyaction.enter(h,null,e);break;case o.capsLock:h.shiftActive=h.capsLock=!h.capsLock,h.showSet();break;case o.V:if(e.ctrlKey||e.metaKey){if(p.preventPaste)return void e.preventDefault();h.checkCombos()}}}).bind("mouseup touchend ".split(" ").join(e+" "),function(){h.last.virtual=!0,h.saveCaret()}),h.$keyboard.bind("mousedown click touchstart ".split(" ").join(h.namespace+" "),function(e){e.stopPropagation(),h.isCurrent()||(h.reveal(),y(h.el.ownerDocument).trigger("checkkeyboard"+h.namespace)),h.setFocus()}),p.preventPaste&&(h.$preview.bind("contextmenu"+h.namespace,function(e){e.preventDefault()}),h.$el.bind("contextmenu"+h.namespace,function(e){e.preventDefault()}))},h.bindButton=function(e,t){var a="."+b.css.keyButton,i=function(e){e.stopPropagation(),e.$target=y(this).closest("."+b.css.keyboard+", ."+b.css.input),t.call(this,e)};return y.fn.on?h.$keyboard.on(e,a,i):y.fn.delegate&&h.$keyboard.delegate(a,e,i),h},h.unbindButton=function(e){return y.fn.off?h.$keyboard.off(e):y.fn.undelegate&&h.$keyboard.undelegate("."+b.css.keyButton,e),h},h.bindKeys=function(){var s=b.css;h.unbindButton(h.namespace+" "+h.namespace+"kb").bindButton("mouseenter mouseleave touchstart ".split(" ").join(h.namespace+" "),function(e){if(!p.alwaysOpen&&!p.userClosed||"mouseleave"===e.type||h.isCurrent()||(h.reveal(),h.setFocus()),h.isCurrent()&&!this.disabled){var t,a,i=h.last,n=y(this),s=e.type;p.useWheel&&h.wheel&&(t=h.getLayers(n),a=(t.length?t.map(function(){return y(this).attr("data-value")||""}).get():"")||[n.text()],i.wheel_$Keys=t,i.wheelLayers=a,i.wheelIndex=y.inArray(n.attr("data-value"),a)),"mouseenter"!==s&&"touchstart"!==s||"password"===h.el.type||n.hasClass(p.css.buttonDisabled)||(n.addClass(p.css.buttonHover),p.useWheel&&h.wheel&&n.attr("title",function(e,t){return h.wheel&&""===t&&h.sets&&1<a.length&&"touchstart"!==s?p.wheelMessage:t})),"mouseleave"===s&&(n.removeClass("password"===h.el.type?"":p.css.buttonHover),p.useWheel&&h.wheel&&(i.wheelIndex=0,i.wheelLayers=[],i.wheel_$Keys=[],n.attr("title",function(e,t){return t===p.wheelMessage?"":t}).html(n.attr("data-html"))))}}).bindButton(p.keyBinding.split(" ").join(h.namespace+" ")+h.namespace+" "+b.events.kbRepeater,function(e){if(e.preventDefault(),!h.$keyboard.is(":visible")||this.disabled)return!1;var t,a=h.last,i=y(this),n=(new Date).getTime();if(p.useWheel&&h.wheel&&(i=a.wheel_$Keys.length&&-1<a.wheelIndex?a.wheel_$Keys.eq(a.wheelIndex):i),t=i.attr("data-action"),!(n-(a.eventTime||0)<p.preventDoubleEventTime)){if(a.eventTime=n,a.event=e,a.virtual=!0,a.$key=i,a.key=i.attr("data-value"),a.keyPress="",h.setFocus(),/^meta/.test(t)&&(t="meta"),t===a.key&&"string"==typeof b.keyaction[t])a.key=t=b.keyaction[t];else if(t in b.keyaction&&"function"==typeof b.keyaction[t]){if(!1===b.keyaction[t](h,this,e))return!1;t=null}return!!h.hasKeyboard()&&(null!=t&&(a.key=y(this).hasClass(s.keyAction)?t:a.key,h.insertText(a.key),h.capsLock||p.stickyShift||e.shiftKey||(h.shiftActive=!1,h.showSet(i.attr("data-name")))),b.caret(h.$preview,a),h.checkCombos(),(e=y.extend({},e,y.Event(b.events.kbChange))).target=h.el,e.action=a.key,h.$el.trigger(e,[h,h.el]),a.preVal=""+a.val,h.saveLastChange(),"function"==typeof p.change?(e.type=b.events.inputChange,p.change(e,h,h.el),!1):void 0)}}).bindButton("mouseup"+h.namespace+" "+"mouseleave touchend touchmove touchcancel ".split(" ").join(h.namespace+"kb "),function(e){h.last.virtual=!0;var t,a=y(this);if("touchmove"===e.type){if((t=a.offset()).right=t.left+a.outerWidth(),t.bottom=t.top+a.outerHeight(),e.originalEvent.touches[0].pageX>=t.left&&e.originalEvent.touches[0].pageX<t.right&&e.originalEvent.touches[0].pageY>=t.top&&e.originalEvent.touches[0].pageY<t.bottom)return!0}else/(mouseleave|touchend|touchcancel)/i.test(e.type)?a.removeClass(p.css.buttonHover):(!p.noFocus&&h.isCurrent()&&h.isVisible()&&h.$preview.focus(),h.checkCaret&&b.caret(h.$preview,h.last));return h.mouseRepeat=[!1,""],clearTimeout(h.repeater),p.acceptValid&&p.autoAcceptOnValid&&"function"==typeof p.validate&&p.validate(h,h.getValue())&&(h.$preview.blur(),h.accept()),!1}).bindButton("click"+h.namespace,function(){return!1}).bindButton("mousewheel"+h.namespace,h.throttleEvent(function(e,t){var a=y(this);if(a&&!a.hasClass(s.keyAction)&&h.last.wheel_$Keys[0]===this&&p.useWheel&&h.wheel){t=t||e.deltaY;var i,n=h.last.wheelLayers||[];return 1<n.length?((i=h.last.wheelIndex+(0<t?-1:1))>n.length-1&&(i=0),i<0&&(i=n.length-1)):i=0,h.last.wheelIndex=i,a.html(n[i]),!1}},30)).bindButton("mousedown touchstart ".split(" ").join(h.namespace+"kb "),function(){var e=y(this);if(e&&(!e.hasClass(s.keyAction)||e.is("."+s.keyPrefix+"tab bksp space enter".split(" ").join(",."+s.keyPrefix))))return 0!==p.repeatRate&&(h.mouseRepeat=[!0,e],setTimeout(function(){h&&h.mouseRepeat[0]&&h.mouseRepeat[1]===e&&!e[0].disabled&&h.repeatKey(e)},p.repeatDelay)),!1})},h.throttleEvent=function(e,t){var a;return function(){a||(e.apply(this,arguments),a=!0,setTimeout(function(){a=!1},t))}},h.execCommand=function(e,t){h.el.ownerDocument.execCommand(e,!1,t),h.el.normalize(),p.reposition&&h.reposition()},h.getValue=function(e){return(e=e||h.$preview)[h.isContentEditable?"text":"val"]()},h.setValue=function(e,t){return t=t||h.$preview,h.isContentEditable?e!==t.text()&&(b.replaceContent(t,e),h.saveCaret()):t.val(e),h},h.insertText=function(e){if(!h.$preview)return h;if("function"==typeof p.beforeInsert&&(e=p.beforeInsert(h.last.event,h,h.el,e)),void 0===e||!1===e)return h.last.key="",h;if(h.isContentEditable)return h.insertContentEditable(e);var t,a=!1,i="\b"===e,n=h.getValue(),s=b.caret(h.$preview),o=n.length;return s.end<s.start&&(s.end=s.start),s.start>o&&(s.end=s.start=o),h.isTextArea&&b.msie&&"\n"===n.substring(s.start,s.start+1)&&(s.start+=1,s.end+=1),t=s.start,"{d}"===e&&(e="",s.end+=1),i&&(e="",a=i&&t===s.end&&0<t),n=n.substring(0,t-(a?1:0))+e+n.substring(s.end),t+=a?-1:e.length,h.setValue(n),h.saveCaret(t,t),h.setScroll(),h},h.insertContentEditable=function(e){return h.$preview.focus(),h.execCommand("insertText",e),h.saveCaret(),h},h.checkMaxLength=function(){if(h.$preview){var e,t,a=h.getValue(),i=h.isContentEditable?b.getEditableLength(h.el):a.length;return!1!==p.maxLength&&i>p.maxLength&&(e=b.caret(h.$preview).start,t=Math.min(e,p.maxLength),p.maxInsert||(a=h.last.val,t=e-1),h.setValue(a.substring(0,p.maxLength)),h.saveCaret(t,t)),h.$decBtn.length&&h.checkDecimal(),h}},h.repeatKey=function(e){e.trigger(b.events.kbRepeater),h.mouseRepeat[0]&&(h.repeater=setTimeout(function(){h&&h.repeatKey(e)},h.repeatTime))},h.getKeySet=function(){var e=[];return h.altActive&&e.push("alt"),h.shiftActive&&e.push("shift"),h.metaActive&&e.push(h.metaActive),e.length?e.join("+"):"normal"},h.showKeySet=function(e){return"string"==typeof e?(h.last.keyset=[h.shiftActive,h.altActive,h.metaActive],h.shiftActive=/shift/i.test(e),h.altActive=/alt/i.test(e),/\bmeta/.test(e)?(h.metaActive=!0,h.showSet(e.match(/\bmeta[\w-]+/i)[0])):(h.metaActive=!1,h.showSet())):h.showSet(e),h},h.showSet=function(e){if(h.hasKeyboard()){p=h.options;var t=b.css,a="."+t.keyPrefix,i=p.css.buttonActive,n="",s=(h.shiftActive?1:0)+(h.altActive?2:0);if(h.shiftActive||(h.capsLock=!1),h.metaActive?(h.shiftActive&&(e=(e||"").replace("-shift","")),h.altActive&&(e=(e||"").replace("-alt","")),""===(n=/^meta/i.test(e)?e:"")?n=!0===h.metaActive?"":h.metaActive:h.metaActive=n,(!p.stickyShift&&h.last.keyset[2]!==h.metaActive||(h.shiftActive||h.altActive)&&!h.$keyboard.find("."+t.keySet+"-"+n+h.rows[s]).length)&&(h.shiftActive=h.altActive=!1)):!p.stickyShift&&h.last.keyset[2]!==h.metaActive&&h.shiftActive&&(h.shiftActive=h.altActive=!1),n=0!==(s=(h.shiftActive?1:0)+(h.altActive?2:0))||h.metaActive?""===n?"":"-"+n:"-normal",!h.$keyboard.find("."+t.keySet+n+h.rows[s]).length)return h.shiftActive=h.last.keyset[0],h.altActive=h.last.keyset[1],void(h.metaActive=h.last.keyset[2]);h.$keyboard.find(a+"alt,"+a+"shift,."+t.keyAction+"[class*=meta]").removeClass(i).end().find(a+"alt").toggleClass(i,h.altActive).end().find(a+"shift").toggleClass(i,h.shiftActive).end().find(a+"lock").toggleClass(i,h.capsLock).end().find("."+t.keySet).hide().end().find("."+(t.keyAction+a+n).replace("--","-")).addClass(i),h.$keyboard.find("."+t.keySet+n+h.rows[s])[0].style.display="inline-block",h.metaActive&&h.$keyboard.find(a+h.metaActive).toggleClass(i,!1!==h.metaActive),h.last.keyset=[h.shiftActive,h.altActive,h.metaActive],h.$el.trigger(b.events.kbKeysetChange,[h,h.el]),p.reposition&&h.reposition()}},h.checkCombos=function(){if(!(h.isVisible()||h.hasKeyboard()&&h.$keyboard.hasClass(b.css.hasFocus)))return h.getValue(h.$preview||h.$el);var e,t,a,i,n=h.getValue(),s=b.caret(h.$preview),o=b.builtLayouts[h.layout],r=h.isContentEditable?b.getEditableLength(h.el):n.length,l=r;return""===n||(s.end<s.start&&(s.end=s.start),s.start>l&&(s.end=s.start=l),b.msie&&"\n"===n.substring(s.start,s.start+1)&&(s.start+=1,s.end+=1),p.useCombos&&(b.msie?n=n.replace(h.regex,function(e,t,a){return p.combos.hasOwnProperty(t)&&p.combos[t][a]||e}):h.$preview.length&&(t=s.start-(0<=s.start-2?2:0),b.caret(h.$preview,t,s.end),a=(i=function(e){return(e||"").replace(h.regex,function(e,t,a){return p.combos.hasOwnProperty(t)&&p.combos[t][a]||e})})((t=b.caret(h.$preview)).text),t&&t.replaceStr&&a!==t.text&&(h.isContentEditable?b.replaceContent(c,i):h.setValue(t.replaceStr(a))),n=h.getValue())),p.restrictInput&&""!==n&&(t=o.acceptedKeys.length,(e=o.acceptedKeysRegex)||(a=y.map(o.acceptedKeys,function(e){return e.replace(h.escapeRegex,"\\$&")}),-1<h.alwaysAllowed.indexOf(b.keyCodes.enter)&&a.push("\\n"),e=o.acceptedKeysRegex=new RegExp("("+a.join("|")+")","g")),(a=n.match(e))?n=a.join(""):(n="",l=0)),s.start+=r-l,s.end+=r-l,h.setValue(n),h.saveCaret(s.start,s.end),h.setScroll(),h.checkMaxLength()),p.acceptValid&&h.checkValid(),n},h.checkValid=function(){var e=b.css,t=h.$keyboard.find("."+e.keyPrefix+"accept"),a=!0;"function"==typeof p.validate&&(a=p.validate(h,h.getValue(),!1)),t.toggleClass(e.inputInvalid,!a).toggleClass(e.inputValid,a).attr("title",t.attr("data-title")+" ("+p.display[a?"valid":"invalid"]+")")},h.checkDecimal=function(){h.decimal&&/\./g.test(h.preview.value)||!h.decimal&&/\,/g.test(h.preview.value)?h.$decBtn.attr({disabled:"disabled","aria-disabled":"true"}).removeClass(p.css.buttonHover).addClass(p.css.buttonDisabled):h.$decBtn.removeAttr("disabled").attr({"aria-disabled":"false"}).addClass(p.css.buttonDefault).removeClass(p.css.buttonDisabled)},h.getLayers=function(e){var t=b.css,a=e.attr("data-pos");return e.closest("."+t.keyboard).find('button[data-pos="'+a+'"]').filter(function(){return""!==y(this).find("."+t.keyText).text()}).add(e)},h.switchInput=function(e,t){if("function"==typeof p.switchInput)p.switchInput(h,e,t);else{h.$keyboard.length&&h.$keyboard.hide();var a,i=!1,n=y("button, input, select, textarea, a, [contenteditable]").filter(":visible").not(":disabled"),s=n.index(h.$el)+(e?1:-1);if(h.$keyboard.length&&h.$keyboard.show(),s>n.length-1&&(i=p.stopAtEnd,s=0),s<0&&(i=p.stopAtEnd,s=n.length-1),!i){if(!(t=h.close(t)))return;(a=n.eq(s).data("keyboard"))&&a.options.openOn.length?a.focusOn():n.eq(s).focus()}}return!1},h.close=function(e){if(h.isOpen&&h.$keyboard.length){clearTimeout(h.throttled);var t=b.css,a=b.events,i=e?h.checkCombos():h.originalContent;if(e&&"function"==typeof p.validate&&!p.validate(h,i,!0)&&(i=h.originalContent,e=!1,p.cancelClose))return;h.isCurrent(!1),h.isOpen=p.alwaysOpen||p.userClosed,h.isContentEditable&&!e?h.$el.html(i):h.setValue(i,h.$el),h.$el.removeClass(t.isCurrent+" "+t.inputAutoAccepted).addClass(e?!0===e?"":t.inputAutoAccepted:"").trigger(a.inputChange),p.alwaysOpen||h.$el.trigger(a.kbBeforeClose,[h,h.el,e||!1]),b.caret(h.$preview,h.last),h.$el.trigger(e?a.inputAccepted:a.inputCanceled,[h,h.el]).trigger(p.alwaysOpen?a.kbInactive:a.kbHidden,[h,h.el]).blur(),h&&(h.last.eventTime=(new Date).getTime(),p.alwaysOpen||p.userClosed&&"true"===e||!h.$keyboard.length||(h.removeKeyboard(),h.timer=setTimeout(function(){h&&h.bindFocus()},200)),h.watermark||""!==h.el.value||""===h.inPlaceholder||(h.$el.addClass(t.placeholder),h.setValue(h.inPlaceholder,h.$el)))}return!!e},h.accept=function(){return h.close(!0)},h.checkClose=function(e){if(!h.opening){var t=y.keyboard.css,a=e.$target||y(e.target).closest("."+b.css.keyboard+", ."+b.css.input);if(a.length||(a=y(e.target)),a.length&&a.hasClass(t.keyboard)){var i=a.data("keyboard");i!==h&&!i.$el.hasClass(t.isCurrent)&&i.options.openOn&&e.type===p.openOn&&i.focusOn()}else h.escClose(e,a)}},h.escCloseCallback={keepOpen:function(){return!h.isOpen}},h.escClose=function(e,t){if(h.isOpen){if(e&&"keyup"===e.type)return e.which!==b.keyCodes.escape||p.ignoreEsc?"":h.close(!(!p.autoAccept||!p.autoAcceptOnEsc)&&"true");var a=!1,i=t.length&&t||y(e.target);if(y.each(h.escCloseCallback,function(e,t){"function"==typeof t&&(a=a||t(i))}),!a&&(!h.isCurrent()&&h.isOpen||h.isOpen&&i[0]!==h.el)){if((p.stayOpen||p.userClosed)&&!i.hasClass(b.css.input))return;if(b.allie&&e.preventDefault(),p.closeByClickEvent){var n=i[0]&&i[0].nodeName.toLowerCase();"input"!==n&&"textarea"!==n&&"click"!==e.type||h.close(!!p.autoAccept&&"true")}else h.close(!!p.autoAccept&&"true")}}},h.keyBtn=y("<button />").attr({role:"button",type:"button","aria-disabled":"false",tabindex:"-1"}).addClass(b.css.keyButton),h.processName=function(e){var t,a,i=(e||"").replace(/[^a-z0-9-_]/gi,""),n=i.length,s=[];if(1<n&&e===i)return e;if(n=e.length){for(t=0;t<n;t++)a=e[t],s.push(/[a-z0-9-_]/i.test(a)?/[-_]/.test(a)&&0!==t?"":a:(0===t?"":"-")+a.charCodeAt(0));return s.join("")}return e},h.processKeys=function(e){var t,a,i=e.indexOf("</"),n={name:e,map:"",title:""};return-1<i||(a=e.split(/:(?!\/\/)/),/\(.+\)/.test(a[0])||/^:\(.+\)/.test(e)||/\([(:)]\)/.test(e)?/\([(:)]\)/.test(e)?(t=a[0].match(/([^(]+)\((.+)\)/))&&t.length?(n.name=t[1],n.map=t[2],n.title=1<a.length?a.slice(1).join(":"):""):(n.name=e.match(/([^(]+)/)[0],":"===n.name&&(a=a.slice(1)),null===t&&(n.map=":",a=a.slice(2)),n.title=a.length?a.join(":"):""):(n.map=e.match(/\(([^()]+?)\)/)[1],""===(t=(e=e.replace(/\(([^()]+)\)/,"")).split(":"))[0]?(n.name=":",a=a.slice(1)):n.name=t[0],n.title=1<a.length?a.slice(1).join(":"):""):(""!==e&&""===a[0]?(n.name=":",a=a.slice(1)):n.name=a[0],n.title=1<a.length?a.slice(1).join(":"):""),n.title=y.trim(n.title).replace(/_/g," ")),n},h.addKey=function(e,t,a){var i,n,s,o={},r=h.processKeys(a?e:t),l=b.css;return!a&&p.display[r.name]?(s=h.processKeys(p.display[r.name])).action=h.processKeys(e).name:(s=r).action=r.name,o.name=h.processName(r.name),""!==s.name&&(""!==s.map?(b.builtLayouts[h.layout].mappedKeys[s.map]=s.name,b.builtLayouts[h.layout].acceptedKeys.push(s.name)):a&&b.builtLayouts[h.layout].acceptedKeys.push(s.name)),i=a?""===o.name?"":l.keyPrefix+o.name:l.keyAction+" "+l.keyPrefix+s.action,i+=(2<s.name.length?" "+l.keyWide:"")+" "+p.css.buttonDefault,o.html='<span class="'+l.keyText+'">'+s.name+"</span>",o.$key=h.keyBtn.clone().attr({"data-value":a?s.name:s.action,"data-name":s.action,"data-pos":h.temp[1]+","+h.temp[2],"data-action":s.action,"data-html":o.html}).addClass(i).html(o.html).appendTo(h.temp[0]),s.map&&o.$key.attr("data-mapped",s.map),(s.title||r.title)&&o.$key.attr({"data-title":r.title||s.title,title:r.title||s.title}),"function"==typeof p.buildKey&&(n=(o=p.buildKey(h,o)).$key.html(),o.$key.attr("data-html",n)),o.$key},h.customHash=function(e){var t,a,i,n,s=[],o=[];for(a in e=void 0===e?p.customLayout:e)e.hasOwnProperty(a)&&s.push(e[a]);if((i=0)===(n=(o=o.concat.apply(o,s).join(" ")).length))return i;for(t=0;t<n;t++)i=(i<<5)-i+o.charCodeAt(t),i&=i;return i},h.buildKeyboard=function(e,t){y.isEmptyObject(p.display)&&h.updateLanguage();var a,i,n,s,o=b.css,r=0,l=b.builtLayouts[e||h.layout||p.layout]={mappedKeys:{},acceptedKeys:[]},c=l.acceptedKeys=p.restrictInclude&&(""+p.restrictInclude).split(/\s+/)||[],d=o.keyboard+" "+p.css.popup+" "+p.css.container+(p.alwaysOpen||p.userClosed?" "+o.alwaysOpen:""),u=y("<div />").addClass(d).attr({role:"textbox"}).hide();return-1<(a=y.inArray("{space}",c))&&(c[a]=" "),d=t&&"custom"===p.layout||!b.layouts.hasOwnProperty(p.layout)?(p.layout="custom",b.layouts.custom=p.customLayout||{normal:["{cancel}"]}):b.layouts[t?p.layout:e||h.layout||p.layout],y.each(d,function(e,t){if(""!==e&&!/^(name|lang|rtl)$/i.test(e))for("default"===e&&(e="normal"),r++,n=y("<div />").attr("name",e).addClass(o.keySet+" "+o.keySet+"-"+e).appendTo(u).toggle("normal"===e),i=0;i<t.length;i++)s=y.trim(t[i]).replace(/\{(\.?)[\s+]?:[\s+]?(\.?)\}/g,"{$1:$2}"),h.buildRow(n,i,s.split(/\s+/),c),n.find("."+o.keyButton+",."+o.keySpacer).filter(":last").after('<br class="'+o.endRow+'"/>')}),1<r&&(h.sets=!0),l.hasMappedKeys=!y.isEmptyObject(l.mappedKeys),l.$keyboard=u},h.buildRow=function(e,t,a,i){var n,s,o,r,l,c,d=b.css;for(o=0;o<a.length;o++)if(r=!(h.temp=[e,t,o]),0!==a[o].length)if(/^\{\S+\}$/.test(a[o])){if(l=a[o].match(/^\{(\S+)\}$/)[1],/\!\!/.test(l)&&(l=l.replace("!!",""),r=!0),/^sp:((\d+)?([\.|,]\d+)?)(em|px)?$/i.test(l)&&(c=parseFloat(l.replace(/,/,".").match(/^sp:((\d+)?([\.|,]\d+)?)(em|px)?$/i)[1]||0),y('<span class="'+d.keyText+'"></span>').width(l.match(/px/i)?c+"px":2*c+"em").addClass(d.keySpacer).appendTo(e)),/^empty(:((\d+)?([\.|,]\d+)?)(em|px)?)?$/i.test(l)){c=/:/.test(l)?parseFloat(l.replace(/,/,".").match(/^empty:((\d+)?([\.|,]\d+)?)(em|px)?$/i)[1]||0):"",h.addKey(""," ",!0).addClass(p.css.buttonDisabled+" "+p.css.buttonEmpty).attr("aria-disabled",!0).width(c?l.match("px")?c+"px":2*c+"em":"");continue}if(/^meta[\w-]+\:?(\w+)?/i.test(l)){h.addKey(l.split(":")[0],l).addClass(d.keyHasActive);continue}switch((s=l.split(":"))[0].toLowerCase()){case"a":case"accept":h.addKey("accept",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"alt":case"altgr":h.addKey("alt",l).addClass(d.keyHasActive);break;case"b":case"bksp":h.addKey("bksp",l);break;case"c":case"cancel":h.addKey("cancel",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"combo":h.addKey("combo",l).addClass(d.keyHasActive).attr("title",function(e,t){return t+" "+p.display[p.useCombos?"active":"disabled"]}).toggleClass(p.css.buttonActive,p.useCombos);break;case"dec":i.push(h.decimal?".":","),h.addKey("dec",l);break;case"e":case"enter":h.addKey("enter",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"lock":h.addKey("lock",l).addClass(d.keyHasActive);break;case"s":case"shift":h.addKey("shift",l).addClass(d.keyHasActive);break;case"sign":i.push("-"),h.addKey("sign",l);break;case"space":i.push(" "),h.addKey("space",l);break;case"t":case"tab":h.addKey("tab",l);break;default:b.keyaction.hasOwnProperty(s[0])&&h.addKey(s[0],l).toggleClass(p.css.buttonAction+" "+d.keyAction,r)}}else n=a[o],h.addKey(n,n,!0)},h.removeBindings=function(e){y(document).unbind(e),h.el.ownerDocument!==document&&y(h.el.ownerDocument).unbind(e),y(window).unbind(e),h.$el.unbind(e)},h.removeKeyboard=function(){h.$decBtn=[],p.usePreview&&h.$preview.removeData("keyboard"),h.$preview.unbind(h.namespace+"keybindings"),h.preview=null,h.$preview=null,h.$previewCopy=null,h.$keyboard.removeData("keyboard"),h.$keyboard.remove(),h.$keyboard=[],h.isOpen=!1,h.isCurrent(!1)},h.destroy=function(e){var t,a=b.css,i=h.extensionNamespace.length,n=[a.input,a.locked,a.placeholder,a.noKeyboard,a.alwaysOpen,p.css.input,a.isCurrent].join(" ");for(clearTimeout(h.timer),clearTimeout(h.timer2),clearTimeout(h.timer3),h.$keyboard.length&&h.removeKeyboard(),h.options.openOn&&h.removeBindings(h.options.openOn),h.removeBindings(h.namespace),h.removeBindings(h.namespace+"callbacks"),t=0;t<i;t++)h.removeBindings(h.extensionNamespace[t]);h.el.active=!1,h.$el.removeClass(n).removeAttr("aria-haspopup").removeAttr("role").removeData("keyboard"),h=null,"function"==typeof e&&e()},h.init()};return b.keyCodes={backSpace:8,tab:9,enter:13,capsLock:20,escape:27,space:32,pageUp:33,pageDown:34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,A:65,Z:90,V:86,C:67,X:88,a:97,z:122},b.css={idSuffix:"_keyboard",initialFocus:"keyboard-init-focus",input:"ui-keyboard-input",inputClone:"ui-keyboard-preview-clone",wrapper:"ui-keyboard-preview-wrapper",preview:"ui-keyboard-preview",keyboard:"ui-keyboard",keySet:"ui-keyboard-keyset",keyButton:"ui-keyboard-button",keyWide:"ui-keyboard-widekey",keyPrefix:"ui-keyboard-",keyText:"ui-keyboard-text",keyHasActive:"ui-keyboard-hasactivestate",keyAction:"ui-keyboard-actionkey",keySpacer:"ui-keyboard-spacer",keyToggle:"ui-keyboard-toggle",keyDisabled:"ui-keyboard-disabled",divWrapperCE:"ui-keyboard-div-wrapper",locked:"ui-keyboard-lockedinput",alwaysOpen:"ui-keyboard-always-open",noKeyboard:"ui-keyboard-nokeyboard",placeholder:"ui-keyboard-placeholder",hasFocus:"ui-keyboard-has-focus",isCurrent:"ui-keyboard-input-current",inputValid:"ui-keyboard-valid-input",inputInvalid:"ui-keyboard-invalid-input",inputAutoAccepted:"ui-keyboard-autoaccepted",endRow:"ui-keyboard-button-endrow"},b.events={kbChange:"keyboardChange",kbBeforeClose:"beforeClose",kbBeforeVisible:"beforeVisible",kbVisible:"visible",kbInit:"initialized",kbInactive:"inactive",kbHidden:"hidden",kbRepeater:"repeater",kbKeysetChange:"keysetChange",inputAccepted:"accepted",inputCanceled:"canceled",inputChange:"change",inputRestricted:"restricted"},b.keyaction={accept:function(e){return e.close(!0),!1},alt:function(e){e.altActive=!e.altActive,e.showSet()},bksp:function(e){e.isContentEditable?(e.execCommand("delete"),e.saveCaret()):e.insertText("\b")},cancel:function(e){return e.close(),!1},clear:function(e){e.$preview[e.isContentEditable?"text":"val"](""),e.$decBtn.length&&e.checkDecimal()},combo:function(e){var t=e.options,a=!t.useCombos,i=e.$keyboard.find("."+b.css.keyPrefix+"combo");return t.useCombos=a,i.toggleClass(t.css.buttonActive,a).attr("title",i.attr("data-title")+" ("+t.display[a?"active":"disabled"]+")"),a&&e.checkCombos(),!1},dec:function(e){e.insertText(e.decimal?".":",")},del:function(e){e.isContentEditable?e.execCommand("forwardDelete"):e.insertText("{d}")},default:function(e){e.shiftActive=e.altActive=e.metaActive=!1,e.showSet()},enter:function(e,t,a){var i=e.options;return a.shiftKey?i.enterNavigation?e.switchInput(!a[i.enterMod],!0):e.close(!0):!i.enterNavigation||e.isTextArea&&!a[i.enterMod]?(e.isTextArea&&y(a.target).closest("button").length&&e.insertText((b.msie?" ":"")+"\n"),void(e.isContentEditable&&!i.enterNavigation&&(e.execCommand("insertHTML",'<div><br class="'+b.css.divWrapperCE+'"></div>'),setTimeout(function(){b.keyaction.right(e),e.saveCaret()},0)))):e.switchInput(!a[i.enterMod],!!i.autoAccept&&"true")},lock:function(e){e.last.keyset[0]=e.shiftActive=e.capsLock=!e.capsLock,e.showSet()},left:function(e){var t=b.caret(e.$preview);0<=t.start-1&&(e.last.start=e.last.end=t.start-1,b.caret(e.$preview,e.last),e.setScroll())},meta:function(e,t){var a=y(t);e.metaActive=!a.hasClass(e.options.css.buttonActive),e.showSet(a.attr("data-name"))},next:function(e){return e.switchInput(!0,e.options.autoAccept),!1},normal:function(e){e.shiftActive=e.altActive=e.metaActive=!1,e.showSet()},prev:function(e){return e.switchInput(!1,e.options.autoAccept),!1},right:function(e){var t=b.caret(e.$preview),a=e.isContentEditable?b.getEditableLength(e.el):e.getValue().length;t.end+1<=a&&(e.last.start=e.last.end=t.end+1,b.caret(e.$preview,e.last),e.setScroll())},shift:function(e){e.last.keyset[0]=e.shiftActive=!e.shiftActive,e.showSet()},sign:function(e){if(/^[+-]?\d*\.?\d*$/.test(e.getValue())){var t,a=b.caret(e.$preview),i=e.getValue(),n=e.isContentEditable?b.getEditableLength(e.el):i.length;e.setValue(-1*i),t=n-i.length,e.last.start=a.start+t,e.last.end=a.end+t,b.caret(e.$preview,e.last),e.setScroll()}},space:function(e){e.insertText(" ")},tab:function(e){var t=e.options;if(!e.isTextArea){if(t.tabNavigation)return e.switchInput(!e.shiftActive,!0);if(e.isInput)return!1}e.insertText("\t")},toggle:function(e){e.enabled=!e.enabled,e.toggle()},NBSP:" ",ZWSP:"​",ZWNJ:"‌",ZWJ:"‍",LRM:"‎",RLM:"‏"},b.builtLayouts={},b.layouts={alpha:{normal:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} a b c d e f g h i j [ ] \\","k l m n o p q r s ; ' {enter}","{shift} t u v w x y z , . / {shift}","{accept} {space} {cancel}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} A B C D E F G H I J { } |",'K L M N O P Q R S : " {enter}',"{shift} T U V W X Y Z < > ? {shift}","{accept} {space} {cancel}"]},qwerty:{normal:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p [ ] \\","a s d f g h j k l ; ' {enter}","{shift} z x c v b n m , . / {shift}","{accept} {space} {cancel}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W E R T Y U I O P { } |",'A S D F G H J K L : " {enter}',"{shift} Z X C V B N M < > ? {shift}","{accept} {space} {cancel}"]},international:{normal:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p [ ] \\","a s d f g h j k l ; ' {enter}","{shift} z x c v b n m , . / {shift}","{accept} {alt} {space} {alt} {cancel}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W E R T Y U I O P { } |",'A S D F G H J K L : " {enter}',"{shift} Z X C V B N M < > ? {shift}","{accept} {alt} {space} {alt} {cancel}"],alt:["~ ¡ ² ³ ¤ € ¼ ½ ¾ ‘ ’ ¥ × {bksp}","{tab} ä å é ® þ ü ú í ó ö « » ¬","á ß ð f g h j k ø ¶ ´ {enter}","{shift} æ x © v b ñ µ ç > ¿ {shift}","{accept} {alt} {space} {alt} {cancel}"],"alt-shift":["~ ¹ ² ³ £ € ¼ ½ ¾ ‘ ’ ¥ ÷ {bksp}","{tab} Ä Å É ® Þ Ü Ú Í Ó Ö « » ¦","Ä § Ð F G H J K Ø ° ¨ {enter}","{shift} Æ X ¢ V B Ñ µ Ç . ¿ {shift}","{accept} {alt} {space} {alt} {cancel}"]},colemak:{normal:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w f p g j l u y ; [ ] \\","{bksp} a r s t d h n e i o ' {enter}","{shift} z x c v b k m , . / {shift}","{accept} {space} {cancel}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W F P G J L U Y : { } |",'{bksp} A R S T D H N E I O " {enter}',"{shift} Z X C V B K M < > ? {shift}","{accept} {space} {cancel}"]},dvorak:{normal:["` 1 2 3 4 5 6 7 8 9 0 [ ] {bksp}","{tab} ' , . p y f g c r l / = \\","a o e u i d h t n s - {enter}","{shift} ; q j k x b m w v z {shift}","{accept} {space} {cancel}"],shift:["~ ! @ # $ % ^ & * ( ) { } {bksp}",'{tab} " < > P Y F G C R L ? + |',"A O E U I D H T N S _ {enter}","{shift} : Q J K X B M W V Z {shift}","{accept} {space} {cancel}"]},num:{normal:["= ( ) {b}","{clear} / * -","7 8 9 +","4 5 6 {sign}","1 2 3 %","0 {dec} {a} {c}"]}},b.language={en:{display:{a:"✔:Accept (Shift+Enter)",accept:"Accept:Accept (Shift+Enter)",alt:"Alt:⌥ AltGr",b:"⌫:Backspace",bksp:"Bksp:Backspace",c:"✖:Cancel (Esc)",cancel:"Cancel:Cancel (Esc)",clear:"C:Clear",combo:"ö:Toggle Combo Keys",dec:".:Decimal",e:"⏎:Enter",empty:" ",enter:"Enter:Enter ⏎",left:"←",lock:"Lock:⇪ Caps Lock",next:"Next ⇨",prev:"⇦ Prev",right:"→",s:"⇧:Shift",shift:"Shift:Shift",sign:"±:Change Sign",space:" :Space",t:"⇥:Tab",tab:"⇥ Tab:Tab",toggle:" ",valid:"valid",invalid:"invalid",active:"active",disabled:"disabled"},wheelMessage:"Use mousewheel to see other keys",comboRegex:/([`\'~\^\"ao])([a-z])/gim,combos:{"`":{a:"à",A:"À",e:"è",E:"È",i:"ì",I:"Ì",o:"ò",O:"Ò",u:"ù",U:"Ù",y:"ỳ",Y:"Ỳ"},"'":{a:"á",A:"Á",e:"é",E:"É",i:"í",I:"Í",o:"ó",O:"Ó",u:"ú",U:"Ú",y:"ý",Y:"Ý"},'"':{a:"ä",A:"Ä",e:"ë",E:"Ë",i:"ï",I:"Ï",o:"ö",O:"Ö",u:"ü",U:"Ü",y:"ÿ",Y:"Ÿ"},"^":{a:"â",A:"Â",e:"ê",E:"Ê",i:"î",I:"Î",o:"ô",O:"Ô",u:"û",U:"Û",y:"ŷ",Y:"Ŷ"},"~":{a:"ã",A:"Ã",e:"ẽ",E:"Ẽ",i:"ĩ",I:"Ĩ",o:"õ",O:"Õ",u:"ũ",U:"Ũ",y:"ỹ",Y:"Ỹ",n:"ñ",N:"Ñ"}}}},b.defaultOptions={language:null,rtl:!1,layout:"qwerty",customLayout:null,position:{of:null,my:"center top",at:"center top",at2:"center bottom"},reposition:!0,usePreview:!0,alwaysOpen:!1,initialFocus:!0,noFocus:!1,stayOpen:!1,userClosed:!1,ignoreEsc:!1,closeByClickEvent:!1,css:{input:"ui-widget-content ui-corner-all",container:"ui-widget-content ui-widget ui-corner-all ui-helper-clearfix",popup:"",buttonDefault:"ui-state-default ui-corner-all",buttonHover:"ui-state-hover",buttonAction:"ui-state-active",buttonActive:"ui-state-active",buttonDisabled:"ui-state-disabled",buttonEmpty:"ui-keyboard-empty"},autoAccept:!1,autoAcceptOnEsc:!1,lockInput:!1,restrictInput:!1,restrictInclude:"",acceptValid:!1,autoAcceptOnValid:!1,checkValidOnInit:!0,cancelClose:!0,tabNavigation:!1,enterNavigation:!1,enterMod:"altKey",stopAtEnd:!0,appendLocally:!1,appendTo:"body",wrapBRs:!0,stickyShift:!0,preventPaste:!1,caretToEnd:!1,scrollAdjustment:10,maxLength:!1,maxInsert:!0,repeatDelay:500,repeatRate:20,resetDefault:!0,openOn:"focus",activeOnReadonly:!1,keyBinding:"mousedown touchstart",useWheel:!0,useCombos:!0,validate:function(){return!0}},b.comboRegex=/([`\'~\^\"ao])([a-z])/gim,b.currentKeyboard="",y('\x3c!--[if lte IE 8]><script>jQuery("body").addClass("oldie");<\/script><![endif]--\x3e\x3c!--[if IE]><script>jQuery("body").addClass("ie");<\/script><![endif]--\x3e').appendTo("body").remove(),b.msie=y("body").hasClass("oldie"),b.allie=y("body").hasClass("ie"),b.watermark=void 0!==document.createElement("input").placeholder,b.checkCaretSupport=function(){if("boolean"!=typeof b.checkCaret){var e=y('<div style="height:0px;width:0px;overflow:hidden;position:fixed;top:0;left:-100px;"><input type="text" value="testing"/></div>').prependTo("body");b.caret(e.find("input"),3,3),b.checkCaret=3!==b.caret(e.find("input").hide().show()).start,e.remove()}return b.checkCaret},b.caret=function(e,t,a){if(!e||!e.length||e.is(":hidden")||"hidden"===e.css("visibility"))return{};var i,n,s,o,r=e.data("keyboard"),l=r&&r.options.noFocus,c=/(textarea|input)/i.test(e[0].nodeName);return l||e.focus(),void 0!==t?("object"==typeof t&&"start"in t&&"end"in t?(i=t.start,n=t.end):void 0===a&&(a=t),"number"==typeof t&&"number"==typeof a?(i=t,n=a):"start"===t?i=n=0:"string"==typeof t&&(i=n="end"),c?e.caret(i,n,l):b.setEditableCaret(e,i,n)):(o=c?e.caret():b.getEditableCaret(e[0]),i=o.start,n=o.end,s=c&&e[0].value||e.text()||"",{start:i,end:n,text:s.substring(i,n),replaceStr:function(e){return s.substring(0,i)+e+s.substring(n,s.length)}})},b.isTextNode=function(e){return e&&3===e.nodeType},b.isBlock=function(e,t){var a=e.ownerDocument.defaultView;return t&&1===t.nodeType&&t!==e&&"block"===a.getComputedStyle(t).display?1:0},b.wrapBRs=function(i){var e=y(i).find("br:not(."+b.css.divWrapperCE+")");e.length&&y.each(e,function(e,t){var a=t.parentNode.childNodes.length;(1!==a||1===a&&!b.isBlock(i,t.parentNode))&&y(t).addClass(b.css.divWrapperCE).wrap("<div>")})},b.getEditableCaret=function(l){if(!(l=y(l)[0]).isContentEditable)return{};var e,t,c=(y(l).data("keyboard")||{}).options,a=l.ownerDocument.getSelection().getRangeAt(0),i=s(a.startContainer,a.startOffset),n=i.position;function s(e,t){var a,i="",n=!1,s=0,o=y.makeArray(l.childNodes);function r(e){e&&(s+=e,i+=c&&c.replaceCR||"\n")}for(;!n&&o.length;){if((a=o.shift())===e&&(n=!0),r(b.isBlock(l,a.previousSibling)),b.isTextNode(a)){if(s+=n?t:a.length,i+=a.textContent,n)return{position:s,text:i}}else!n&&a.childNodes&&(o=y.makeArray(a.childNodes).concat(o));r(b.isTextNode(a.previousSibling)&&b.isBlock(l,a))}return{position:s,text:i}}return!1!==c.wrapBRs&&b.wrapBRs(l),t=a.endContainer===a.startContainer&&a.endOffset===a.startOffset?(e=n,""):(e=(i=s(a.endContainer,a.endOffset)).position,i.text.substring(n,e)),{start:n,end:e,text:t}},b.getEditableLength=function(e){var t=b.setEditableCaret(e,"getMax");return"number"==typeof t?t:null},b.setEditableCaret=function(u,e,t){if(!(u=y(u)[0]).isContentEditable)return{};var a=u.ownerDocument,i=a.createRange(),n=a.getSelection(),p=(y(u).data("keyboard")||{}).options,s=e,o=t,r="",l=c("getMax"===e?"end":e);function c(a){"end"===a?a=u.innerHTML.length:a<0&&(a=0);var e,t,i="",n=!1,s=0,o=0,r=0,l=y.makeArray(u.childNodes);function c(e){return i+=e?p&&p.replaceCR||"\n":"",0<e}function d(e){var t=s+e;return o=r,r+=e,0<=a-t?a-(s=t)<=0:a-t<=0}for(;!n&&l.length;)if(e=l.shift(),c(t=b.isBlock(u,e.previousSibling))&&d(t)&&(n=!0),c(t=b.isTextNode(e.previousSibling)&&b.isBlock(u,e))&&d(t)&&(n=!0),b.isTextNode(e)){if(i+=e.textContent,d(e.length))return{node:e,offset:t=a-s==0&&1<=s-o?e.length:a-s,position:a,text:i}}else!n&&e.childNodes&&(l=y.makeArray(e.childNodes).concat(l));return l.length?{node:e,offset:a-s,position:a,text:i}:{node:e,offset:e&&e.length||0,position:r,text:i}}if(l.node){if(s=l.position,"getMax"===e)return s;i.setStart(l.node,l.offset),void 0!==t&&t!==e&&(l=c(t)),l.node&&(o=l.position,i.setEnd(l.node,l.offset),r=s===o?"":l.text.substring(s,o)),n.removeAllRanges(),n.addRange(i)}return{start:s,end:o,text:r}},b.replaceContent=function(e,t){e=y(e)[0];for(var a,i,n,s=typeof t,o=b.getEditableCaret(e).start,r=0,l=[e];a=l.pop();)if(b.isTextNode(a))"function"===s?r<=o&&o<=r+a.length&&(a.textContent=t(a.textContent)):"string"===s&&(n=t.substring(r,r+a.length))!==a.textContent&&(a.textContent=n),r+=a.length;else if(a&&a.childNodes)for(i=a.childNodes.length;i--;)l.push(a.childNodes[i]);i=b.getEditableCaret(e),b.setEditableCaret(e,i.start,i.start)},y.fn.keyboard=function(e){return this.each(function(){y(this).data("keyboard")||new y.keyboard(this,e)})},y.fn.getkeyboard=function(){return this.data("keyboard")},y.fn.caret=function(t,a,e){if(void 0===this[0]||this.is(":hidden")||"hidden"===this.css("visibility")||!/(INPUT|TEXTAREA)/i.test(this[0].nodeName))return this;var i,n,s,o,r,l=this,c=l[0],d=c.ownerDocument.selection,u=c.scrollTop,p=!1,h=!0;try{p="selectionStart"in c}catch(e){h=!1}return h&&void 0!==t?(/(email|number)/i.test(c.type)||(p?(c.selectionStart=t,c.selectionEnd=a):((i=c.createTextRange()).collapse(!0),i.moveStart("character",t),i.moveEnd("character",a-t),i.select())),e||!l.is(":visible")&&"hidden"===l.css("visibility")||c.focus(),c.scrollTop=u,this):(/(email|number)/i.test(c.type)?t=a=l.val().length:p?(t=c.selectionStart,a=c.selectionEnd):d?a="TEXTAREA"===c.nodeName.toUpperCase()?(r=l.val(),(s=(n=d.createRange()).duplicate()).moveToElementText(c),s.setEndPoint("EndToEnd",n),(t=s.text.replace(/\r/g,"\n").length)+n.text.replace(/\r/g,"\n").length):(r=l.val().replace(/\r/g,"\n"),(n=d.createRange().duplicate()).moveEnd("character",r.length),t=""===n.text?r.length:r.lastIndexOf(n.text),(n=d.createRange().duplicate()).moveStart("character",-r.length),n.text.length):t=a=(c.value||"").length,o=c.value||"",{start:t,end:a,text:o.substring(t,a),replace:function(e){return o.substring(0,t)+e+o.substring(a,o.length)}})},b});