Files
Chamilo/web/assets/keyboard/dist/js/jquery.keyboard.min.js
2025-04-10 11:37:29 +02:00

2 lines
46 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*! jQuery UI Virtual Keyboard v1.30.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(h){"use strict";var b=h.keyboard=function(c,o){var p,y=this;y.version="1.30.2",y.$el=h(c),y.el=c,y.$el.data("keyboard",y),y.init=function(){y.initialized=!1,y.isTextArea="textarea"===y.el.nodeName.toLowerCase(),y.isInput="input"===y.el.nodeName.toLowerCase(),y.isContentEditable=!y.isTextArea&&!y.isInput&&y.el.isContentEditable;var e,t,a,i=b.css,n=b.events;if(y.isInput&&h.inArray((y.el.type||"").toLowerCase(),b.supportedInputTypes)<0)throw new TypeError('Input of type "'+y.el.type+'" is not supported; use type text, search, URL, tel or password');y.settings=o||{},o&&o.position&&(t=h.extend({},o.position),o.position=null),y.options=p=h.extend(!0,{},b.defaultOptions,o),t&&(p.position=t,o.position=t),y.el.active=!0,y.namespace=".keyboard"+Math.random().toString(16).slice(2),y.extensionNamespace=[],y.shiftActive=y.altActive=y.metaActive=y.sets=y.capsLock=!1,y.rows=["","-shift","-alt","-alt-shift"],y.inPlaceholder=y.$el.attr("placeholder")||"",y.watermark=b.watermark&&""!==y.inPlaceholder,y.repeatTime=1e3/(p.repeatRate||20),p.preventDoubleEventTime=p.preventDoubleEventTime||100,y.isOpen=!1,y.wheel="function"==typeof h.fn.mousewheel,y.escapeRegex=/[-\/\\^$*+?.()|[\]{}]/g,e=b.keyCodes,y.alwaysAllowed=[e.capsLock,e.pageUp,e.pageDown,e.end,e.home,e.left,e.up,e.right,e.down,e.insert,e.delete],y.$keyboard=[],y.enabled=!0,y.checkCaret=p.lockInput||b.checkCaretSupport(),y.isContentEditable&&(p.usePreview=!1),y.last={start:0,end:0,key:"",val:"",preVal:"",layout:"",virtual:!0,keyset:[!1,!1,!1],wheel_$Keys:[],wheelIndex:0,wheelLayers:[]},y.temp=["",0,0],h.each([n.kbInit,n.kbBeforeVisible,n.kbVisible,n.kbHidden,n.inputCanceled,n.inputAccepted,n.kbBeforeClose,n.inputRestricted],function(e,t){"function"==typeof p[t]&&y.$el.bind(t+y.namespace+"callbacks",p[t])}),p.alwaysOpen&&(p.stayOpen=!0),a=h(document),y.el.ownerDocument!==document&&(a=a.add(y.el.ownerDocument));var s="keyup checkkeyboard mousedown touchstart ";p.closeByClickEvent&&(s+="click "),a.bind(s.split(" ").join(y.namespace+" "),function(e){clearTimeout(y.timer3),y.timer3=setTimeout(function(){y.checkClose(e)},1)}),y.$el.addClass(i.input+" "+p.css.input).attr({"aria-haspopup":"true",role:"textbox"}),(p.lockInput||y.el.readOnly)&&(p.lockInput=!0,y.$el.addClass(i.locked).attr({readonly:"readonly"})),y.isUnavailable()&&y.$el.addClass(i.noKeyboard),p.openOn&&y.bindFocus(),y.watermark||""!==y.getValue(y.$el)||""===y.inPlaceholder||""===y.$el.attr("placeholder")||(y.$el.addClass(i.placeholder),y.setValue(y.inPlaceholder,y.$el)),y.$el.trigger(n.kbInit,[y,y.el]),p.alwaysOpen&&y.reveal(),y.initialized=!0},y.toggle=function(){if(y.hasKeyboard()){var e=y.$keyboard.find("."+b.css.keyToggle),t=!y.enabled;return y.preview.readonly=t||y.options.lockInput,y.$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&&y.typing_options&&(y.typing_options.text=""),y}},y.setCurrent=function(){var e=b.css,t=h("."+e.isCurrent),a=t.data("keyboard");h.isEmptyObject(a)||a.el===y.el||a.close(!!a.options.autoAccept&&"true"),t.removeClass(e.isCurrent),h("."+e.hasFocus).removeClass(e.hasFocus),y.$el.addClass(e.isCurrent),y.$preview.focus(),y.$keyboard.addClass(e.hasFocus),y.isCurrent(!0),y.isOpen=!0},y.isUnavailable=function(){return y.$el.is(":disabled")||!y.options.activeOnReadonly&&y.$el.attr("readonly")&&!y.$el.hasClass(b.css.locked)},y.isCurrent=function(e){var t=b.currentKeyboard||!1;return e?t=b.currentKeyboard=y.el:!1===e&&t===y.el&&(t=b.currentKeyboard=""),t===y.el},y.hasKeyboard=function(){return y.$keyboard&&0<y.$keyboard.length},y.isVisible=function(){return!!y.hasKeyboard()&&y.$keyboard.is(":visible")},y.setFocus=function(){var e=y.$preview||y.$el;p.noFocus||e.focus(),y.isContentEditable?b.setEditableCaret(e,y.last.start,y.last.end):b.caret(e,y.last)},y.focusOn=function(){y&&y.el.active&&(y.isVisible()?y.setCurrent():(clearTimeout(y.timer),y.reveal()))},y.redraw=function(e){return e&&(y.options.layout=e),y.$keyboard.length&&(y.last.preVal=""+y.last.val,y.saveLastChange(),y.setValue(y.last.val,y.$el),y.removeKeyboard(),y.shiftActive=y.altActive=y.metaActive=!1),y.isOpen=p.alwaysOpen,y.reveal(!0),y},y.reveal=function(e){var t,a=y.isOpen,i=b.css;if(y.opening=!a,h("."+i.keyboard).not("."+i.alwaysOpen).each(function(){var e=h(this).data("keyboard");h.isEmptyObject(e)||e.close(!!e.options.autoAccept&&"true")}),!y.isUnavailable())return y.$el.removeClass(i.noKeyboard),p.openOn&&y.$el.unbind(h.trim((p.openOn+" ").split(/\s+/).join(y.namespace+" "))),y.$keyboard&&(!y.$keyboard||y.$keyboard.length&&!h.contains(y.el.ownerDocument.body,y.$keyboard[0]))||y.startup(),y.watermark||y.getValue()!==y.inPlaceholder||(y.$el.removeClass(i.placeholder),y.setValue("",y.$el)),y.originalContent=y.isContentEditable?y.$el.html():y.getValue(y.$el),y.el===y.preview||y.isContentEditable||y.setValue(y.originalContent),p.acceptValid&&p.checkValidOnInit&&y.checkValid(),p.resetDefault&&(y.shiftActive=y.altActive=y.metaActive=!1),y.showSet(),y.isVisible()||y.$el.trigger(b.events.kbBeforeVisible,[y,y.el]),(y.initialized||p.initialFocus||!p.initialFocus&&y.$el.hasClass(b.css.initialFocus))&&y.setCurrent(),y.toggle(),y.$keyboard.show(),p.usePreview&&b.msie&&(void 0===y.width&&(y.$preview.hide(),y.width=Math.ceil(y.$keyboard.width()),y.$preview.show()),y.$preview.width(y.width)),y.reposition(),y.checkDecimal(),y.lineHeight=parseInt(y.$preview.css("lineHeight"),10)||parseInt(y.$preview.css("font-size"),10)+4,p.caretToEnd&&(t=y.isContentEditable?b.getEditableLength(y.el):y.originalContent.length,y.saveCaret(t,t)),b.allie&&(0===y.last.end&&0<y.last.start&&(y.last.end=y.last.start),y.last.start<0&&(y.last.start=y.last.end=y.originalContent.length)),a||e?(b.caret(y.$preview,y.last),y.opening=!1):y.timer2=setTimeout(function(){var e;y.opening=!1,/(number|email)/i.test(y.el.type)||p.caretToEnd||y.saveCaret(e,e,y.$el),(p.initialFocus||y.$el.hasClass(b.css.initialFocus))&&b.caret(y.$preview,y.last),y.last.eventTime=(new Date).getTime(),y.$el.trigger(b.events.kbVisible,[y,y.el]),y.timer=setTimeout(function(){y&&y.saveCaret()},200)},10),y},y.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=(y.language=t).split("-")[0],p.display=h.extend(!0,{},a.en.display,a[t]&&a[t].display||{},y.settings.display),p.combos=h.extend(!0,{},a.en.combos,a[t]&&a[t].combos||{},y.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&&(y.regex=a[t].comboRegex),y.decimal=/^\./.test(p.display.dec),y.$el.toggleClass("rtl",p.rtl).css("direction",p.rtl?"rtl":"")},y.startup=function(){var e=b.css;(p.alwaysOpen||p.userClosed)&&y.$preview||y.makePreview(),y.hasKeyboard()||("custom"===p.layout&&(p.layoutHash="custom"+y.customHash()),y.layout="custom"===p.layout?p.layoutHash:p.layout,y.last.layout=y.layout,y.updateLanguage(),void 0===b.builtLayouts[y.layout]&&("function"==typeof p.create?y.$keyboard=p.create(y):y.$keyboard.length||y.buildKeyboard(y.layout,!0)),y.$keyboard=b.builtLayouts[y.layout].$keyboard.clone(),y.$keyboard.data("keyboard",y),""!==(y.el.id||"")&&y.$keyboard.attr("id",y.el.id+b.css.idSuffix),y.makePreview()),y.$keyboard.attr("data-"+e.keyboard+"-layout",p.layout).attr("data-"+e.keyboard+"-language",y.language),y.$decBtn=y.$keyboard.find("."+e.keyPrefix+"dec"),(p.enterNavigation||y.isTextArea)&&y.alwaysAllowed.push(b.keyCodes.enter),y.bindKeyboard(),y.$keyboard.appendTo(p.appendLocally?y.$el.parent():p.appendTo||"body"),y.bindKeys(),p.reposition&&h.ui&&h.ui.position&&"body"===p.appendTo&&h(window).bind("resize"+y.namespace,function(){y.reposition()})},y.reposition=function(){return y.position=!h.isEmptyObject(p.position)&&p.position,h.ui&&h.ui.position&&y.position&&(y.position.of=y.position.of||y.$el.data("keyboardPosition")||y.$el,y.position.collision=y.position.collision||"flipfit flipfit",y.position.at=p.usePreview?p.position.at:p.position.at2,y.isVisible()&&y.$keyboard.position(y.position)),y},y.makePreview=function(){if(p.usePreview){var e,t,a,i,n=b.css;for(y.$preview=y.$el.clone(!1).data("keyboard",y).removeClass(n.placeholder+" "+n.input).addClass(n.preview+" "+p.css.input).attr("tabindex","-1").show(),y.preview=y.$preview[0],i=/^(data-|id|aria-haspopup)/i,e=(t=y.$preview.get(0).attributes).length-1;0<=e;e--)a=t[e]&&t[e].name,i.test(a)&&y.preview.removeAttribute(a);h("<div />").addClass(n.wrapper).append(y.$preview).prependTo(y.$keyboard)}else y.$preview=y.$el,y.preview=y.el},y.caret=function(e,t){var a=b.caret(y.$preview,e,t);return a instanceof h?(y.saveCaret(a.start,a.end),y):a},y.saveCaret=function(e,t,a){var i;y.isCurrent()&&(i=void 0===e?b.caret(a||y.$preview):b.caret(a||y.$preview,e,t),y.last.start=void 0===e?i.start:e,y.last.end=void 0===t?i.end:t)},y.saveLastChange=function(e){y.last.val=e||y.getValue(y.$preview||y.$el),y.isContentEditable&&(y.last.elms=y.el.cloneNode(!0))},y.setScroll=function(){if(!y.isContentEditable&&y.last.virtual){var e,t,a,i,n=y.last.val.substring(0,Math.max(y.last.start,y.last.end));y.$previewCopy||(y.$previewCopy=y.$preview.clone().removeAttr("id").css({position:"absolute",left:0,zIndex:-10,visibility:"hidden"}).addClass(b.css.inputClone),y.$previewCopy[0].disabled=!0,y.isTextArea||y.$previewCopy.css({"white-space":"pre",width:0}),p.usePreview?y.$preview.after(y.$previewCopy):y.$keyboard.prepend(y.$previewCopy)),y.isTextArea?(y.$previewCopy.height(y.lineHeight).val(n),y.preview.scrollTop=y.lineHeight*(Math.floor(y.$previewCopy[0].scrollHeight/y.lineHeight)-1)):(y.$previewCopy.val(n.replace(/\s/g," ")),a=/c/i.test(p.scrollAdjustment)?y.preview.clientWidth/2:p.scrollAdjustment,e=y.$previewCopy[0].scrollWidth-1,void 0===y.last.scrollWidth&&(y.last.scrollWidth=e,y.last.direction=!0),i=y.last.scrollWidth===e?y.last.direction:y.last.scrollWidth<e,t=y.preview.clientWidth-a,i?y.preview.scrollLeft=e<t?0:e-t:e>=y.preview.scrollWidth-t?y.preview.scrollLeft=y.preview.scrollWidth-a:y.preview.scrollLeft=0<e-a?e-a:0,y.last.scrollWidth=e,y.last.direction=i)}},y.bindFocus=function(){p.openOn&&y&&y.el.active&&(y.$el.bind(p.openOn+y.namespace,function(){y.focusOn()}),h(":focus")[0]===y.el&&y.$el.blur())},y.bindKeyboard=function(){var s,o=b.keyCodes,r=b.builtLayouts[y.layout],e=y.namespace+"keybindings";y.$preview.unbind(y.namespace).bind("click"+e+" touchstart"+e,function(){p.alwaysOpen&&!y.isCurrent()&&y.reveal(),y.timer2=setTimeout(function(){y&&y.saveCaret()},150)}).bind("keypress"+e,function(e){if(p.lockInput)return!1;if(y.isCurrent()){var t=e.charCode||e.which,a=t>=o.A&&t<=o.Z,i=t>=o.a&&t<=o.z,n=y.last.key=String.fromCharCode(t);if(!(t<o.space)){if(y.last.virtual=!1,y.last.event=e,y.last.$key=[],y.checkCaret&&y.saveCaret(),t!==o.capsLock&&(a||i)&&(y.capsLock=a&&!e.shiftKey||i&&e.shiftKey,y.capsLock&&!y.shiftActive&&(y.shiftActive=!0,y.showSet())),p.restrictInput){if((e.which===o.backSpace||0===e.which)&&h.inArray(e.keyCode,y.alwaysAllowed))return;-1===h.inArray(n,r.acceptedKeys)&&(e.preventDefault(),(s=h.extend({},e)).type=b.events.inputRestricted,y.$el.trigger(s,[y,y.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)&&(y.last.key=r.mappedKeys[n],y.insertText(y.last.key),e.preventDefault()),"function"==typeof p.beforeInsert&&(y.insertText(y.last.key),e.preventDefault()),y.checkMaxLength()}}}).bind("keyup"+e,function(e){if(y.isCurrent()){switch(y.last.virtual=!1,e.which){case o.tab:if(y.tab&&!p.lockInput){y.shiftActive=e.shiftKey;var t=b.keyaction.tab(y);if(y.tab=!1,!t)return!1}else e.preventDefault();break;case o.escape:return p.ignoreEsc||y.close(!(!p.autoAccept||!p.autoAcceptOnEsc)&&"true"),!1}clearTimeout(y.throttled),y.throttled=setTimeout(function(){y&&y.isVisible()&&y.checkCombos()},100),y.checkMaxLength(),y.last.preVal=""+y.last.val,y.saveLastChange();var a=h.Event(b.events.kbChange);if(a.action=y.last.key,y.$el.trigger(a,[y,y.el]),"function"==typeof p.change)return a.type=b.events.inputChange,p.change(a,y,y.el),!1;p.acceptValid&&p.autoAcceptOnValid&&"function"==typeof p.validate&&p.validate(y,y.getValue(y.$preview))&&(y.$preview.blur(),y.accept())}}).bind("keydown"+e,function(e){if(y.last.keyPress=e.which,p.alwaysOpen&&!y.isCurrent()&&y.reveal(),e.which===o.tab)return!(y.tab=!0);if(p.lockInput||e.timeStamp===y.last.timeStamp)return!p.lockInput;switch(y.last.timeStamp=e.timeStamp,y.last.virtual=!1,e.which){case o.backSpace:b.keyaction.bksp(y,null,e),e.preventDefault();break;case o.enter:b.keyaction.enter(y,null,e);break;case o.capsLock:y.shiftActive=y.capsLock=!y.capsLock,y.showSet();break;case o.V:if(e.ctrlKey||e.metaKey){if(p.preventPaste)return void e.preventDefault();y.checkCombos()}}}).bind("mouseup touchend ".split(" ").join(e+" "),function(){y.last.virtual=!0,y.saveCaret()}),y.$keyboard.bind("mousedown click touchstart ".split(" ").join(y.namespace+" "),function(e){e.stopPropagation(),y.isCurrent()||(y.reveal(),h(y.el.ownerDocument).trigger("checkkeyboard"+y.namespace)),y.setFocus()}),p.preventPaste&&(y.$preview.bind("contextmenu"+y.namespace,function(e){e.preventDefault()}),y.$el.bind("contextmenu"+y.namespace,function(e){e.preventDefault()}))},y.bindButton=function(e,t){var a="."+b.css.keyButton,i=function(e){e.stopPropagation(),e.$target=h(this).closest("."+b.css.keyboard+", ."+b.css.input),t.call(this,e)};return h.fn.on?y.$keyboard.on(e,a,i):h.fn.delegate&&y.$keyboard.delegate(a,e,i),y},y.unbindButton=function(e){return h.fn.off?y.$keyboard.off(e):h.fn.undelegate&&y.$keyboard.undelegate("."+b.css.keyButton,e),y},y.bindKeys=function(){var s=b.css;y.unbindButton(y.namespace+" "+y.namespace+"kb").bindButton("mouseenter mouseleave touchstart ".split(" ").join(y.namespace+" "),function(e){if(!p.alwaysOpen&&!p.userClosed||"mouseleave"===e.type||y.isCurrent()||(y.reveal(),y.setFocus()),y.isCurrent()&&!this.disabled){var t,a,i=y.last,n=h(this),s=e.type;p.useWheel&&y.wheel&&(t=y.getLayers(n),a=(t.length?t.map(function(){return h(this).attr("data-value")||""}).get():"")||[n.text()],i.wheel_$Keys=t,i.wheelLayers=a,i.wheelIndex=h.inArray(n.attr("data-value"),a)),"mouseenter"!==s&&"touchstart"!==s||"password"===y.el.type||n.hasClass(p.css.buttonDisabled)||(n.addClass(p.css.buttonHover),p.useWheel&&y.wheel&&n.attr("title",function(e,t){return y.wheel&&""===t&&y.sets&&1<a.length&&"touchstart"!==s?p.wheelMessage:t})),"mouseleave"===s&&(n.removeClass("password"===y.el.type?"":p.css.buttonHover),p.useWheel&&y.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(y.namespace+" ")+y.namespace+" "+b.events.kbRepeater,function(e){if(e.preventDefault(),!y.$keyboard.is(":visible")||this.disabled)return!1;var t,a=y.last,i=h(this),n=(new Date).getTime();if(p.useWheel&&y.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="",y.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](y,this,e))return!1;t=null}return!!y.hasKeyboard()&&(null!=t&&(a.key=h(this).hasClass(s.keyAction)?t:a.key,y.insertText(a.key),y.capsLock||p.stickyShift||e.shiftKey||(y.shiftActive=!1,y.showSet(i.attr("data-name")))),b.caret(y.$preview,a),y.checkCombos(),(e=h.extend({},e,h.Event(b.events.kbChange))).target=y.el,e.action=a.key,y.$el.trigger(e,[y,y.el]),a.preVal=""+a.val,y.saveLastChange(),"function"==typeof p.change?(e.type=b.events.inputChange,p.change(e,y,y.el),!1):void 0)}}).bindButton("mouseup"+y.namespace+" "+"mouseleave touchend touchmove touchcancel ".split(" ").join(y.namespace+"kb "),function(e){y.last.virtual=!0;var t,a=h(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&&y.isCurrent()&&y.isVisible()&&y.$preview.focus(),y.checkCaret&&b.caret(y.$preview,y.last));return y.mouseRepeat=[!1,""],clearTimeout(y.repeater),p.acceptValid&&p.autoAcceptOnValid&&"function"==typeof p.validate&&p.validate(y,y.getValue())&&(y.$preview.blur(),y.accept()),!1}).bindButton("click"+y.namespace,function(){return!1}).bindButton("mousewheel"+y.namespace,y.throttleEvent(function(e,t){var a=h(this);if(a&&!a.hasClass(s.keyAction)&&y.last.wheel_$Keys[0]===this&&p.useWheel&&y.wheel){t=t||e.deltaY;var i,n=y.last.wheelLayers||[];return 1<n.length?((i=y.last.wheelIndex+(0<t?-1:1))>n.length-1&&(i=0),i<0&&(i=n.length-1)):i=0,y.last.wheelIndex=i,a.html(n[i]),!1}},30)).bindButton("mousedown touchstart ".split(" ").join(y.namespace+"kb "),function(){var e=h(this);if(e&&(!e.hasClass(s.keyAction)||e.is("."+s.keyPrefix+"tab bksp space enter".split(" ").join(",."+s.keyPrefix))))return 0!==p.repeatRate&&(y.mouseRepeat=[!0,e],setTimeout(function(){y&&y.mouseRepeat[0]&&y.mouseRepeat[1]===e&&!e[0].disabled&&y.repeatKey(e)},p.repeatDelay)),!1})},y.throttleEvent=function(e,t){var a;return function(){a||(e.apply(this,arguments),a=!0,setTimeout(function(){a=!1},t))}},y.execCommand=function(e,t){y.el.ownerDocument.execCommand(e,!1,t),y.el.normalize(),p.reposition&&y.reposition()},y.getValue=function(e){return(e=e||y.$preview)[y.isContentEditable?"text":"val"]()},y.setValue=function(e,t){return t=t||y.$preview,y.isContentEditable?e!==t.text()&&(b.replaceContent(t,e),y.saveCaret()):t.val(e),y},y.insertText=function(e){if(!y.$preview)return y;if("function"==typeof p.beforeInsert&&(e=p.beforeInsert(y.last.event,y,y.el,e)),void 0===e||!1===e)return y.last.key="",y;if(y.isContentEditable)return y.insertContentEditable(e);var t,a=!1,i="\b"===e,n=y.getValue(),s=b.caret(y.$preview),o=n.length;return s.end<s.start&&(s.end=s.start),s.start>o&&(s.end=s.start=o),y.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,y.setValue(n),y.saveCaret(t,t),y.setScroll(),y},y.insertContentEditable=function(e){return y.$preview.focus(),y.execCommand("insertText",e),y.saveCaret(),y},y.checkMaxLength=function(){if(y.$preview){var e,t,a=y.getValue(),i=y.isContentEditable?b.getEditableLength(y.el):a.length;return!1!==p.maxLength&&i>p.maxLength&&(e=b.caret(y.$preview).start,t=Math.min(e,p.maxLength),p.maxInsert||(a=y.last.val,t=e-1),y.setValue(a.substring(0,p.maxLength)),y.saveCaret(t,t)),y.$decBtn.length&&y.checkDecimal(),y}},y.repeatKey=function(e){e.trigger(b.events.kbRepeater),y.mouseRepeat[0]&&(y.repeater=setTimeout(function(){y&&y.repeatKey(e)},y.repeatTime))},y.getKeySet=function(){var e=[];return y.altActive&&e.push("alt"),y.shiftActive&&e.push("shift"),y.metaActive&&e.push(y.metaActive),e.length?e.join("+"):"normal"},y.showKeySet=function(e){return"string"==typeof e?(y.last.keyset=[y.shiftActive,y.altActive,y.metaActive],y.shiftActive=/shift/i.test(e),y.altActive=/alt/i.test(e),/\bmeta/.test(e)?(y.metaActive=!0,y.showSet(e.match(/\bmeta[\w-]+/i)[0])):(y.metaActive=!1,y.showSet())):y.showSet(e),y},y.showSet=function(e){if(y.hasKeyboard()){p=y.options;var t=b.css,a="."+t.keyPrefix,i=p.css.buttonActive,n="",s=(y.shiftActive?1:0)+(y.altActive?2:0);if(y.shiftActive||(y.capsLock=!1),y.metaActive?(y.shiftActive&&(e=(e||"").replace("-shift","")),y.altActive&&(e=(e||"").replace("-alt","")),""===(n=/^meta/i.test(e)?e:"")?n=!0===y.metaActive?"":y.metaActive:y.metaActive=n,(!p.stickyShift&&y.last.keyset[2]!==y.metaActive||(y.shiftActive||y.altActive)&&!y.$keyboard.find("."+t.keySet+"-"+n+y.rows[s]).length)&&(y.shiftActive=y.altActive=!1)):!p.stickyShift&&y.last.keyset[2]!==y.metaActive&&y.shiftActive&&(y.shiftActive=y.altActive=!1),n=0!==(s=(y.shiftActive?1:0)+(y.altActive?2:0))||y.metaActive?""===n?"":"-"+n:"-normal",!y.$keyboard.find("."+t.keySet+n+y.rows[s]).length)return y.shiftActive=y.last.keyset[0],y.altActive=y.last.keyset[1],void(y.metaActive=y.last.keyset[2]);y.$keyboard.find(a+"alt,"+a+"shift,."+t.keyAction+"[class*=meta]").removeClass(i).end().find(a+"alt").toggleClass(i,y.altActive).end().find(a+"shift").toggleClass(i,y.shiftActive).end().find(a+"lock").toggleClass(i,y.capsLock).end().find("."+t.keySet).hide().end().find("."+(t.keyAction+a+n).replace("--","-")).addClass(i),y.$keyboard.find("."+t.keySet+n+y.rows[s])[0].style.display="inline-block",y.metaActive&&y.$keyboard.find(a+y.metaActive).toggleClass(i,!1!==y.metaActive),y.last.keyset=[y.shiftActive,y.altActive,y.metaActive],y.$el.trigger(b.events.kbKeysetChange,[y,y.el]),p.reposition&&y.reposition()}},y.checkCombos=function(){if(!(y.isVisible()||y.hasKeyboard()&&y.$keyboard.hasClass(b.css.hasFocus)))return y.getValue(y.$preview||y.$el);var e,t,a,i,n=y.getValue(),s=b.caret(y.$preview),o=b.builtLayouts[y.layout],r=y.isContentEditable?b.getEditableLength(y.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(y.regex,function(e,t,a){return p.combos.hasOwnProperty(t)&&p.combos[t][a]||e}):y.$preview.length&&(t=s.start-(0<=s.start-2?2:0),b.caret(y.$preview,t,s.end),a=(i=function(e){return(e||"").replace(y.regex,function(e,t,a){return p.combos.hasOwnProperty(t)&&p.combos[t][a]||e})})((t=b.caret(y.$preview)).text),t&&t.replaceStr&&a!==t.text&&(y.isContentEditable?b.replaceContent(c,i):y.setValue(t.replaceStr(a))),n=y.getValue())),p.restrictInput&&""!==n&&(t=o.acceptedKeys.length,(e=o.acceptedKeysRegex)||(a=h.map(o.acceptedKeys,function(e){return e.replace(y.escapeRegex,"\\$&")}),-1<y.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,y.setValue(n),y.saveCaret(s.start,s.end),y.setScroll(),y.checkMaxLength()),p.acceptValid&&y.checkValid(),n},y.checkValid=function(){var e=b.css,t=y.$keyboard.find("."+e.keyPrefix+"accept"),a=!0;"function"==typeof p.validate&&(a=p.validate(y,y.getValue(),!1)),t.toggleClass(e.inputInvalid,!a).toggleClass(e.inputValid,a).attr("title",t.attr("data-title")+" ("+p.display[a?"valid":"invalid"]+")")},y.checkDecimal=function(){y.decimal&&/\./g.test(y.preview.value)||!y.decimal&&/\,/g.test(y.preview.value)?y.$decBtn.attr({disabled:"disabled","aria-disabled":"true"}).removeClass(p.css.buttonHover).addClass(p.css.buttonDisabled):y.$decBtn.removeAttr("disabled").attr({"aria-disabled":"false"}).addClass(p.css.buttonDefault).removeClass(p.css.buttonDisabled)},y.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""!==h(this).find("."+t.keyText).text()}).add(e)},y.switchInput=function(e,t){if("function"==typeof p.switchInput)p.switchInput(y,e,t);else{y.$keyboard.length&&y.$keyboard.hide();var a,i=!1,n=h("button, input, select, textarea, a, [contenteditable]").filter(":visible").not(":disabled"),s=n.index(y.$el)+(e?1:-1);if(y.$keyboard.length&&y.$keyboard.show(),s>n.length-1&&(i=p.stopAtEnd,s=0),s<0&&(i=p.stopAtEnd,s=n.length-1),!i){if(!(t=y.close(t)))return;(a=n.eq(s).data("keyboard"))&&a.options.openOn.length?a.focusOn():n.eq(s).focus()}}return!1},y.close=function(e){if(y.isOpen&&y.$keyboard.length){clearTimeout(y.throttled);var t=b.css,a=b.events,i=e?y.checkCombos():y.originalContent;if(e&&"function"==typeof p.validate&&!p.validate(y,i,!0)&&(i=y.originalContent,e=!1,p.cancelClose))return;y.isCurrent(!1),y.isOpen=p.alwaysOpen||p.userClosed,y.isContentEditable&&!e?y.$el.html(i):y.setValue(i,y.$el),y.$el.removeClass(t.isCurrent+" "+t.inputAutoAccepted).addClass(e?!0===e?"":t.inputAutoAccepted:"").trigger(a.inputChange),p.alwaysOpen||y.$el.trigger(a.kbBeforeClose,[y,y.el,e||!1]),b.caret(y.$preview,y.last),y.$el.trigger(e?a.inputAccepted:a.inputCanceled,[y,y.el]).trigger(p.alwaysOpen?a.kbInactive:a.kbHidden,[y,y.el]).blur(),y&&(y.last.eventTime=(new Date).getTime(),p.alwaysOpen||p.userClosed&&"true"===e||!y.$keyboard.length||(y.removeKeyboard(),y.timer=setTimeout(function(){y&&y.bindFocus()},200)),y.watermark||""!==y.el.value||""===y.inPlaceholder||(y.$el.addClass(t.placeholder),y.setValue(y.inPlaceholder,y.$el)))}return!!e},y.accept=function(){return y.close(!0)},y.checkClose=function(e){if(!y.opening){var t=h.keyboard.css,a=e.$target||h(e.target).closest("."+b.css.keyboard+", ."+b.css.input);if(a.length||(a=h(e.target)),a.length&&a.hasClass(t.keyboard)){var i=a.data("keyboard");i!==y&&!i.$el.hasClass(t.isCurrent)&&i.options.openOn&&e.type===p.openOn&&i.focusOn()}else y.escClose(e,a)}},y.escCloseCallback={keepOpen:function(){return!y.isOpen}},y.escClose=function(e,t){if(y.isOpen){if(e&&"keyup"===e.type)return e.which!==b.keyCodes.escape||p.ignoreEsc?"":y.close(!(!p.autoAccept||!p.autoAcceptOnEsc)&&"true");var a=!1,i=t.length&&t||h(e.target);if(h.each(y.escCloseCallback,function(e,t){"function"==typeof t&&(a=a||t(i))}),!a&&(!y.isCurrent()&&y.isOpen||y.isOpen&&i[0]!==y.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||y.close(!!p.autoAccept&&"true")}else y.close(!!p.autoAccept&&"true")}}},y.keyBtn=h("<button />").attr({role:"button",type:"button","aria-disabled":"false",tabindex:"-1"}).addClass(b.css.keyButton),y.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},y.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=h.trim(n.title).replace(/_/g," ")),n},y.addKey=function(e,t,a){var i,n,s,o={},r=y.processKeys(a?e:t),l=b.css;return!a&&p.display[r.name]?(s=y.processKeys(p.display[r.name])).action=y.processKeys(e).name:(s=r).action=r.name,o.name=y.processName(r.name),""!==s.name&&(""!==s.map?(b.builtLayouts[y.layout].mappedKeys[s.map]=s.name,b.builtLayouts[y.layout].acceptedKeys.push(s.name)):a&&b.builtLayouts[y.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=y.keyBtn.clone().attr({"data-value":a?s.name:s.action,"data-name":s.action,"data-pos":y.temp[1]+","+y.temp[2],"data-action":s.action,"data-html":o.html}).addClass(i).html(o.html).appendTo(y.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(y,o)).$key.html(),o.$key.attr("data-html",n)),o.$key},y.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},y.buildKeyboard=function(e,t){h.isEmptyObject(p.display)&&y.updateLanguage();var a,i,n,s,o=b.css,r=0,l=b.builtLayouts[e||y.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=h("<div />").addClass(d).attr({role:"textbox"}).hide();return-1<(a=h.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||y.layout||p.layout],h.each(d,function(e,t){if(""!==e&&!/^(name|lang|rtl)$/i.test(e))for("default"===e&&(e="normal"),r++,n=h("<div />").attr("name",e).addClass(o.keySet+" "+o.keySet+"-"+e).appendTo(u).toggle("normal"===e),i=0;i<t.length;i++)s=h.trim(t[i]).replace(/\{(\.?)[\s+]?:[\s+]?(\.?)\}/g,"{$1:$2}"),y.buildRow(n,i,s.split(/\s+/),c),n.find("."+o.keyButton+",."+o.keySpacer).filter(":last").after('<br class="'+o.endRow+'"/>')}),1<r&&(y.sets=!0),l.hasMappedKeys=!h.isEmptyObject(l.mappedKeys),l.$keyboard=u},y.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=!(y.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),h('<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):"",y.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)){y.addKey(l.split(":")[0],l).addClass(d.keyHasActive);continue}switch((s=l.split(":"))[0].toLowerCase()){case"a":case"accept":y.addKey("accept",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"alt":case"altgr":y.addKey("alt",l).addClass(d.keyHasActive);break;case"b":case"bksp":y.addKey("bksp",l);break;case"c":case"cancel":y.addKey("cancel",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"combo":y.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(y.decimal?".":","),y.addKey("dec",l);break;case"e":case"enter":y.addKey("enter",l).addClass(p.css.buttonAction+" "+d.keyAction);break;case"lock":y.addKey("lock",l).addClass(d.keyHasActive);break;case"s":case"shift":y.addKey("shift",l).addClass(d.keyHasActive);break;case"sign":i.push("-"),y.addKey("sign",l);break;case"space":i.push(" "),y.addKey("space",l);break;case"t":case"tab":y.addKey("tab",l);break;default:b.keyaction.hasOwnProperty(s[0])&&y.addKey(s[0],l).toggleClass(p.css.buttonAction+" "+d.keyAction,r)}}else n=a[o],y.addKey(n,n,!0)},y.removeBindings=function(e){h(document).unbind(e),y.el.ownerDocument!==document&&h(y.el.ownerDocument).unbind(e),h(window).unbind(e),y.$el.unbind(e)},y.removeKeyboard=function(){y.$decBtn=[],p.usePreview&&y.$preview.removeData("keyboard"),y.$preview.unbind(y.namespace+"keybindings"),y.preview=null,y.$preview=null,y.$previewCopy=null,y.$keyboard.removeData("keyboard"),y.$keyboard.remove(),y.$keyboard=[],y.isOpen=!1,y.isCurrent(!1)},y.destroy=function(e){var t,a=b.css,i=y.extensionNamespace.length,n=[a.input,a.locked,a.placeholder,a.noKeyboard,a.alwaysOpen,p.css.input,a.isCurrent].join(" ");for(clearTimeout(y.timer),clearTimeout(y.timer2),clearTimeout(y.timer3),y.$keyboard.length&&y.removeKeyboard(),y.options.openOn&&y.removeBindings(y.options.openOn),y.removeBindings(y.namespace),y.removeBindings(y.namespace+"callbacks"),t=0;t<i;t++)y.removeBindings(y.extensionNamespace[t]);y.el.active=!1,y.$el.removeClass(n).removeAttr("aria-haspopup").removeAttr("role").removeData("keyboard"),y=null,"function"==typeof e&&e()},y.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&&h(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=h(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((e.decimal?/^[+-]?\d*\.?\d*$/:/^[+-]?\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.supportedInputTypes=["text","search","url","tel","password"],b.comboRegex=/([`\'~\^\"ao])([a-z])/gim,b.currentKeyboard="",h('\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=h("body").hasClass("oldie"),b.allie=h("body").hasClass("ie"),b.watermark=void 0!==document.createElement("input").placeholder,b.checkCaretSupport=function(){if("boolean"!=typeof b.checkCaret){var e=h('<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=h(i).find("br:not(."+b.css.divWrapperCE+")");e.length&&h.each(e,function(e,t){var a=t.parentNode.childNodes.length;(1!==a||1===a&&!b.isBlock(i,t.parentNode))&&h(t).addClass(b.css.divWrapperCE).wrap("<div>")})},b.getEditableCaret=function(l){if(!(l=h(l)[0]).isContentEditable)return{};var e,t,c=(h(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=h.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=h.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=h(u)[0]).isContentEditable)return{};var a=u.ownerDocument,i=a.createRange(),n=a.getSelection(),p=(h(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=h.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=h.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=h(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)},h.fn.keyboard=function(e){return this.each(function(){h(this).data("keyboard")||new h.keyboard(this,e)})},h.fn.getkeyboard=function(){return this.data("keyboard")},h.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,y=!0;try{p="selectionStart"in c}catch(e){y=!1}return y&&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});