Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/lib/content-tools.min.js

7 lines
173 KiB
JavaScript
Raw Normal View History

2018-10-16 16:28:42 +00:00
/*! ContentTools v1.5.4 by Anthony Blackshaw <ant@getme.co.uk> (https://github.com/anthonyjb) */
(function(){var a,b;a={},a.Machine=function(){function a(a){this.context=a,this._stateTransitions={},this._stateTransitionsAny={},this._defaultTransition=null,this._initialState=null,this._currentState=null}return a.prototype.addTransition=function(a,b,c,d){return c||(c=b),this._stateTransitions[[a,b]]=[c,d]},a.prototype.addTransitions=function(a,b,c,d){var e,f,g,h;for(c||(c=b),h=[],f=0,g=a.length;g>f;f++)e=a[f],h.push(this.addTransition(e,b,c,d));return h},a.prototype.addTransitionAny=function(a,b,c){return b||(b=a),this._stateTransitionsAny[a]=[b,c]},a.prototype.setDefaultTransition=function(a,b){return this._defaultTransition=[a,b]},a.prototype.getTransition=function(a,b){if(this._stateTransitions[[a,b]])return this._stateTransitions[[a,b]];if(this._stateTransitionsAny[b])return this._stateTransitionsAny[b];if(this._defaultTransition)return this._defaultTransition;throw new Error("Transition is undefined: ("+a+", "+b+")")},a.prototype.getCurrentState=function(){return this._currentState},a.prototype.setInitialState=function(a){return this._initialState=a,this._currentState?void 0:this.reset()},a.prototype.reset=function(){return this._currentState=this._initialState},a.prototype.process=function(a){var b;return b=this.getTransition(a,this._currentState),b[1]&&b[1].call(this.context||(this.context=this),a),this._currentState=b[0]},a}(),"undefined"!=typeof window&&(window.FSM=a),"undefined"!=typeof module&&module.exports&&(b=module.exports=a)}).call(this),function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B=[].slice,C=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};r={},"undefined"!=typeof window&&(window.HTMLString=r),"undefined"!=typeof module&&module.exports&&(z=module.exports=r),r.String=function(){function a(a,b){null==b&&(b=!1),this._preserveWhitespace=b,a?(null===r.String._parser&&(r.String._parser=new A),this.characters=r.String._parser.parse(a,this._preserveWhitespace).characters):this.characters=[]}return a._parser=null,a.prototype.isWhitespace=function(){var a,b,c,d;for(d=this.characters,b=0,c=d.length;c>b;b++)if(a=d[b],!a.isWhitespace())return!1;return!0},a.prototype.length=function(){return this.characters.length},a.prototype.preserveWhitespace=function(){return this._preserveWhitespace},a.prototype.capitalize=function(){var a,b;return b=this.copy(),b.length()&&(a=b.characters[0]._c.toUpperCase(),b.characters[0]._c=a),b},a.prototype.charAt=function(a){return this.characters[a].copy()},a.prototype.concat=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;for(g=2<=arguments.length?B.call(arguments,0,i=arguments.length-1):(i=0,[]),c=arguments[i++],"undefined"!=typeof c&&"boolean"!=typeof c&&(g.push(c),c=!0),e=this.copy(),j=0,m=g.length;m>j;j++)if(f=g[j],0!==f.length){if(h=f,"string"==typeof f&&(h=new r.String(f,this._preserveWhitespace)),c&&e.length())for(b=e.charAt(e.length()-1),d=b.tags(),b.isTag()&&d.shift(),"string"!=typeof f&&(h=h.copy()),p=h.characters,k=0,n=p.length;n>k;k++)a=p[k],a.addTags.apply(a,d);for(q=h.characters,l=0,o=q.length;o>l;l++)a=q[l],e.characters.push(a)}return e},a.prototype.contains=function(a){var b,c,d,e,f,g,h;if("string"==typeof a)return this.text().indexOf(a)>-1;for(d=0;d<=this.length()-a.length();){for(c=!0,h=a.characters,e=f=0,g=h.length;g>f;e=++f)if(b=h[e],!b.eq(this.characters[e+d])){c=!1;break}if(c)return!0;d++}return!1},a.prototype.endsWith=function(a){var b,c,d,e,f,g;if("string"==typeof a)return""===a||this.text().slice(-a.length)===a;for(c=this.characters.slice().reverse(),g=a.characters.slice().reverse(),d=e=0,f=g.length;f>e;d=++e)if(b=g[d],!b.eq(c[d]))return!1;return!0},a.prototype.format=function(){var a,b,c,d,e,f,g;for(b=arguments[0],f=arguments[1],e=3<=arguments.length?B.call(arguments,2):[],0>f&&(f=this.length()+f+1),0>b&&(b=this.length()+b),d=this.copy(),c=g=b;f>=b?f>g:g>f;c=f>=b?++g:--g)a=d.characters[c],a.addTags.apply(a,e);return d},a.prototype.hasTags=function(){var a,b,c,d,e,f,g,h;for(d=2<=arguments.length?B.call(arguments,0,e=arguments.length-1):(e=0,[]),c=arguments[e++],"undefined"!=typeof
},c.prototype.hasCSSClass=function(a){var b,c;return this.attr("class")&&(c=function(){var a,c,d,e;for(d=this.attr("class").split(" "),e=[],a=0,c=d.length;c>a;a++)b=d[a],e.push(b);return e}.call(this),c.indexOf(a)>-1)?!0:!1},c.prototype.merge=function(a){return this.can("merge")&&this.can("remove")?this.constructor.mergers[a.type()]?this.constructor.mergers[a.type()](a,this):a.constructor.mergers[this.type()]?a.constructor.mergers[this.type()](a,this):void 0:!1},c.prototype.mount=function(){var b;return this._domElement||(this._domElement=document.createElement(this.tagName())),b=this.nextSibling(),b?this.parent().domElement().insertBefore(this._domElement,b.domElement()):this.isFixed()?(this.parent().domElement().parentNode.replaceChild(this._domElement,this.parent().domElement()),this.parent()._domElement=this._domElement):this.parent().domElement().appendChild(this._domElement),this._addDOMEventListeners(),this._addCSSClass("ce-element"),this._addCSSClass("ce-element--type-"+this.cssTypeName()),this.isFocused()&&this._addCSSClass("ce-element--focused"),a.Root.get().trigger("mount",this)},c.prototype.removeAttr=function(a){return a=a.toLowerCase(),this._attributes[a]?(delete this._attributes[a],this.isMounted()&&"class"!==a.toLowerCase()&&this._domElement.removeAttribute(a),this.taint()):void 0},c.prototype.removeCSSClass=function(a){var b,c,d;if(this.hasCSSClass(a))return d=function(){var a,c,d,e;for(d=this.attr("class").split(" "),e=[],a=0,c=d.length;c>a;a++)b=d[a],e.push(b);return e}.call(this),c=d.indexOf(a),c>-1&&d.splice(c,1),d.length?this.attr("class",d.join(" ")):this.removeAttr("class"),this._removeCSSClass(a),this.taint()},c.prototype.tagName=function(a){return void 0===a?this._tagName:(this._tagName=a.toLowerCase(),this.isMounted()&&(this.unmount(),this.mount()),this.taint())},c.prototype.unmount=function(){return this._removeDOMEventListeners(),this.isFixed()?(this._removeCSSClass("ce-element"),this._removeCSSClass("ce-element--type-"+this.cssTypeName()),void this._removeCSSClass("ce-element--focused")):(this._domElement.parentNode&&this._domElement.parentNode.removeChild(this._domElement),this._domElement=null,a.Root.get().trigger("unmount",this))},c.prototype._addDOMEventListeners=function(){var a,b,c,d;this._domEventHandlers={dragstart:function(){return function(a){return a.preventDefault()}}(this),focus:function(){return function(a){return a.preventDefault()}}(this),keydown:function(a){return function(b){return a._onKeyDown(b)}}(this),keyup:function(a){return function(b){return a._onKeyUp(b)}}(this),mousedown:function(a){return function(b){return 0===b.button?a._onMouseDown(b):void 0}}(this),mousemove:function(a){return function(b){return a._onMouseMove(b)}}(this),mouseover:function(a){return function(b){return a._onMouseOver(b)}}(this),mouseout:function(a){return function(b){return a._onMouseOut(b)}}(this),mouseup:function(a){return function(b){return 0===b.button?a._onMouseUp(b):void 0}}(this),dragover:function(){return function(a){return a.preventDefault()}}(this),drop:function(a){return function(b){return a._onNativeDrop(b)}}(this),paste:function(a){return function(b){return a._onPaste(b)}}(this)},c=this._domEventHandlers,d=[];for(b in c)a=c[b],d.push(this._domElement.addEventListener(b,a));return d},c.prototype._onKeyDown=function(){},c.prototype._onKeyUp=function(){},c.prototype._onMouseDown=function(){return this.focus?this.focus(!0):void 0},c.prototype._onMouseMove=function(a){return this._onOver(a)},c.prototype._onMouseOver=function(a){return this._onOver(a)},c.prototype._onMouseOut=function(){var b,c;return this._removeCSSClass("ce-element--over"),c=a.Root.get(),b=c.dragging(),b?(this._removeCSSClass("ce-element--drop"),this._removeCSSClass("ce-element--drop-above"),this._removeCSSClass("ce-element--drop-below"),this._removeCSSClass("ce-element--drop-center"),this._removeCSSClass("ce-element--drop-left"),this._removeCSSClass("ce-element--drop-right"),c._dropTarget=null):void 0},c.prototype._onMouseUp=function(){return this._ieMouseDownEchoed=!1},c.prototype._onNativeDrop=function(b){return b.
if(b=null,"a"===a.tagName.toLowerCase()){for(b=this.getDOMElementAttributes(a),f=function(){var b,c,e,f;for(e=a.childNodes,f=[],b=0,c=e.length;c>b;b++)d=e[b],f.push(d);return f}(),i=0,j=f.length;j>i;i++)if(e=f[i],1===e.nodeType&&"img"===e.tagName.toLowerCase()){a=e;break}"a"===a.tagName.toLowerCase()&&(a=document.createElement("img"))}return c=this.getDOMElementAttributes(a),h=c.width,g=c.height,void 0===c.width&&(h=void 0===c.height?a.naturalWidth:a.clientWidth),void 0===c.height&&(g=void 0===c.width?a.naturalHeight:a.clientHeight),c.width=h,c.height=g,new this(c,b)},c}(a.ResizableElement),a.TagNames.get().register(a.Image,"img"),a.ImageFixture=function(b){function c(a,b,d){c.__super__.constructor.call(this,a,b),this._src=d}return i(c,b),c.prototype.cssTypeName=function(){return"image-fixture"},c.prototype.type=function(){return"ImageFixture"},c.prototype.typeName=function(){return"ImageFixture"},c.prototype.html=function(b){var c,d,e,f;return null==b&&(b=""),f=a.LINE_ENDINGS,d=this._attributesToString(),c="",void 0!==this._attributes.alt&&(c='alt="'+this._attributes.alt+'"'),e=""+b+'<img src="'+this.src()+'"'+c+">",""+b+"<"+this.tagName()+" "+d+">"+f+(""+a.INDENT+e+f)+(""+b+"</"+this.tagName()+">")},c.prototype.mount=function(){var a,b,d,e,f;this._domElement=document.createElement(this.tagName()),f=this._attributes;for(b in f)e=f[b],"alt"!==b&&"style"!==b&&this._domElement.setAttribute(b,e);return a="",this.a&&this.a["class"]&&(a+=" "+this.a["class"]),this._attributes["class"]&&(a+=" "+this._attributes["class"]),this._domElement.setAttribute("class",a),d=this._attributes.style?this._attributes.style:"",d=d.replace(/background-image:.+?(;|$)/i,""),d=[d.trim(),"background-image:url('"+this.src()+"');"].join(" "),this._domElement.setAttribute("style",d.trim()),c.__super__.mount.call(this)},c.prototype.src=function(a){return void 0===a?this._src:(this._src=a.toLowerCase(),this.isMounted()&&(this.unmount(),this.mount()),this.taint())},c.prototype.unmount=function(){var a,b;return this.isFixed()?(b=document.createElement("div"),b.innerHTML=this.html(),a=b.firstElementChild,this._domElement.parentNode.replaceChild(a,this._domElement),this._domElement=a,this.parent()._domElement=this._domElement):c.__super__.unmount.call(this)},c.prototype._attributesToString=function(){var b,c,d,e,f;this._attributes.style?(d=this._attributes.style?this._attributes.style:"",d=d.replace(/background-image:.+?(;|$)/i,""),d=[d.trim(),"background-image:url('"+this.src()+"');"].join(" "),this._attributes.style=d.trim()):this._attributes.style="background-image:url('"+this.src()+"');",b={},f=this._attributes;for(c in f)e=f[c],"alt"!==c&&(b[c]=e);return" "+a.attributesToString(b)},c.droppers={ImageFixture:a.Element._dropVert,Image:a.Element._dropVert,PreText:a.Element._dropVert,Text:a.Element._dropVert},c.fromDOMElement=function(a){var b,c,d,e,f,g,h,i,j;for(h=a.tagName,c=this.getDOMElementAttributes(a),g="",b="",f=function(){var b,c,e,f;for(e=a.childNodes,f=[],b=0,c=e.length;c>b;b++)d=e[b],f.push(d);return f}(),i=0,j=f.length;j>i;i++)if(e=f[i],1===e.nodeType&&"img"===e.tagName.toLowerCase()){g=e.getAttribute("src")||"",b=e.getAttribute("alt")||"";break}return c=this.getDOMElementAttributes(a),c.alt=b,new this(a.tagName,c,g)},c}(a.Element),a.TagNames.get().register(a.ImageFixture,"img-fixture"),a.Video=function(b){function c(a,b,d){var e;null==d&&(d=[]),c.__super__.constructor.call(this,a,b),this.sources=d,e=this.size(),this._aspectRatio=e[1]/e[0]}return i(c,b),c.prototype.cssTypeName=function(){return"video"},c.prototype.type=function(){return"Video"},c.prototype.typeName=function(){return"Video"},c.prototype._title=function(){var a;return a="",this.attr("src")?a=this.attr("src"):this.sources.length&&(a=this.sources[0].src),a||(a="No video source set"),a.length>80&&(a=a.substr(0,80)+"..."),a},c.prototype.createDraggingDOMElement=function(){var a;if(this.isMounted())return a=c.__super__.createDraggingDOMElement.call(this),a.innerHTML=this._title(),a},c.prototype.html=function(b){var c,d,e,f,g,h,i;if(null==b&&(b=""),d=a.LINE_ENDINGS,"video"===this.tagN
},b.prototype.unmount=function(){return b.__super__.unmount.call(this),this._domEdit=null,this._domConfirm=null,this._domCancel=null},b.prototype._addDOMEventListeners=function(){return this._domEdit.addEventListener("click",function(a){return function(b){return b.preventDefault(),a.edit()}}(this)),this._domConfirm.addEventListener("click",function(a){return function(b){return b.preventDefault(),a.confirm()}}(this)),this._domCancel.addEventListener("click",function(a){return function(b){return b.preventDefault(),a.cancel()}}(this))},b}(b.WidgetUI),b.InspectorUI=function(a){function c(){c.__super__.constructor.call(this),this._tagUIs=[]}return h(c,a),c.prototype.mount=function(){return this._domElement=this.constructor.createDiv(["ct-widget","ct-inspector"]),this.parent().domElement().appendChild(this._domElement),this._domTags=this.constructor.createDiv(["ct-inspector__tags","ct-tags"]),this._domElement.appendChild(this._domTags),this._domCounter=this.constructor.createDiv(["ct-inspector__counter"]),this._domElement.appendChild(this._domCounter),this.updateCounter(),this._addDOMEventListeners(),this._handleFocusChange=function(a){return function(){return a.updateTags()}}(this),ContentEdit.Root.get().bind("blur",this._handleFocusChange),ContentEdit.Root.get().bind("focus",this._handleFocusChange),ContentEdit.Root.get().bind("mount",this._handleFocusChange)},c.prototype.unmount=function(){return c.__super__.unmount.call(this),this._domTags=null,ContentEdit.Root.get().unbind("blur",this._handleFocusChange),ContentEdit.Root.get().unbind("focus",this._handleFocusChange),ContentEdit.Root.get().unbind("mount",this._handleFocusChange)},c.prototype.updateCounter=function(){var a,c,d,e,f,g,h,i,j,k,l;if(this.isMounted()){for(c="",l=b.EditorApp.get().orderedRegions(),j=0,k=l.length;k>j;j++)g=l[j],g&&(c+=g.domElement().textContent);return c=c.trim(),c=c.replace(/<\/?[a-z][^>]*>/gi,""),c=c.replace(/[\u200B]+/,""),c=c.replace(/['";:,.?¿\-!¡]+/g,""),i=(c.match(/\S+/g)||[]).length,i=i.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),d=ContentEdit.Root.get().focused(),d&&"PreText"===d.type()&&d.selection().isCollapsed()?(e=0,a=1,h=d.content.substring(0,d.selection().get()[0]),f=h.text().split("\n"),e=f.length,a=f[f.length-1].length+1,e=e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),a=a.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),this._domCounter.textContent=""+i+" / "+e+":"+a):void(this._domCounter.textContent=i)}},c.prototype.updateTags=function(){var a,c,d,e,f,g,h,i,j;for(a=ContentEdit.Root.get().focused(),i=this._tagUIs,e=0,g=i.length;g>e;e++)d=i[e],d.unmount();if(this._tagUIs=[],a){for(c=a.parents(),c.reverse(),c.push(a),j=[],f=0,h=c.length;h>f;f++)a=c[f],-1===b.INSPECTOR_IGNORED_ELEMENTS.indexOf(a.type())&&(d=new b.TagUI(a),this._tagUIs.push(d),j.push(d.mount(this._domTags)));return j}},c.prototype._addDOMEventListeners=function(){return this._updateCounterInterval=setInterval(function(a){return function(){return a.updateCounter()}}(this),250)},c.prototype._removeDOMEventListeners=function(){return clearInterval(this._updateCounterInterval)},c}(b.WidgetUI),b.TagUI=function(a){function c(a){this.element=a,this._onMouseDown=i(this._onMouseDown,this),c.__super__.constructor.call(this)}return h(c,a),c.prototype.mount=function(a,b){return null==b&&(b=null),this._domElement=this.constructor.createDiv(["ct-tag"]),this._domElement.textContent=this.element.tagName(),c.__super__.mount.call(this,a,b)},c.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("mousedown",this._onMouseDown)},c.prototype._onMouseDown=function(a){var c,d,e;return a.preventDefault(),this.element.storeState&&this.element.storeState(),c=b.EditorApp.get(),e=new b.ModalUI,d=new b.PropertiesDialog(this.element),d.addEventListener("cancel",function(a){return function(){return e.hide(),d.hide(),a.element.restoreState?a.element.restoreState():void 0}}(this)),d.addEventListener("save",function(a){return function(b){var c,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;j=b.detail(),f=j.changedAttributes,n=j.changedStyles,l=j.innerHTML;for(m in f)if(o=f[m]
},e.prototype.save=function(){var a,b;return b=null,this._supportsCoding&&(b=this._domInnerHTML.value),a={changedAttributes:this.changedAttributes(),changedStyles:this.changedStyles(),innerHTML:b},this.dispatchEvent(this.createEvent("save",a))},e.prototype._addAttributeUI=function(c,d){var e,f;return f=this,e=new a(c,d),this._attributeUIs.push(e),e.addEventListener("blur",function(){var a,b,c;return f._focusedAttributeUI=null,ContentEdit.addCSSClass(f._domRemoveAttribute,"ct-control--muted"),a=f._attributeUIs.indexOf(this),c=f._attributeUIs.length,""===this.name()&&c-1>a&&(this.unmount(),f._attributeUIs.splice(a,1)),b=f._attributeUIs[c-1],b&&b.name()&&b.value()?f._addAttributeUI("",""):void 0}),e.addEventListener("focus",function(){return f._focusedAttributeUI=this,ContentEdit.removeCSSClass(f._domRemoveAttribute,"ct-control--muted")}),e.addEventListener("namechange",function(){var a,d,e,g,h,i,j;for(a=f.element,c=this.name().toLowerCase(),e=b.getRestrictedAtributes(a.tagName()),g=!0,e&&-1!==e.indexOf(c)&&(g=!1),j=f._attributeUIs,h=0,i=j.length;i>h;h++)d=j[h],""!==c&&d!==this&&d.name().toLowerCase()===c&&(g=!1);return this.valid(g),g?ContentEdit.removeCSSClass(f._domApply,"ct-control--muted"):ContentEdit.addCSSClass(f._domApply,"ct-control--muted")}),e.mount(this._domAttributes),e},e.prototype._addDOMEventListeners=function(){var a,b;return e.__super__._addDOMEventListeners.call(this),a=function(a){return function(b){var c,d,e,f,g,h;for(f=["attributes","code","styles"],g=0,h=f.length;h>g;g++)d=f[g],d!==b&&(e=d.charAt(0).toUpperCase()+d.slice(1),ContentEdit.removeCSSClass(a._domElement,"ct-properties-dialog--"+d),ContentEdit.removeCSSClass(a["_dom"+e+"Tab"],"ct-control--active"));return c=b.charAt(0).toUpperCase()+b.slice(1),ContentEdit.addCSSClass(a._domElement,"ct-properties-dialog--"+b),ContentEdit.addCSSClass(a["_dom"+c+"Tab"],"ct-control--active"),window.localStorage.setItem("ct-properties-dialog-tab",b)}}(this),this._domStylesTab.addEventListener("mousedown",function(){return function(){return a("styles")}}(this)),this._domAttributesTab.addEventListener("mousedown",function(){return function(){return a("attributes")}}(this)),this._supportsCoding&&this._domCodeTab.addEventListener("mousedown",function(){return function(){return a("code")}}(this)),this._domRemoveAttribute.addEventListener("mousedown",function(a){return function(b){var c,d;return b.preventDefault(),a._focusedAttributeUI&&(c=a._attributeUIs.indexOf(a._focusedAttributeUI),d=c===a._attributeUIs.length-1,a._focusedAttributeUI.unmount(),a._attributeUIs.splice(c,1),d)?a._addAttributeUI("",""):void 0}}(this)),b=function(a){return function(){var b;try{return b=new HTMLString.String(a._domInnerHTML.value),ContentEdit.removeCSSClass(a._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.removeCSSClass(a._domApply,"ct-control--muted")}catch(c){return ContentEdit.addCSSClass(a._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.addCSSClass(a._domApply,"ct-control--muted")}}}(this),this._domInnerHTML.addEventListener("input",b),this._domInnerHTML.addEventListener("propertychange",b),this._domApply.addEventListener("click",function(a){return function(b){var c;return b.preventDefault(),c=a._domApply.getAttribute("class"),-1===c.indexOf("ct-control--muted")?a.save():void 0}}(this))},e}(b.DialogUI),d=function(a){function b(a,c){this.style=a,b.__super__.constructor.call(this),this._applied=c}return h(b,a),b.prototype.applied=function(a){if(void 0===a)return this._applied;if(this._applied!==a)return this._applied=a,this._applied?ContentEdit.addCSSClass(this._domElement,"ct-section--applied"):ContentEdit.removeCSSClass(this._domElement,"ct-section--applied")},b.prototype.mount=function(a,c){var d;return null==c&&(c=null),this._domElement=this.constructor.createDiv(["ct-section"]),this._applied&&ContentEdit.addCSSClass(this._domElement,"ct-section--applied"),d=this.constructor.createDiv(["ct-section__label"]),d.textContent=this.style.name(),this._domElement.appendChild(d),this._domElement.appendChild(this.constructor.createDiv(["ct-sect
else if(a.isFixed()&&"a"===a.tagName())o=a.domElement().getBoundingClientRect();else{if(c.isCollapsed()){for(h=a.content.characters,s=c.get(0)[0],k=s;s>0&&h[s-1].hasTags("a");)s-=1;for(;k<h.length&&h[k].hasTags("a");)k+=1;c=new ContentSelect.Range(s,k),c.select(a.domElement())}a.storeState(),r=new HTMLString.Tag("span",{"class":"ct--puesdo-select"}),w=c.get(),l=w[0],t=w[1],a.content=a.content.format(l,t,r),a.updateInnerHTML(),j=a.domElement(),m=j.getElementsByClassName("ct--puesdo-select"),o=m[0].getBoundingClientRect()}return f=b.EditorApp.get(),n=new b.ModalUI(v=!0,e=!0),n.addEventListener("click",function(){return this.unmount(),i.hide(),a.content&&(a.content=a.content.unformat(l,t,r),a.updateInnerHTML(),a.restoreState()),d(g),g?b.Tools.Link.dispatchEditorEvent("tool-applied",u):void 0}),i=new b.LinkDialog(this.getAttr("href",a,c),this.getAttr("target",a,c)),x=b.getScrollPosition(),p=x[0],q=x[1],i.position([o.left+o.width/2+p,o.top+o.height/2+q]),i.addEventListener("save",function(b){var c,d,e,f,h,i,j,k,m;if(f=b.detail(),g=!0,"Image"===a.type()){if(d=["align-center","align-left","align-right"],f.href){for(a.a={href:f.href},a.a&&(a.a["class"]=a.a["class"]),f.target&&(a.a.target=f.target),i=0,k=d.length;k>i;i++)if(e=d[i],a.hasCSSClass(e)){a.removeCSSClass(e),a.a["class"]=e;break}}else{for(h=[],a.a["class"]&&(h=a.a["class"].split(" ")),j=0,m=d.length;m>j;j++)if(e=d[j],h.indexOf(e)>-1){a.addCSSClass(e);break}a.a=null}a.unmount(),a.mount()}else a.isFixed()&&"a"===a.tagName()?a.attr("href",f.href):(a.content=a.content.unformat(l,t,"a"),f.href&&(c=new HTMLString.Tag("a",f),a.content=a.content.format(l,t,c),a.content.optimize()),a.updateInnerHTML());return a.taint(),n.dispatchEvent(n.createEvent("click"))}),f.attach(n),f.attach(i),n.show(),i.show()}},c}(b.Tools.Bold),b.Tools.Heading=function(a){function c(){return c.__super__.constructor.apply(this,arguments)}return h(c,a),b.ToolShelf.stow(c,"heading"),c.label="Heading",c.icon="heading",c.tagName="h1",c.canApply=function(a){return a.isFixed()?!1:void 0!==a.content&&-1!==["Text","PreText"].indexOf(a.type())},c.isApplied=function(a){return a.content?-1===["Text","PreText"].indexOf(a.type())?!1:a.tagName()===this.tagName:!1},c.apply=function(a,b,c){var d,e,f,g,h;return h={tool:this,element:a,selection:b},this.dispatchEditorEvent("tool-apply",h)?(a.storeState(),"PreText"===a.type()?(d=a.content.html().replace(/&nbsp;/g," "),g=new ContentEdit.Text(this.tagName,{},d),f=a.parent(),e=f.children.indexOf(a),f.detach(a),f.attach(g,e),a.blur(),g.focus(),g.selection(b)):(a.removeAttr("class"),a.tagName(a.tagName()===this.tagName?"p":this.tagName),a.restoreState()),this.dispatchEditorEvent("tool-applied",h),c(!0)):void 0},c}(b.Tool),b.Tools.Subheading=function(a){function c(){return c.__super__.constructor.apply(this,arguments)}return h(c,a),b.ToolShelf.stow(c,"subheading"),c.label="Subheading",c.icon="subheading",c.tagName="h2",c}(b.Tools.Heading),b.Tools.Paragraph=function(a){function c(){return c.__super__.constructor.apply(this,arguments)}return h(c,a),b.ToolShelf.stow(c,"paragraph"),c.label="Paragraph",c.icon="paragraph",c.tagName="p",c.canApply=function(a){return a.isFixed()?!1:void 0!==a},c.apply=function(a,d,e){var f,g,h,i;return f=this.editor().ctrlDown(),b.Tools.Heading.canApply(a)&&!f?c.__super__.constructor.apply.call(this,a,d,e):(i={tool:this,element:a,selection:d},this.dispatchEditorEvent("tool-apply",i)?("Region"!==a.parent().type()&&(a=a.closest(function(a){return"Region"===a.parent().type()})),h=a.parent(),g=new ContentEdit.Text("p"),h.attach(g,h.children.indexOf(a)+1),g.focus(),e(!0),this.dispatchEditorEvent("tool-applied",i)):void 0)},c}(b.Tools.Heading),b.Tools.Preformatted=function(a){function c(){return c.__super__.constructor.apply(this,arguments)}return h(c,a),b.ToolShelf.stow(c,"preformatted"),c.label="Preformatted",c.icon="preformatted",c.tagName="pre",c.apply=function(a,c,d){var e,f,g,h,i;return i={tool:this,element:a,selection:c},this.dispatchEditorEvent("tool-apply",i)?"PreText"===a.type()?void b.Tools.Paragraph.apply(a,c,d):(h=a.content.text(),g=new ContentEd