-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimpla-text.html
More file actions
1 lines (1 loc) · 4.4 KB
/
simpla-text.html
File metadata and controls
1 lines (1 loc) · 4.4 KB
1
<link rel="import" href="../polymer/polymer.html"> <link rel="import" href="../simpla-element-behavior/simpla-element-behavior.html"> <dom-module id="simpla-text"> <template> <style>:host{display:block}:host([contenteditable]){outline:0}:host([inline]){display:inline}</style> <slot></slot> </template> <script>!function(){"use strict";var e=document.createElement("simpla-text-toolbar"),t=["simpla-text-toolbar.html","../simpla-richtext-behavior/simpla-richtext-behavior.html"],i=["bold","italic","underline","link"],n={observers:["_checkEditorPrepped(editable, inline)","_updateEditorEditable(editable)"],getEditor:function(){return this._editor},_importEditorDeps:function(){var e=this,i=[];return t.forEach(function(t){i.push(new Promise(function(i,n){e.importHref(e.resolveUrl(t),i,n)}))}),Promise.all(i)},loadEditor:function(){var e=this;return Promise.resolve(this._editor||this._createEditor()).then(function(t){return e._editor=t,t})},runCommand:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.loadEditor().then(function(i){return i.format(e,t)})},_createEditor:function(){var t=this;return this.__waitForEditor||(this.__waitForEditor=this._importEditorDeps().then(function(){var n=window.SimplaBehaviors.RichText,o=void 0,r=void 0,a=void 0;return o=new n(t,{inline:t.inline,placeholder:t.placeholder,plugins:t.plaintext?[]:i,editable:t.editable,typographer:!t.noTypographer}),r=function(i){var n=i.name,r=i.applied,a=i.meta;e.target===o&&(t._tools=t._tools||{},t._tools[n]={applied:r,meta:a},e.set?(e.set("tools."+n+".active",r),e.set("tools."+n+".meta",a)):(e.tools=e.tools||{},e.tools[n]={applied:r,meta:a}))},a=function(i){var n=i.empty,r=i.native,a=!n&&t.editable&&!t.plaintext;t.fire("select",{selection:r}),e.parentElement!==document.body&&document.body.appendChild(e),e.range=a&&r.rangeCount&&r.getRangeAt(0),t._tools&&(e.tools=t._tools),r&&(e.target=o)},o.on("plugin",r),o.on("select",a),o.on("input",function(){t.__waitForEditor.then(function(){return t.fire("input")})}),t.value&&t.value.trim()&&o.setHTML(t.value),o})),this.__waitForEditor},_updateEditorEditable:function(e){var t=this.getEditor();t&&(t.editable=e)},_checkEditorPrepped:function(e){e&&this.loadEditor()}},o=["h1","h2","h3","h4","h5","h6","p","li","dd","figcaption","mark","q","s","time","u","legend","option","b","big","i","small","tt","abbr","acronym","cite","pre","code","dfn","em","kbd","strong","samp","var","a","span","sub","sup","button","label"],r={properties:{inline:{type:Boolean,reflectToAttribute:!0}},attached:function(){this._autoSetMode()},_autoSetMode:function(){var e=this.parentElement&&this.parentElement.nodeName.toLowerCase();void 0===this.inline&&(this.inline=-1!==o.indexOf(e))}},a=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},l=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),s={type:"Text",dataProperties:["value"],setCallback:"_setToSimpla",getCallback:"_getFromSimpla"},u=function(){function e(){a(this,e)}return l(e,[{key:"beforeRegister",value:function(){this.is="simpla-text",this.properties={plaintext:{type:Boolean,value:!1},placeholder:{type:String,value:"Enter your text..."},noTypographer:{type:Boolean,value:!1},active:{type:Boolean,notify:!0,readOnly:!0,value:!1},value:{type:String,observer:"_renderValue"}},this.listeners={tap:"_handleTap",blur:"_handleBlur",focus:"_handleFocus",input:"_refreshValue"}}},{key:"attached",value:function(){this._refreshValue()}},{key:"_handleBlur",value:function(){this._setActive(!1)}},{key:"_handleFocus",value:function(){this.editable&&this._setActive(!0)}},{key:"_handleTap",value:function(){this.editable&&this._setActive(!0)}},{key:"_editableObserver",value:function(e){e||this._setActive(!1)}},{key:"_refreshValue",value:function(){var e=this.getEditor();this.__refreshingValue=!0,this.value=e?e.getHTML():this.innerHTML,this.__refreshingValue=!1}},{key:"_renderValue",value:function(e){var t=this.getEditor();this.__refreshingValue||(t?t.setHTML(e):this.innerHTML=e)}},{key:"_getFromSimpla",value:function(e){e&&e.data&&this.value!==e.data.text&&(this.value=e.data.text)}},{key:"_setToSimpla",value:function(){return{text:this.value}}},{key:"behaviors",get:function(){return[SimplaBehaviors.Element(s),n,r]}}]),e}();Polymer(u)}()</script> </dom-module>