1 line
2.8 KiB
JavaScript
1 line
2.8 KiB
JavaScript
define(["exports","./../dom.js","./../focusmanager.js","./../dialoghelper/dialoghelper.js"],function(_exports,_dom,_focusmanager,_dialoghelper){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!modules/alphanumericshortcuts/alphanumericshortcuts.css"]);var inputDisplayElement,alpanumericShortcutTimeout,currentDisplayText="";function clearAlphaNumericShortcutTimeout(){alpanumericShortcutTimeout&&(clearTimeout(alpanumericShortcutTimeout),alpanumericShortcutTimeout=null)}function resetAlphaNumericShortcutTimeout(instance){clearAlphaNumericShortcutTimeout(),alpanumericShortcutTimeout=setTimeout(function(){var value=currentDisplayText;currentDisplayText="",inputDisplayElement.innerHTML="",inputDisplayElement.classList.add("hide"),clearAlphaNumericShortcutTimeout(),function(instance,value){instance.onAlphaNumericValueEntered&&instance.onAlphaNumericValueEntered(value)}(this,value)}.bind(instance),2e3)}function onAlphanumericKeyPress(instance,e,chr){3<=currentDisplayText.length||(inputDisplayElement||((inputDisplayElement=document.createElement("div")).classList.add("alphanumeric-shortcut","hide","dialog"),_dom.default.allowBackdropFilter()&&inputDisplayElement.classList.add("dialog-blur"),document.body.appendChild(inputDisplayElement)),currentDisplayText+=chr,inputDisplayElement.innerHTML=currentDisplayText,inputDisplayElement.classList.remove("hide"),resetAlphaNumericShortcutTimeout(instance))}function AlphaNumericShortcuts(options){(this.options=options).focusScope=_focusmanager.default.getCurrentScope(),this.keyDownHandler=this.onKeyDown.bind(this),this.addEventListeners()}AlphaNumericShortcuts.prototype.onKeyDown=function(e){var options,tagName;e.ctrlKey||e.shiftKey||e.altKey||(options=this.options)&&options.focusScope===_focusmanager.default.getCurrentScope()&&"INPUT"!==(tagName=e.target.tagName)&&"TEXTAREA"!==tagName&&(e=(tagName=e.key)?tagName.match(/^[0-9a-zA-Z]+$/):null)&&1===(e=e.toString().toUpperCase()).length&&(options.itemsContainer,onAlphanumericKeyPress(this,0,e))},AlphaNumericShortcuts.prototype.addEventListeners=function(){var keyDownHandler;!this._eventHandlersBound&&(this._eventHandlersBound=!0,keyDownHandler=this.keyDownHandler)&&_dom.default.addEventListener(window,"keydown",keyDownHandler,{passive:!0})},AlphaNumericShortcuts.prototype.removeEventListeners=function(){this._eventHandlersBound=null;var keyDownHandler=this.keyDownHandler;keyDownHandler&&_dom.default.removeEventListener(window,"keydown",keyDownHandler,{passive:!0})},AlphaNumericShortcuts.prototype.pause=function(){this.removeEventListeners()},AlphaNumericShortcuts.prototype.resume=function(){this.addEventListeners()},AlphaNumericShortcuts.prototype.destroy=function(){this.removeEventListeners(),this.keyDownHandler=null,this.options=null},_exports.default=AlphaNumericShortcuts}); |