You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
1.2 KiB

  1. !function(e){e.add("module","editable",{init:function(e,t){this.app=e;var n={classname:"editable",focus:!1};this.context=t,this.params=t.getParams(n),this.$element=t.getElement()},start:function(){this.$element.addClass(this.params.classname).attr("contenteditable",!0),this._setFocus(),this._setEvents()},stop:function(){this.$element.removeClass(this.params.classname).removeAttr("contenteditable"),this.$element.off(".kube.editable")},_setEvents:function(){this.$element.on("keydown.kube.editable",this._keydown.bind(this)),this.$element.on("paste.kube.editable",this._paste.bind(this)),this.$element.on("blur.kube.editable",this._blur.bind(this))},_setFocus:function(){this.params.focus&&this.$element.focus()},_checkEmpty:function(){this.$element.text().replace(" ","").length||this.$element.empty()},_paste:function(e){e.preventDefault();var t=e.originalEvent||e,n="";t.clipboardData?(n=t.clipboardData.getData("text/plain"),document.execCommand("insertText",!1,n)):window.clipboardData&&(n=window.clipboardData.getData("Text"),document.selection.createRange().pasteHTML(n))},_blur:function(e){this._checkEmpty()},_keydown:function(e){13===e.which&&e.preventDefault()}})}(Kube);