wmdeit_kaform/addons/editable/kube.editable.min.js

1 line
1.2 KiB
JavaScript
Raw Permalink Normal View History

2020-02-20 13:45:47 +00:00
!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);