Skip to content

Instantly share code, notes, and snippets.

@cloudwales
Created March 13, 2019 09:55
Show Gist options
  • Save cloudwales/8bb72daa1132ce7eb3ec4d9879cc41e2 to your computer and use it in GitHub Desktop.
Save cloudwales/8bb72daa1132ce7eb3ec4d9879cc41e2 to your computer and use it in GitHub Desktop.
content-tools.min.js
(function(){var x={};x.Machine=function(){function l(l){this.context=l;this._stateTransitions={};this._stateTransitionsAny={};this._currentState=this._initialState=this._defaultTransition=null}l.prototype.addTransition=function(l,t,g,f){g||(g=t);return this._stateTransitions[[l,t]]=[g,f]};l.prototype.addTransitions=function(l,t,g,f){var r;g||(g=t);var y=[];var z=0;for(r=l.length;z<r;z++){var c=l[z];y.push(this.addTransition(c,t,g,f))}return y};l.prototype.addTransitionAny=function(l,t,g){t||(t=l);
return this._stateTransitionsAny[l]=[t,g]};l.prototype.setDefaultTransition=function(l,t){return this._defaultTransition=[l,t]};l.prototype.getTransition=function(l,t){if(this._stateTransitions[[l,t]])return this._stateTransitions[[l,t]];if(this._stateTransitionsAny[t])return this._stateTransitionsAny[t];if(this._defaultTransition)return this._defaultTransition;throw Error("Transition is undefined: ("+l+", "+t+")");};l.prototype.getCurrentState=function(){return this._currentState};l.prototype.setInitialState=
function(l){this._initialState=l;if(!this._currentState)return this.reset()};l.prototype.reset=function(){return this._currentState=this._initialState};l.prototype.process=function(l){var t=this.getTransition(l,this._currentState);t[1]&&t[1].call(this.context||(this.context=this),l);return this._currentState=t[0]};return l}();"undefined"!==typeof window&&(window.FSM=x);"undefined"!==typeof module&&module.exports&&(module.exports=x)}).call(this);
(function(){var x=[].slice,l=[].indexOf||function(c){for(var a=0,b=this.length;a<b;a++)if(a in this&&this[a]===c)return a;return-1};var r={};"undefined"!==typeof window&&(window.HTMLString=r);"undefined"!==typeof module&&module.exports&&(module.exports=r);r.String=function(){function c(a,b){null==b&&(b=!1);this._preserveWhitespace=b;a?(null===r.String._parser&&(r.String._parser=new z),this.characters=r.String._parser.parse(a,this._preserveWhitespace).characters):this.characters=[]}c._parser=null;
c.prototype.isWhitespace=function(){var a;var b=this.characters;var e=0;for(a=b.length;e<a;e++){var d=b[e];if(!d.isWhitespace())return!1}return!0};c.prototype.length=function(){return this.characters.length};c.prototype.preserveWhitespace=function(){return this._preserveWhitespace};c.prototype.capitalize=function(){var a=this.copy();if(a.length()){var b=a.characters[0]._c.toUpperCase();a.characters[0]._c=b}return a};c.prototype.charAt=function(a){return this.characters[a].copy()};c.prototype.concat=
function(){var a,b,e;var d=2<=arguments.length?x.call(arguments,0,a=arguments.length-1):(a=0,[]);a=arguments[a++];"undefined"!==typeof a&&"boolean"!==typeof a&&(d.push(a),a=!0);var k=this.copy();var h=0;for(b=d.length;h<b;h++){var m=d[h];if(0!==m.length){var c=m;"string"===typeof m&&(c=new r.String(m,this._preserveWhitespace));if(a&&k.length()){var f=k.charAt(k.length()-1);var g=f.tags();f.isTag()&&g.shift();"string"!==typeof m&&(c=c.copy());var q=c.characters;m=0;for(e=q.length;m<e;m++)f=q[m],f.addTags.apply(f,
g)}m=c.characters;g=0;for(c=m.length;g<c;g++)f=m[g],k.characters.push(f)}}return k};c.prototype.contains=function(a){var b,e,d;if("string"===typeof a)return-1<this.text().indexOf(a);for(b=0;b<=this.length()-a.length();){var k=!0;var h=a.characters;var m=e=0;for(d=h.length;e<d;m=++e){var c=h[m];if(!c.eq(this.characters[m+b])){k=!1;break}}if(k)return!0;b++}return!1};c.prototype.endsWith=function(a){var b,e;if("string"===typeof a)return""===a||this.text().slice(-a.length)===a;var d=this.characters.slice().reverse();
var k=a.characters.slice().reverse();var h=b=0;for(e=k.length;b<e;h=++b)if(a=k[h],!a.eq(d[h]))return!1;return!0};c.prototype.format=function(){var a,b;var e=arguments[0];var d=arguments[1];var k=3<=arguments.length?x.call(arguments,2):[];0>d&&(d=this.length()+d+1);0>e&&(e=this.length()+e);var h=this.copy();for(a=b=e;e<=d?b<d:b>d;a=e<=d?++b:--b)a=h.characters[a],a.addTags.apply(a,k);return h};c.prototype.hasTags=function(){var a,b;var e=2<=arguments.length?x.call(arguments,0,a=arguments.length-1):
(a=0,[]);var d=arguments[a++];"undefined"!==typeof d&&"boolean"!==typeof d&&(e.push(d),d=!1);var k=!1;var h=this.characters;var m=0;for(b=h.length;m<b;m++)if(a=h[m],a.hasTags.apply(a,e))k=!0;else if(d)return!1;return k};c.prototype.html=function(){var a,b,e;var d="";var k=[];var h=[];var m=this.characters;var c=0;for(b=m.length;c<b;c++){var f=m[c];var g=[];var q=k.slice().reverse();var p=0;for(a=q.length;p<a;p++){var l=q[p];g.push(l);if(!f.hasTags(l)){var w=0;for(e=g.length;w<e;w++)l=g[w],d+=l.tail(),
k.pop(),h.pop();g=[]}}l=f._tags;a=0;for(q=l.length;a<q;a++)g=l[a],-1!==h.indexOf(g.head())||g.selfClosing()||(p=g.head(),d+=p,k.push(g),h.push(p));0<f._tags.length&&f._tags[0].selfClosing()&&(d+=f._tags[0].head());d+=f.c()}k=k.reverse();h=0;for(f=k.length;h<f;h++)g=k[h],d+=g.tail();return d};c.prototype.indexOf=function(a,b){var e,d;null==b&&(b=0);0>b&&(b=0);if("string"===typeof a)return this.text().indexOf(a,b);for(;b<=this.length()-a.length();){var k=!0;var h=a.characters;var m=e=0;for(d=h.length;e<
d;m=++e){var c=h[m];if(!c.eq(this.characters[m+b])){k=!1;break}}if(k)return b;b++}return-1};c.prototype.insert=function(a,b,e){var d;null==e&&(e=!0);var k=this.slice(0,a);var h=this.slice(a);0>a&&(a=this.length()+a);var m=b;"string"===typeof b&&(m=new r.String(b,this._preserveWhitespace));if(e&&0<a){e=this.charAt(a-1);a=e.tags();e.isTag()&&a.shift();"string"!==typeof b&&(m=m.copy());var c=m.characters;e=0;for(d=c.length;e<d;e++)b=c[e],b.addTags.apply(b,a)}e=m.characters;m=0;for(a=e.length;m<a;m++)b=
e[m],k.characters.push(b);a=h.characters;h=0;for(m=a.length;h<m;h++)b=a[h],k.characters.push(b);return k};c.prototype.lastIndexOf=function(a,b){var e,d,k;null==b&&(b=0);0>b&&(b=0);var h=this.characters.slice(b).reverse();b=0;if("string"===typeof a){if(!this.contains(a))return-1;for(a=a.split("").reverse();b<=h.length-a.length;){var m=!0;var c=d=e=0;for(k=a.length;d<k;c=++d){var f=a[c];h[c+b].isTag()&&(e+=1);if(f!==h[e+c+b].c()){m=!1;break}}if(m)return b;b++}return-1}for(a=a.characters.slice().reverse();b<=
h.length-a.length;){m=!0;c=e=0;for(d=a.length;e<d;c=++e)if(f=a[c],!f.eq(h[c+b])){m=!1;break}if(m)return b;b++}return-1};c.prototype.optimize=function(){var a,b,e;var d=[];var k=[];var h=null;var m=this.characters.slice().reverse();var c=0;for(e=m.length;c<e;c++){var f=m[c];f._runLengthMap={};f._runLengthMapSize=0;var g=[];var q=d.slice().reverse();var p=0;for(a=q.length;p<a;p++){var l=q[p];g.push(l);if(!f.hasTags(l)){l=0;for(g=g.length;l<g;l++)d.pop(),k.pop();g=[]}}q=f._tags;p=0;for(a=q.length;p<
a;p++){var w=q[p];-1!==k.indexOf(w.head())||w.selfClosing()||(d.push(w),k.push(w.head()))}g=0;for(q=d.length;g<q;g++)w=d[g],p=w.head(),h?(f._runLengthMap[p]||(f._runLengthMap[p]=[w,0]),a=0,h._runLengthMap[p]&&(a=h._runLengthMap[p][1]),f._runLengthMap[p][1]=a+1):f._runLengthMap[p]=[w,1];h=f}h=function(b,a){return a[1]-b[1]};c=this.characters;e=[];d=0;for(k=c.length;d<k;d++)if(f=c[d],m=f._tags.length,!(0<m&&f._tags[0].selfClosing()&&3>m||2>m)){var z=[];p=f._runLengthMap;for(w in p)m=p[w],z.push(m);
z.sort(h);a=f._tags.slice();p=0;for(m=a.length;p<m;p++)w=a[p],w.selfClosing()||f.removeTags(w);e.push(f.addTags.apply(f,function(){var a;var e=[];var d=0;for(a=z.length;d<a;d++)b=z[d],e.push(b[0]);return e}()))}return e};c.prototype.slice=function(a,b){var e=new r.String("",this._preserveWhitespace);var d;var k=this.characters.slice(a,b);var h=[];var m=0;for(d=k.length;m<d;m++){var c=k[m];h.push(c.copy())}e.characters=h;return e};c.prototype.split=function(a,b){var e,d,k;null==a&&(a="");null==b&&
(b=0);var h=0;for(e=[0];!(0<b&&0>b);){h=this.indexOf(a,h);if(-1===h)break;e.push(h);h+=1}e.push(this.length());var m=[];var c=d=0;for(k=e.length-2;0<=k?d<=k:d>=k;c=0<=k?++d:--d)h=e[c],0<c&&(h+=1),c=e[c+1],m.push(this.slice(h,c));return m};c.prototype.startsWith=function(a){var b,e;if("string"===typeof a)return this.text().slice(0,a.length)===a;var d=a.characters;var k=b=0;for(e=d.length;b<e;k=++b)if(a=d[k],!a.eq(this.characters[k]))return!1;return!0};c.prototype.substr=function(a,b){if(0>=b)return new r.String("",
this._preserveWhitespace);0>a&&(a=this.length()+a);void 0===b&&(b=this.length()-a);return this.slice(a,a+b)};c.prototype.substring=function(a,b){void 0===b&&(b=this.length());return this.slice(a,b)};c.prototype.text=function(){var a;var b="";var e=this.characters;var d=0;for(a=e.length;d<a;d++){var k=e[d];k.isTag()?k.isTag("br")&&(b+="\n"):(k.c(),b+=k.c())}return this.constructor.decode(b)};c.prototype.toLowerCase=function(){var a;var b=this.copy();var e=b.characters;var d=0;for(a=e.length;d<a;d++){var k=
e[d];1===k._c.length&&(k._c=k._c.toLowerCase())}return b};c.prototype.toUpperCase=function(){var a;var b=this.copy();var e=b.characters;var d=0;for(a=e.length;d<a;d++){var k=e[d];1===k._c.length&&(k._c=k._c.toUpperCase())}return b};c.prototype.trim=function(){var a,b;var e=this.characters;var d=a=0;for(b=e.length;a<b;d=++a){var k=e[d];if(!k.isWhitespace())break}var h=this.characters.slice().reverse();b=a=0;for(e=h.length;a<e&&(k=h[b],k.isWhitespace());b=++a);b=this.length()-b-1;a=new r.String("",
this._preserveWhitespace);e=this.characters.slice(d,+b+1||9E9);h=[];d=0;for(b=e.length;d<b;d++)k=e[d],h.push(k.copy());a.characters=h;return a};c.prototype.trimLeft=function(){var a,b;var e=this.length()-1;var d=this.characters;var k=a=0;for(b=d.length;a<b;k=++a){var h=d[k];if(!h.isWhitespace())break}a=new r.String("",this._preserveWhitespace);b=this.characters.slice(k,+e+1||9E9);d=[];k=0;for(e=b.length;k<e;k++)h=b[k],d.push(h.copy());a.characters=d;return a};c.prototype.trimRight=function(){var a,
b;var e=this.characters.slice().reverse();var d=a=0;for(b=e.length;a<b;d=++a){var k=e[d];if(!k.isWhitespace())break}d=this.length()-d-1;a=new r.String("",this._preserveWhitespace);e=this.characters.slice(0,+d+1||9E9);var h=[];d=0;for(b=e.length;d<b;d++)k=e[d],h.push(k.copy());a.characters=h;return a};c.prototype.unformat=function(){var a,b;var e=arguments[0];var d=arguments[1];var k=3<=arguments.length?x.call(arguments,2):[];0>d&&(d=this.length()+d+1);0>e&&(e=this.length()+e);var h=this.copy();for(a=
b=e;e<=d?b<d:b>d;a=e<=d?++b:--b)a=h.characters[a],a.removeTags.apply(a,k);return h};c.prototype.copy=function(){var a=new r.String("",this._preserveWhitespace);var b;var e=this.characters;var d=[];var k=0;for(b=e.length;k<b;k++){var h=e[k];d.push(h.copy())}a.characters=d;return a};c.decode=function(a){var b=document.createElement("textarea");b.innerHTML=a;return b.textContent};c.encode=function(a){var b=document.createElement("textarea");b.textContent=a;return b.innerHTML};c.join=function(a,b){var e;
var d=b.shift();var k=0;for(e=b.length;k<e;k++){var h=b[k];d=d.concat(a,h)}return d};return c}();var t="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-_$".split("");var g=t.concat("1234567890".split(""));var f=g.concat([":"]);var A=g.concat(["#"]);var y=g.concat([":"]);var z=function(){function c(){this.fsm=new FSM.Machine(this);this.fsm.setInitialState(1);this.fsm.addTransitionAny(1,null,function(a){return this._pushChar(a)});this.fsm.addTransition("<",1,3);this.fsm.addTransition("&",1,2);
this.fsm.addTransitions(A,2,null,function(a){return this.entity+=a});this.fsm.addTransition(";",2,1,function(){this._pushChar("&"+this.entity+";");return this.entity=""});this.fsm.addTransitions([" ","\n"],3);this.fsm.addTransitions(t,3,4,function(){return this._back()});this.fsm.addTransition("/",3,5);this.fsm.addTransitions([" ","\n"],4);this.fsm.addTransitions(t,4,6,function(){return this._back()});this.fsm.addTransitions([" ","\n"],5);this.fsm.addTransitions(t,5,7,function(){return this._back()});
this.fsm.addTransitions(y,6,null,function(a){return this.tagName+=a});this.fsm.addTransitions([" ","\n"],6,10);this.fsm.addTransition("/",6,8,function(){return this.selfClosing=!0});this.fsm.addTransition(">",6,1,function(){return this._pushTag()});this.fsm.addTransitions([" ","\n"],8);this.fsm.addTransition(">",8,1,function(){return this._pushTag()});this.fsm.addTransitions([" ","\n"],10);this.fsm.addTransition("/",10,8,function(){return this.selfClosing=!0});this.fsm.addTransition(">",10,1,function(){return this._pushTag()});
this.fsm.addTransitions(t,10,11,function(){return this._back()});this.fsm.addTransitions(y,7,null,function(a){return this.tagName+=a});this.fsm.addTransitions([" ","\n"],7,9);this.fsm.addTransition(">",7,1,function(){return this._popTag()});this.fsm.addTransitions([" ","\n"],9);this.fsm.addTransition(">",9,1,function(){return this._popTag()});this.fsm.addTransitions(f,11,null,function(a){return this.attributeName+=a});this.fsm.addTransitions([" ","\n"],11,12);this.fsm.addTransition("=",11,13);this.fsm.addTransitions([" ",
"\n"],12);this.fsm.addTransition("=",12,13);this.fsm.addTransitions(">",11,10,function(){this._pushAttribute();return this._back()});this.fsm.addTransitionAny(12,10,function(){this._pushAttribute();return this._back()});this.fsm.addTransitions([" ","\n"],13);this.fsm.addTransition("'",13,14);this.fsm.addTransition('"',13,15);this.fsm.addTransitions(g.concat(["&"],13,16,function(){return this._back()}));this.fsm.addTransition(" ",16,10,function(){return this._pushAttribute()});this.fsm.addTransitions(["/",
">"],16,10,function(){this._back();return this._pushAttribute()});this.fsm.addTransition("&",16,17);this.fsm.addTransitionAny(16,null,function(a){return this.attributeValue+=a});this.fsm.addTransition("'",14,10,function(){return this._pushAttribute()});this.fsm.addTransition("&",14,18);this.fsm.addTransitionAny(14,null,function(a){return this.attributeValue+=a});this.fsm.addTransition('"',15,10,function(){return this._pushAttribute()});this.fsm.addTransition("&",15,19);this.fsm.addTransitionAny(15,
null,function(a){return this.attributeValue+=a});this.fsm.addTransitions(A,17,null,function(a){return this.entity+=a});this.fsm.addTransitions(A,18,function(a){return this.entity+=a});this.fsm.addTransitions(A,19,null,function(a){return this.entity+=a});this.fsm.addTransition(";",17,16,function(){this.attributeValue+="&"+this.entity+";";return this.entity=""});this.fsm.addTransition(";",18,14,function(){this.attributeValue+="&"+this.entity+";";return this.entity=""});this.fsm.addTransition(";",19,
15,function(){this.attributeValue+="&"+this.entity+";";return this.entity=""})}c.prototype._back=function(){return this.head--};c.prototype._pushAttribute=function(){this.attributes[this.attributeName]=this.attributeValue;return this.attributeValue=this.attributeName=""};c.prototype._pushChar=function(a){a=new r.Character(a,this.tags);if(this._preserveWhitespace)this.string.characters.push(a);else{if(this.string.length()&&!a.isTag()&&!a.isEntity()&&a.isWhitespace()){var b=this.string.characters[this.string.length()-
1];if(b.isWhitespace()&&!b.isTag()&&!b.isEntity())return}return this.string.characters.push(a)}};c.prototype._pushTag=function(){var a;var b=new r.Tag(this.tagName,this.attributes);this.tags.push(b);b.selfClosing()&&(this._pushChar(""),this.tags.pop(),!this.selfClosed&&(a=this.tagName,0<=l.call(r.Tag.SELF_CLOSING,a))&&this.fsm.reset());this.tagName="";this.selfClosed=!1;return this.attributes={}};c.prototype._popTag=function(){for(var a,b;b=this.tags.pop(),this.string.length()&&(a=this.string.characters[this.string.length()-
1],a.isTag()||a.isEntity()||!a.isWhitespace()||a.removeTags(b)),b.name()!==this.tagName.toLowerCase(););return this.tagName=""};c.prototype.parse=function(a,b){this._preserveWhitespace=b;this.reset();a=this.preprocess(a);for(this.fsm.parser=this;this.head<a.length;){var e=a[this.head];try{this.fsm.process(e)}catch(d){throw e=d,Error("Error at char "+this.head+" >> "+e);}this.head++}return this.string};c.prototype.preprocess=function(a){a=a.replace(/\r\n/g,"\n").replace(/\r/g,"\n");a=a.replace(/\x3c!--[\s\S]*?--\x3e/g,
"");this._preserveWhitespace||(a=a.replace(/\s+/g," "));return a};c.prototype.reset=function(){this.fsm.reset();this.head=0;this.string=new r.String;this.entity="";this.tags=[];this.tagName="";this.selfClosing=!1;this.attributes={};return this.attributeValue=this.attributeName=""};return c}();r.Tag=function(){function c(a,b){var e;this._name=a.toLowerCase();this._selfClosing=!0===r.Tag.SELF_CLOSING[this._name];this._head=null;this._attributes={};for(e in b){var d=b[e];this._attributes[e]=d}}c.SELF_CLOSING=
{area:!0,base:!0,br:!0,hr:!0,img:!0,input:!0,"link meta":!0,wbr:!0};c.prototype.head=function(){var a,b;if(!this._head){var e=[];var d=this._attributes;for(a in d)(b=d[a])?e.push(""+a+'="'+b+'"'):e.push(""+a);e.sort();e.unshift(this._name);this._head="<"+e.join(" ")+">"}return this._head};c.prototype.name=function(){return this._name};c.prototype.selfClosing=function(){return this._selfClosing};c.prototype.tail=function(){return this._selfClosing?"":"</"+this._name+">"};c.prototype.attr=function(a,
b){if(void 0===b)return this._attributes[a];this._attributes[a]=b;return this._head=null};c.prototype.removeAttr=function(a){if(void 0!==this._attributes[a])return delete this._attributes[a],this._head=null};c.prototype.copy=function(){return new r.Tag(this._name,this._attributes)};return c}();r.Character=function(){function c(a,b){this._c=a;1<a.length&&(this._c=a.toLowerCase());this._tags=[];this.addTags.apply(this,b)}c.prototype.c=function(){return this._c};c.prototype.isEntity=function(){return 1<
this._c.length};c.prototype.isTag=function(a){return 0===this._tags.length||!this._tags[0].selfClosing()||a&&this._tags[0].name()!==a?!1:!0};c.prototype.isWhitespace=function(){var a;return" "===(a=this._c)||"\n"===a||"&nbsp;"===a||this.isTag("br")};c.prototype.tags=function(){var a;var b=this._tags;var e=[];var d=0;for(a=b.length;d<a;d++){var k=b[d];e.push(k.copy())}return e};c.prototype.addTags=function(){var a;var b=1<=arguments.length?x.call(arguments,0):[];var e=[];var d=0;for(a=b.length;d<a;d++){var k=
b[d];Array.isArray(k)||(k.selfClosing()?this.isTag()||this._tags.unshift(k.copy()):e.push(this._tags.push(k.copy())))}return e};c.prototype.eq=function(a){var b;if(this.c()!==a.c()||this._tags.length!==a._tags.length)return!1;var e={};var d=this._tags;var k=0;for(b=d.length;k<b;k++){var h=d[k];e[h.head()]=!0}b=a._tags;a=0;for(k=b.length;a<k;a++)if(h=b[a],!e[h.head()])return!1;return!0};c.prototype.hasTags=function(){var a;var b=1<=arguments.length?x.call(arguments,0):[];var e={};var d={};var k=this._tags;
var h=0;for(a=k.length;h<a;h++){var m=k[h];e[m.name()]=!0;d[m.head()]=!0}h=0;for(a=b.length;h<a;h++)if(m=b[h],"string"===typeof m){if(void 0===e[m])return!1}else if(void 0===d[m.head()])return!1;return!0};c.prototype.removeTags=function(){var a;var b=1<=arguments.length?x.call(arguments,0):[];if(0===b.length)this._tags=[];else{var e={};var d={};var k=0;for(a=b.length;k<a;k++){var h=b[k];"string"===typeof h?e[h]=h:d[h.head()]=h}return this._tags=this._tags.filter(function(b){if(!d[b.head()]&&!e[b.name()])return b})}};
c.prototype.copy=function(){var a=r.Character,b=this._c,e;var d=this._tags;var k=[];var h=0;for(e=d.length;h<e;h++){var m=d[h];k.push(m.copy())}return new a(b,k)};return c}()}).call(this);
(function(){var x=[].indexOf||function(f){for(var g=0,c=this.length;g<c;g++)if(g in this&&this[g]===f)return g;return-1};var l={};l.Range=function(){function y(f,c){this.set(f,c)}y.prototype.isCollapsed=function(){return this._from===this._to};y.prototype.span=function(){return this._to-this._from};y.prototype.collapse=function(){return this._to=this._from};y.prototype.eq=function(f){return this.get()[0]===f.get()[0]&&this.get()[1]===f.get()[1]};y.prototype.get=function(){return[this._from,this._to]};
y.prototype.select=function(f){l.Range.unselectAll();var c=document.createRange();var a=g(f,this._from);var b=a[0];a=a[1];var e=g(f,this._to);f=e[0];var d=e[1];var k=b.length||0;e=f.length||0;c.setStart(b,Math.min(a,k));c.setEnd(f,Math.min(d,e));return window.getSelection().addRange(c)};y.prototype.set=function(f,c){f=Math.max(0,f);c=Math.max(0,c);this._from=Math.min(f,c);return this._to=Math.max(f,c)};y.prepareElement=function(f){var c,a;var b=f.querySelectorAll(r.join(", "));var e=[];f=c=0;for(a=
b.length;c<a;f=++c){var d=b[f];d.parentNode.insertBefore(document.createTextNode(""),d);f<b.length-1?e.push(d.parentNode.insertBefore(document.createTextNode(""),d.nextSibling)):e.push(void 0)}return e};y.query=function(g){var c=new l.Range(0,0);try{var a=window.getSelection().getRangeAt(0)}catch(k){return c}if(null===g.firstChild&&null===g.lastChild||!t(a.startContainer,g)||!t(a.endContainer,g))return c;var b=A(g,a);var e=b[0];var d=b[1];a=b[2];b=b[3];c.set(f(g,e)+d,f(g,a)+b);return c};y.rect=function(){try{var f=
window.getSelection().getRangeAt(0)}catch(a){return null}if(f.collapsed){var c=document.createElement("span");f.insertNode(c);f=c.getBoundingClientRect();c.parentNode.removeChild(c);return f}return f.getBoundingClientRect()};y.unselectAll=function(){if(window.getSelection())return window.getSelection().removeAllRanges()};return y}();var r=["br","img","input"];var t=function(f,g){for(;f;){if(f===g)return!0;f=f.parentNode}return!1};var g=function(f,g){var c,a,b;if(0===f.childNodes.length)return[f,g];
var e=null;var d=g;for(c=function(){var b;var e=f.childNodes;var d=[];var c=0;for(b=e.length;c<b;c++)a=e[c],d.push(a);return d}();0<c.length;)switch(e=c.shift(),e.nodeType){case Node.TEXT_NODE:if(e.textContent.length>=d)return[e,d];d-=e.textContent.length;break;case Node.ELEMENT_NODE:if(b=e.nodeName.toLowerCase(),0<=x.call(r,b)){if(0===d)return[e,0];d=Math.max(0,d-1)}else e.childNodes&&Array.prototype.unshift.apply(c,function(){var b;var d=e.childNodes;var m=[];var c=0;for(b=d.length;c<b;c++)a=d[c],
m.push(a);return m}())}return[e,d]};var f=function(f,g){var c,a,b,e;if(0===f.childNodes.length)return 0;var d=0;for(c=function(){var b;var e=f.childNodes;var d=[];var k=0;for(b=e.length;k<b;k++)a=e[k],d.push(a);return d}();0<c.length;){var k=c.shift();if(k===g){if(b=k.nodeName.toLowerCase(),0<=x.call(r,b))return d+1;break}switch(k.nodeType){case Node.TEXT_NODE:d+=k.textContent.length;break;case Node.ELEMENT_NODE:(e=k.nodeName.toLowerCase(),0<=x.call(r,e))?d+=1:k.childNodes&&Array.prototype.unshift.apply(c,
function(){var b;var e=k.childNodes;var d=[];var c=0;for(b=e.length;c<b;c++)a=e[c],d.push(a);return d}())}}return d};var A=function(f,g){var c,a,b;var e=f.childNodes;var d=g.cloneRange();d.collapse(!0);var k=g.cloneRange();k.collapse(!1);var h=d.startContainer;var m=d.startOffset;var u=k.endContainer;var v=k.endOffset;if(!d.comparePoint)return[h,m,u,v];if(h===f){h=e[e.length-1];m=h.textContent.length;var n=c=0;for(a=e.length;c<a;n=++c){var q=e[n];if(1===d.comparePoint(q,0)){0===n?(h=q,m=0):(h=e[n-
1],m=q.textContent.length);if(b=h.nodeName.toLowerCase,0<=x.call(r,b))m=1;break}}}if(g.collapsed)return[h,m,h,m];if(u===f)for(u=e[e.length-1],v=u.textContent.length,n=d=0,c=e.length;d<c;n=++d)q=e[n],1===k.comparePoint(q,0)&&(u=0===n?q:e[n-1],v=q.textContent.length+1);return[h,m,u,v]};"undefined"!==typeof window&&(window.ContentSelect=l);"undefined"!==typeof module&&module.exports&&(module.exports=l)}).call(this);
(function(){var x=[].slice,l=[].indexOf||function(c){for(var a=0,b=this.length;a<b;a++)if(a in this&&this[a]===c)return a;return-1},r={}.hasOwnProperty,t=function(c,a){function b(){this.constructor=c}for(var e in a)r.call(a,e)&&(c[e]=a[e]);b.prototype=a.prototype;c.prototype=new b;c.__super__=a.prototype;return c},g=function(c,a){return function(){return c.apply(a,arguments)}};var f={ALIGNMENT_CLASS_NAMES:{left:"align-left",right:"align-right"},DEFAULT_MAX_ELEMENT_WIDTH:800,DEFAULT_MIN_ELEMENT_WIDTH:80,
DRAG_HOLD_DURATION:500,DROP_EDGE_SIZE:50,HELPER_CHAR_LIMIT:250,INDENT:" ",LANGUAGE:"en",LINE_ENDINGS:"\n",PREFER_LINE_BREAKS:!1,RESIZE_CORNER_SIZE:15,TRIM_WHITESPACE:!0,_translations:{},_:function(c){var a=f.LANGUAGE;return f._translations[a]&&f._translations[a][c]?f._translations[a][c]:c},addTranslations:function(c,a){return f._translations[c]=a},addCSSClass:function(c,a){var b;if(c.classList)c.classList.add(a);else if(b=c.getAttribute("class")){var e;var d=b.split(" ");var k=[];var h=0;for(e=
d.length;h<e;h++){var m=d[h];k.push(m)}if(-1===k.indexOf(a))return c.setAttribute("class",""+b+" "+a)}else return c.setAttribute("class",a)},attributesToString:function(c){var a;if(!c)return"";var b=[];for(k in c)b.push(k);b.sort();var e=[];var d=0;for(a=b.length;d<a;d++){var k=b[d];var h=c[k];""===h?e.push(k):(h=HTMLString.String.encode(h),h=h.replace(/"/g,"&quot;"),e.push(""+k+'="'+h+'"'))}return e.join(" ")},removeCSSClass:function(c,a){var b;if(c.classList)c.classList.remove(a),0===c.classList.length&&
c.removeAttribute("class");else if(b=c.getAttribute("class")){var e;var d=b.split(" ");b=[];var k=0;for(e=d.length;k<e;k++){var h=d[k];b.push(h)}h=b.indexOf(a);if(-1<h)return b.splice(h,1),b.length?c.setAttribute("class",b.join(" ")):c.removeAttribute("class")}}};"undefined"!==typeof window&&(window.ContentEdit=f);"undefined"!==typeof module&&module.exports&&(module.exports=f);var A=function(){function c(){this._tagNames={}}c.prototype.register=function(){var a;var b=arguments[0];var e=2<=arguments.length?
x.call(arguments,1):[];var d=[];var k=0;for(a=e.length;k<a;k++){var h=e[k];d.push(this._tagNames[h.toLowerCase()]=b)}return d};c.prototype.match=function(a){a=a.toLowerCase();return this._tagNames[a]?this._tagNames[a]:f.Static};return c}();f.TagNames=function(){function c(){}var a=null;c.get=function(){return null!=a?a:a=new A};return c}();f.Node=function(){function c(){this._bindings={};this._modified=this._parent=null}c.prototype.lastModified=function(){return this._modified};c.prototype.parent=
function(){return this._parent};c.prototype.parents=function(){var a;var b=[];for(a=this._parent;a;)b.push(a),a=a._parent;return b};c.prototype.type=function(){return"Node"};c.prototype.html=function(a){throw Error("`html` not implemented");};c.prototype.bind=function(a,b){void 0===this._bindings[a]&&(this._bindings[a]=[]);this._bindings[a].push(b);return b};c.prototype.trigger=function(){var a;var b=arguments[0];var e=2<=arguments.length?x.call(arguments,1):[];if(this._bindings[b]){var d=this._bindings[b];
var k=[];var h=0;for(a=d.length;h<a;h++)(b=d[h])&&k.push(b.call.apply(b,[this].concat(x.call(e))));return k}};c.prototype.unbind=function(a,b){var e,d;if(!a)this._bindings={};else if(!b)this._bindings[a]=void 0;else if(this._bindings[a]){var k=this._bindings[a];var h=[];var c=e=0;for(d=k.length;e<d;c=++e){var f=k[c];f===b?h.push(this._bindings[a].splice(c,1)):h.push(void 0)}return h}};c.prototype.commit=function(){this._modified=null;return f.Root.get().trigger("commit",this)};c.prototype.taint=function(){var a,
b;this._modified=a=Date.now();var e=this.parents();var d=0;for(b=e.length;d<b;d++){var k=e[d];k._modified=a}k=f.Root.get();k._modified=a;return k.trigger("taint",this)};c.prototype.closest=function(a){var b;for(b=this.parent();b&&!a(b);)b=b.parent?b.parent():null;return b};c.prototype.next=function(){var a;if(this.children&&0<this.children.length)return this.children[0];var b=[this].concat(this.parents());var e=0;for(a=b.length;e<a;e++){var d=b[e];if(!d.parent())return null;var k=d.parent().children;
d=k.indexOf(d);if(d<k.length-1)return k[d+1]}};c.prototype.nextContent=function(){return this.nextWithTest(function(a){return void 0!==a.content})};c.prototype.nextSibling=function(){var a=this.parent().children.indexOf(this);return a===this.parent().children.length-1?null:this.parent().children[a+1]};c.prototype.nextWithTest=function(a){var b;for(b=this;b;)if((b=b.next())&&a(b))return b};c.prototype.previous=function(){if(!this.parent())return null;var a=this.parent().children;if(a[0]===this)return this.parent();
for(a=a[a.indexOf(this)-1];a.children&&a.children.length;)a=a.children[a.children.length-1];return a};c.prototype.previousContent=function(){return this.previousWithTest(function(a){return void 0!==a.content})};c.prototype.previousSibling=function(){var a=this.parent().children.indexOf(this);return 0===a?null:this.parent().children[a-1]};c.prototype.previousWithTest=function(a){var b;for(b=this;b;)if((b=b.previous())&&a(b))return b};c.extend=function(a){var b;var e=a.prototype;for(b in e){var d=e[b];
"constructor"!==b&&(this.prototype[b]=d)}for(b in a)d=a[b],0<=l.call("__super__",b)||(this.prototype[b]=d);return this};c.fromDOMElement=function(a){throw Error("`fromDOMElement` not implemented");};return c}();f.NodeCollection=function(c){function a(){a.__super__.constructor.call(this);this.children=[]}t(a,c);a.prototype.descendants=function(){var b;var a=[];for(b=this.children.slice();0<b.length;){var d=b.shift();a.push(d);d.children&&0<d.children.length&&(b=d.children.slice().concat(b))}return a};
a.prototype.isMounted=function(){return!1};a.prototype.type=function(){return"NodeCollection"};a.prototype.attach=function(b,a){b.parent()&&b.parent().detach(b);b._parent=this;void 0!==a?this.children.splice(a,0,b):this.children.push(b);b.mount&&this.isMounted()&&b.mount();this.taint();return f.Root.get().trigger("attach",this,b)};a.prototype.commit=function(){var b;var a=this.descendants();var d=0;for(b=a.length;d<b;d++){var k=a[d];k._modified=null}this._modified=null;return f.Root.get().trigger("commit",
this)};a.prototype.detach=function(b){var a=this.children.indexOf(b);if(-1!==a)return b.unmount&&this.isMounted()&&b.isMounted()&&b.unmount(),this.children.splice(a,1),b._parent=null,this.taint(),f.Root.get().trigger("detach",this,b)};return a}(f.Node);f.Element=function(c){function a(b,e){a.__super__.constructor.call(this);this._tagName=b.toLowerCase();this._attributes=e?e:{};this._domElement=null;this._behaviours={drag:!0,drop:!0,merge:!0,remove:!0,resize:!0,spawn:!0}}t(a,c);a.prototype.attributes=
function(){var b;var a={};var d=this._attributes;for(b in d){var k=d[b];a[b]=k}return a};a.prototype.cssTypeName=function(){return"element"};a.prototype.domElement=function(){return this._domElement};a.prototype.isFixed=function(){return this.parent()&&"Fixture"===this.parent().type()};a.prototype.isFocused=function(){return f.Root.get().focused()===this};a.prototype.isMounted=function(){return null!==this._domElement};a.prototype.type=function(){return"Element"};a.prototype.typeName=function(){return"Element"};
a.prototype.addCSSClass=function(b){var a=!1;this.hasCSSClass(b)||(a=!0,this.attr("class")?this.attr("class",""+this.attr("class")+" "+b):this.attr("class",b));this._addCSSClass(b);if(a)return this.taint()};a.prototype.attr=function(b,a){b=b.toLowerCase();if(void 0===a)return this._attributes[b];this._attributes[b]=a;this.isMounted()&&"class"!==b.toLowerCase()&&this._domElement.setAttribute(b,a);return this.taint()};a.prototype.blur=function(){var b=f.Root.get();if(this.isFocused())return this._removeCSSClass("ce-element--focused"),
b._focused=null,b.trigger("blur",this)};a.prototype.can=function(b,a){return void 0===a?!this.isFixed()&&this._behaviours[b]:this._behaviours[b]=a};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=document.createElement("div");b.setAttribute("class","ce-drag-helper ce-drag-helper--type-"+this.cssTypeName());b.setAttribute("data-ce-type",f._(this.typeName()));return b}};a.prototype.drag=function(b,a){if(this.isMounted()&&this.can("drag")){var e=f.Root.get();e.startDragging(this,
b,a);return e.trigger("drag",this)}};a.prototype.drop=function(b,a){if(this.can("drop")){var e=f.Root.get();if(b){b._removeCSSClass("ce-element--drop");b._removeCSSClass("ce-element--drop-"+a[0]);b._removeCSSClass("ce-element--drop-"+a[1]);if(this.constructor.droppers[b.type()]){this.constructor.droppers[b.type()](this,b,a);e.trigger("drop",this,b,a);return}if(b.constructor.droppers[this.type()]){b.constructor.droppers[this.type()](this,b,a);e.trigger("drop",this,b,a);return}}return e.trigger("drop",
this,null,null)}};a.prototype.focus=function(b){var a=f.Root.get();if(!this.isFocused())return a.focused()&&a.focused().blur(),this._addCSSClass("ce-element--focused"),a._focused=this,this.isMounted()&&!b&&this.domElement().focus(),a.trigger("focus",this)};a.prototype.hasCSSClass=function(b){if(this.attr("class")){var a;var d=this.attr("class").split(" ");var k=[];var h=0;for(a=d.length;h<a;h++){var c=d[h];k.push(c)}if(-1<k.indexOf(b))return!0}return!1};a.prototype.merge=function(b){if(!this.can("merge")||
!this.can("remove"))return!1;if(this.constructor.mergers[b.type()])return this.constructor.mergers[b.type()](b,this);if(b.constructor.mergers[this.type()])return b.constructor.mergers[this.type()](b,this)};a.prototype.mount=function(){var b;this._domElement||(this._domElement=document.createElement(this.tagName()));(b=this.nextSibling())?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");return f.Root.get().trigger("mount",this)};a.prototype.removeAttr=function(b){b=b.toLowerCase();if(this._attributes[b])return delete this._attributes[b],this.isMounted()&&"class"!==b.toLowerCase()&&this._domElement.removeAttribute(b),
this.taint()};a.prototype.removeCSSClass=function(b){if(this.hasCSSClass(b)){var a;var d=this.attr("class").split(" ");var k=[];var h=0;for(a=d.length;h<a;h++){var c=d[h];k.push(c)}c=k.indexOf(b);-1<c&&k.splice(c,1);k.length?this.attr("class",k.join(" ")):this.removeAttr("class");this._removeCSSClass(b);return this.taint()}};a.prototype.tagName=function(b){if(void 0===b)return this._tagName;this._tagName=b.toLowerCase();this.isMounted()&&(this.unmount(),this.mount());return this.taint()};a.prototype.unmount=
function(){this._removeDOMEventListeners();if(this.isFixed())this._removeCSSClass("ce-element"),this._removeCSSClass("ce-element--type-"+this.cssTypeName()),this._removeCSSClass("ce-element--focused");else return this._domElement.parentNode&&this._domElement.parentNode.removeChild(this._domElement),this._domElement=null,f.Root.get().trigger("unmount",this)};a.prototype._addDOMEventListeners=function(){var b;var a=this._domEventHandlers={dragstart:function(b){return function(b){return b.preventDefault()}}(this),
focus:function(b){return function(b){return b.preventDefault()}}(this),keydown:function(b){return function(a){return b._onKeyDown(a)}}(this),keyup:function(b){return function(a){return b._onKeyUp(a)}}(this),mousedown:function(b){return function(a){if(0===a.button)return b._onMouseDown(a)}}(this),mousemove:function(b){return function(a){return b._onMouseMove(a)}}(this),mouseover:function(b){return function(a){return b._onMouseOver(a)}}(this),mouseout:function(b){return function(a){return b._onMouseOut(a)}}(this),
mouseup:function(b){return function(a){if(0===a.button)return b._onMouseUp(a)}}(this),dragover:function(b){return function(b){return b.preventDefault()}}(this),drop:function(b){return function(a){return b._onNativeDrop(a)}}(this),paste:function(b){return function(a){return b._onPaste(a)}}(this)};var d=[];for(b in a){var k=a[b];d.push(this._domElement.addEventListener(b,k))}return d};a.prototype._onKeyDown=function(b){};a.prototype._onKeyUp=function(b){};a.prototype._onMouseDown=function(b){if(this.focus)return this.focus(!0)};
a.prototype._onMouseMove=function(b){return this._onOver(b)};a.prototype._onMouseOver=function(b){return this._onOver(b)};a.prototype._onMouseOut=function(b){this._removeCSSClass("ce-element--over");b=f.Root.get();if(b.dragging())return 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"),
b._dropTarget=null};a.prototype._onMouseUp=function(b){return this._ieMouseDownEchoed=!1};a.prototype._onNativeDrop=function(b){b.preventDefault();b.stopPropagation();return f.Root.get().trigger("native-drop",this,b)};a.prototype._onPaste=function(b){b.preventDefault();b.stopPropagation();return f.Root.get().trigger("paste",this,b)};a.prototype._onOver=function(b){this._addCSSClass("ce-element--over");var a=f.Root.get();if((b=a.dragging())&&b!==this&&!a._dropTarget&&this.can("drop")&&(this.constructor.droppers[b.type()]||
b.constructor.droppers[this.type()]))return this._addCSSClass("ce-element--drop"),a._dropTarget=this};a.prototype._removeDOMEventListeners=function(){var b;var a=this._domEventHandlers;var d=[];for(b in a){var k=a[b];d.push(this._domElement.removeEventListener(b,k))}return d};a.prototype._addCSSClass=function(b){if(this.isMounted())return f.addCSSClass(this._domElement,b)};a.prototype._attributesToString=function(){return 0<Object.getOwnPropertyNames(this._attributes).length?" "+f.attributesToString(this._attributes):
""};a.prototype._removeCSSClass=function(b){if(this.isMounted())return f.removeCSSClass(this._domElement,b)};a.droppers={};a.mergers={};a.placements=["above","below"];a.getDOMElementAttributes=function(b){var a;if(!b.hasAttributes())return{};var d={};var k=b.attributes;var h=0;for(a=k.length;h<a;h++)b=k[h],d[b.name.toLowerCase()]=b.value;return d};a._dropVert=function(b,a,d){b.parent().detach(b);var e=a.parent().children.indexOf(a);"below"===d[0]&&(e+=1);return a.parent().attach(b,e)};a._dropBoth=
function(b,a,d){var e;b.parent().detach(b);var h=a.parent().children.indexOf(a);"below"===d[0]&&"center"===d[1]&&(h+=1);var c=f.ALIGNMENT_CLASS_NAMES.left;var u=f.ALIGNMENT_CLASS_NAMES.right;if(b.a){if(b._removeCSSClass(c),b._removeCSSClass(u),b.a["class"]){var g=[];var n=b.a["class"].split(" ");var q=0;for(e=n.length;q<e;q++){var p=n[q];p!==c&&p!==u&&g.push(p)}g.length?b.a["class"]=g.join(" "):delete b.a["class"]}}else b.removeCSSClass(c),b.removeCSSClass(u);"left"===d[1]&&(b.a?(b.a["class"]=b.a["class"]?
b.a["class"]+(" "+c):c,b._addCSSClass(c)):b.addCSSClass(c));"right"===d[1]&&(b.a?(b.a["class"]=b.a["class"]?b.a["class"]+(" "+u):u,b._addCSSClass(u)):b.addCSSClass(u));return a.parent().attach(b,h)};return a}(f.Node);f.ElementCollection=function(c){function a(b,e){a.__super__.constructor.call(this,b,e);f.NodeCollection.prototype.constructor.call(this)}t(a,c);a.extend(f.NodeCollection);a.prototype.cssTypeName=function(){return"element-collection"};a.prototype.isMounted=function(){return null!==this._domElement};
a.prototype.type=function(){return"ElementCollection"};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=a.__super__.createDraggingDOMElement.call(this);var e=this._domElement.textContent;e.length>f.HELPER_CHAR_LIMIT&&(e=e.substr(0,f.HELPER_CHAR_LIMIT));b.innerHTML=e;return b}};a.prototype.detach=function(b){f.NodeCollection.prototype.detach.call(this,b);if(0===this.children.length&&this.parent())return this.parent().detach(this)};a.prototype.html=function(b){null==b&&(b=
"");var a;var d=this.children;var k=[];var h=0;for(a=d.length;h<a;h++){var c=d[h];k.push(c.html(b+f.INDENT))}h=f.LINE_ENDINGS;if(this.isFixed())return k.join(h);c=this._attributesToString();return""+b+"<"+this.tagName()+c+">"+h+(""+k.join(h)+h)+(""+b+"</"+this.tagName()+">")};a.prototype.mount=function(){this._domElement=document.createElement(this._tagName);var b=this._attributes;for(h in b){var e=b[h];this._domElement.setAttribute(h,e)}a.__super__.mount.call(this);var d=this.children;var k=[];e=
0;for(b=d.length;e<b;e++){var h=d[e];k.push(h.mount())}return k};a.prototype.unmount=function(){var b;var e=this.children;var d=0;for(b=e.length;d<b;d++){var k=e[d];k.unmount()}return a.__super__.unmount.call(this)};a.prototype.blur=void 0;a.prototype.focus=void 0;return a}(f.Element);f.ResizableElement=function(c){function a(b,e){a.__super__.constructor.call(this,b,e);this._domSizeInfoElement=null;this._aspectRatio=1}t(a,c);a.prototype.aspectRatio=function(){return this._aspectRatio};a.prototype.maxSize=
function(){var b=parseInt(this.attr("data-ce-max-width")||0);b||(b=f.DEFAULT_MAX_ELEMENT_WIDTH);b=Math.max(b,this.size()[0]);return[b,b*this.aspectRatio()]};a.prototype.minSize=function(){var b=parseInt(this.attr("data-ce-min-width")||0);b||(b=f.DEFAULT_MIN_ELEMENT_WIDTH);b=Math.min(b,this.size()[0]);return[b,b*this.aspectRatio()]};a.prototype.type=function(){return"ResizableElement"};a.prototype.mount=function(){a.__super__.mount.call(this);return this._domElement.setAttribute("data-ce-size",this._getSizeInfo())};
a.prototype.resize=function(b,a,d){if(this.isMounted()&&this.can("resize"))return f.Root.get().startResizing(this,b,a,d,!0)};a.prototype.size=function(b){if(!b){var a=parseInt(this.attr("width")||1);b=parseInt(this.attr("height")||1);return[a,b]}b[0]=parseInt(b[0]);b[1]=parseInt(b[1]);a=this.minSize();b[0]=Math.max(b[0],a[0]);b[1]=Math.max(b[1],a[1]);a=this.maxSize();b[0]=Math.min(b[0],a[0]);b[1]=Math.min(b[1],a[1]);this.attr("width",parseInt(b[0]));this.attr("height",parseInt(b[1]));if(this.isMounted())return this._domElement.style.width=
""+b[0]+"px",this._domElement.style.height=""+b[1]+"px",this._domElement.setAttribute("data-ce-size",this._getSizeInfo())};a.prototype._onMouseDown=function(b){var e;a.__super__._onMouseDown.call(this,b);if(e=this._getResizeCorner(b.clientX,b.clientY))return this.resize(e,b.clientX,b.clientY);clearTimeout(this._dragTimeout);return this._dragTimeout=setTimeout(function(a){return function(){return a.drag(b.pageX,b.pageY)}}(this),150)};a.prototype._onMouseMove=function(b){a.__super__._onMouseMove.call(this);
if(this.can("resize")&&(this._removeCSSClass("ce-element--resize-top-left"),this._removeCSSClass("ce-element--resize-top-right"),this._removeCSSClass("ce-element--resize-bottom-left"),this._removeCSSClass("ce-element--resize-bottom-right"),b=this._getResizeCorner(b.clientX,b.clientY)))return this._addCSSClass("ce-element--resize-"+b[0]+"-"+b[1])};a.prototype._onMouseOut=function(b){a.__super__._onMouseOut.call(this);this._removeCSSClass("ce-element--resize-top-left");this._removeCSSClass("ce-element--resize-top-right");
this._removeCSSClass("ce-element--resize-bottom-left");return this._removeCSSClass("ce-element--resize-bottom-right")};a.prototype._onMouseUp=function(b){a.__super__._onMouseUp.call(this);if(this._dragTimeout)return clearTimeout(this._dragTimeout)};a.prototype._getResizeCorner=function(b,a){var e=this._domElement.getBoundingClientRect();var k=[b-e.left,a-e.top];b=k[0];a=k[1];var h=this.size();k=f.RESIZE_CORNER_SIZE;k=Math.min(k,Math.max(parseInt(h[0]/4),1));k=Math.min(k,Math.max(parseInt(h[1]/4),
1));h=null;b<k?a<k?h=["top","left"]:a>e.height-k&&(h=["bottom","left"]):b>e.width-k&&(a<k?h=["top","right"]:a>e.height-k&&(h=["bottom","right"]));return h};a.prototype._getSizeInfo=function(){var b=this.size();return"w "+b[0]+" \u00d7 h "+b[1]};return a}(f.Element);f.Region=function(c){function a(b){a.__super__.constructor.call(this);this._domElement=b;this.setContent(b)}t(a,c);a.prototype.domElement=function(){return this._domElement};a.prototype.isMounted=function(){return!0};a.prototype.type=function(){return"Region"};
a.prototype.html=function(b){null==b&&(b="");var a=f.LINE_ENDINGS;var d;var k=this.children;var h=[];var c=0;for(d=k.length;c<d;c++){var u=k[c];h.push(u.html(b))}return h.join(a).trim()};a.prototype.setContent=function(b){var a,d;var k=b;void 0===b.childNodes&&(k=document.createElement("div"),k.innerHTML=b);var h=this.children.slice();var c=0;for(a=h.length;c<a;c++)b=h[c],this.detach(b);b=f.TagNames.get();var u=k.childNodes;c=[];h=0;for(d=u.length;h<d;h++)a=u[h],c.push(a);h=0;for(d=c.length;h<d;h++)a=
c[h],1===a.nodeType&&(u=a.getAttribute("data-ce-tag")?b.match(a.getAttribute("data-ce-tag")):b.match(a.tagName),u=u.fromDOMElement(a),k.removeChild(a),u&&this.attach(u));return f.Root.get().trigger("ready",this)};return a}(f.NodeCollection);f.Fixture=function(c){function a(b){a.__super__.constructor.call(this);this._domElement=b;b=f.TagNames.get();b=(this._domElement.getAttribute("data-ce-tag")?b.match(this._domElement.getAttribute("data-ce-tag")):b.match(this._domElement.tagName)).fromDOMElement(this._domElement);
this.children=[b];b._parent=this;b.mount();f.Root.get().trigger("ready",this)}t(a,c);a.prototype.domElement=function(){return this._domElement};a.prototype.isMounted=function(){return!0};a.prototype.type=function(){return"Fixture"};a.prototype.html=function(b){null==b&&(b="");var a=f.LINE_ENDINGS;var d;var k=this.children;var h=[];var c=0;for(d=k.length;c<d;c++){var u=k[c];h.push(u.html(b))}return h.join(a).trim()};return a}(f.NodeCollection);var y=function(c){function a(){this._onStopResizing=g(this._onStopResizing,
this);this._onResize=g(this._onResize,this);this._onStopDragging=g(this._onStopDragging,this);this._onDrag=g(this._onDrag,this);a.__super__.constructor.call(this);this._resizingInit=this._resizing=this._draggingDOMElement=this._dropTarget=this._dragging=this._focused=null}t(a,c);a.prototype.dragging=function(){return this._dragging};a.prototype.dropTarget=function(){return this._dropTarget};a.prototype.focused=function(){return this._focused};a.prototype.resizing=function(){return this._resizing};
a.prototype.type=function(){return"Root"};a.prototype.cancelDragging=function(){if(this._dragging)return document.body.removeChild(this._draggingDOMElement),document.removeEventListener("mousemove",this._onDrag),document.removeEventListener("mouseup",this._onStopDragging),this._dragging._removeCSSClass("ce-element--dragging"),this._dropTarget=this._dragging=null,f.removeCSSClass(document.body,"ce--dragging")};a.prototype.startDragging=function(b,a,d){if(!this._dragging)return this._dragging=b,this._dragging._addCSSClass("ce-element--dragging"),
this._draggingDOMElement=this._dragging.createDraggingDOMElement(),document.body.appendChild(this._draggingDOMElement),this._draggingDOMElement.style.left=""+a+"px",this._draggingDOMElement.style.top=""+d+"px",document.addEventListener("mousemove",this._onDrag),document.addEventListener("mouseup",this._onStopDragging),f.addCSSClass(document.body,"ce--dragging")};a.prototype._getDropPlacement=function(b,a){if(!this._dropTarget)return null;var e=this._dropTarget.domElement().getBoundingClientRect();
var k=[b-e.left,a-e.top];b=k[0];a=k[1];k="center";b<f.DROP_EDGE_SIZE?k="left":b>e.width-f.DROP_EDGE_SIZE&&(k="right");var h="above";a>e.height/2&&(h="below");return[h,k]};a.prototype._onDrag=function(b){var a,d;ContentSelect.Range.unselectAll();this._draggingDOMElement.style.left=""+b.pageX+"px";this._draggingDOMElement.style.top=""+b.pageY+"px";if(this._dropTarget&&(b=this._getDropPlacement(b.clientX,b.clientY),this._dropTarget._removeCSSClass("ce-element--drop-above"),this._dropTarget._removeCSSClass("ce-element--drop-below"),
this._dropTarget._removeCSSClass("ce-element--drop-center"),this._dropTarget._removeCSSClass("ce-element--drop-left"),this._dropTarget._removeCSSClass("ce-element--drop-right"),(a=b[0],0<=l.call(this._dragging.constructor.placements,a))&&this._dropTarget._addCSSClass("ce-element--drop-"+b[0]),d=b[1],0<=l.call(this._dragging.constructor.placements,d)))return this._dropTarget._addCSSClass("ce-element--drop-"+b[1])};a.prototype._onStopDragging=function(b){b=this._getDropPlacement(b.clientX,b.clientY);
this._dragging.drop(this._dropTarget,b);return this.cancelDragging()};a.prototype.startResizing=function(b,a,d,k,h){if(!this._resizing)return this._resizing=b,this._resizingInit={corner:a,fixed:h,origin:[d,k],size:b.size()},this._resizing._addCSSClass("ce-element--resizing"),a=this._resizing.parent().domElement(),b=document.createElement("div"),b.setAttribute("class","ce-measure"),a.appendChild(b),this._resizingParentWidth=b.getBoundingClientRect().width,a.removeChild(b),document.addEventListener("mousemove",
this._onResize),document.addEventListener("mouseup",this._onStopResizing),f.addCSSClass(document.body,"ce--resizing")};a.prototype._onResize=function(b){ContentSelect.Range.unselectAll();var a=this._resizingInit.origin[0]-b.clientX;"right"===this._resizingInit.corner[1]&&(a=-a);a=this._resizingInit.size[0]+a;a=Math.min(a,this._resizingParentWidth);this._resizingInit.fixed?b=a*this._resizing.aspectRatio():(b=this._resizingInit.origin[1]-b.clientY,"bottom"===this._resizingInit.corner[0]&&(b=-b),b=this._resizingInit.size[1]+
b);return this._resizing.size([a,b])};a.prototype._onStopResizing=function(b){document.removeEventListener("mousemove",this._onResize);document.removeEventListener("mouseup",this._onStopResizing);this._resizing._removeCSSClass("ce-element--resizing");this._resizingParentWidth=this._resizingInit=this._resizing=null;return f.removeCSSClass(document.body,"ce--resizing")};return a}(f.Node);f.Root=function(){function c(){}var a=null;c.get=function(){return null!=a?a:a=new y};return c}();f.Static=function(c){function a(b,
e,d){a.__super__.constructor.call(this,b,e);this._content=d}t(a,c);a.prototype.cssTypeName=function(){return"static"};a.prototype.type=function(){return"Static"};a.prototype.typeName=function(){return"Static"};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=a.__super__.createDraggingDOMElement.call(this);var e=this._domElement.textContent;e.length>f.HELPER_CHAR_LIMIT&&(e=e.substr(0,f.HELPER_CHAR_LIMIT));b.innerHTML=e;return b}};a.prototype.html=function(b){null==b&&(b="");
return HTMLString.Tag.SELF_CLOSING[this._tagName]?""+b+"<"+this._tagName+this._attributesToString()+">":""+b+"<"+this._tagName+this._attributesToString()+">"+(""+this._content)+(""+b+"</"+this._tagName+">")};a.prototype.mount=function(){var b;this._domElement=document.createElement(this._tagName);var e=this._attributes;for(b in e){var d=e[b];this._domElement.setAttribute(b,d)}this._domElement.innerHTML=this._content;return a.__super__.mount.call(this)};a.prototype.blur=void 0;a.prototype.focus=void 0;
a.prototype._onMouseDown=function(b){a.__super__._onMouseDown.call(this,b);if(void 0!==this.attr("data-ce-moveable"))return clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(function(a){return function(){return a.drag(b.pageX,b.pageY)}}(this),150)};a.prototype._onMouseOver=function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.prototype._onMouseUp=function(b){a.__super__._onMouseUp.call(this,b);if(this._dragTimeout)return clearTimeout(this._dragTimeout)};
a.droppers={Static:f.Element._dropVert};a.fromDOMElement=function(b){return new this(b.tagName,this.getDOMElementAttributes(b),b.innerHTML)};return a}(f.Element);f.TagNames.get().register(f.Static,"static");f.Text=function(c){function a(b,e,d){a.__super__.constructor.call(this,b,e);this.content=d instanceof HTMLString.String?d:new HTMLString.String(d,!0)}t(a,c);a.prototype.cssTypeName=function(){return"text"};a.prototype.type=function(){return"Text"};a.prototype.typeName=function(){return"Text"};
a.prototype.blur=function(){this.isMounted()&&this._syncContent();this.content.isWhitespace()&&this.can("remove")?this.parent()&&this.parent().detach(this):this.isMounted()&&(document.documentMode||/Edge/.test(navigator.userAgent)||this._domElement.blur(),this._domElement.removeAttribute("contenteditable"));return a.__super__.blur.call(this)};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=a.__super__.createDraggingDOMElement.call(this);var e=HTMLString.String.encode(this._domElement.textContent);
e.length>f.HELPER_CHAR_LIMIT&&(e=e.substr(0,f.HELPER_CHAR_LIMIT));b.innerHTML=e;return b}};a.prototype.drag=function(b,e){this.storeState();this._domElement.removeAttribute("contenteditable");return a.__super__.drag.call(this,b,e)};a.prototype.drop=function(b,e){a.__super__.drop.call(this,b,e);return this.restoreState()};a.prototype.focus=function(b){this.isMounted()&&this._domElement.setAttribute("contenteditable","");return a.__super__.focus.call(this,b)};a.prototype.html=function(b){null==b&&(b=
"");if(!this._lastCached||this._lastCached<this._modified){var a=this.content.copy();a.optimize();this._lastCached=Date.now();this._cached=a.html()}var d=f.LINE_ENDINGS;a=this._attributesToString();return""+b+"<"+this._tagName+a+">"+d+(""+b+f.INDENT+this._cached+d)+(""+b+"</"+this._tagName+">")};a.prototype.mount=function(){var b;this._domElement=document.createElement(this._tagName);var e=this._attributes;for(b in e){var d=e[b];this._domElement.setAttribute(b,d)}this.updateInnerHTML();return a.__super__.mount.call(this)};
a.prototype.restoreState=function(){if(this._savedSelection){if(this.isMounted()&&this.isFocused())return this._domElement.setAttribute("contenteditable",""),this._addCSSClass("ce-element--focused"),document.activeElement!==this.domElement()&&this.domElement().focus(),this._savedSelection.select(this._domElement),this._savedSelection=void 0;this._savedSelection=void 0}};a.prototype.selection=function(b){return void 0===b?this.isMounted()?ContentSelect.Range.query(this._domElement):new ContentSelect.Range(0,
0):b.select(this._domElement)};a.prototype.storeState=function(){if(this.isMounted()&&this.isFocused())return this._savedSelection=ContentSelect.Range.query(this._domElement)};a.prototype.unmount=function(){this._domElement.removeAttribute("contenteditable");return a.__super__.unmount.call(this)};a.prototype.updateInnerHTML=function(){this._domElement.innerHTML=this.content.html();ContentSelect.Range.prepareElement(this._domElement);return this._flagIfEmpty()};a.prototype._onKeyDown=function(b){switch(b.keyCode){case 40:return this._keyDown(b);
case 37:return this._keyLeft(b);case 39:return this._keyRight(b);case 38:return this._keyUp(b);case 9:return this._keyTab(b);case 8:return this._keyBack(b);case 46:return this._keyDelete(b);case 13:return this._keyReturn(b)}};a.prototype._onKeyUp=function(b){a.__super__._onKeyUp.call(this,b);return this._syncContent()};a.prototype._onMouseDown=function(b){a.__super__._onMouseDown.call(this,b);clearTimeout(this._dragTimeout);this._dragTimeout=setTimeout(function(a){return function(){return a.drag(b.pageX,
b.pageY)}}(this),f.DRAG_HOLD_DURATION);if(0===this.content.length()&&f.Root.get().focused()===this)return b.preventDefault(),document.activeElement!==this._domElement&&this._domElement.focus(),(new ContentSelect.Range(0,0)).select(this._domElement)};a.prototype._onMouseMove=function(b){this._dragTimeout&&clearTimeout(this._dragTimeout);return a.__super__._onMouseMove.call(this,b)};a.prototype._onMouseOut=function(b){this._dragTimeout&&clearTimeout(this._dragTimeout);return a.__super__._onMouseOut.call(this,
b)};a.prototype._onMouseUp=function(b){this._dragTimeout&&clearTimeout(this._dragTimeout);return a.__super__._onMouseUp.call(this,b)};a.prototype._keyBack=function(b){var a=ContentSelect.Range.query(this._domElement);if(0===a.get()[0]&&a.isCollapsed()&&(b.preventDefault(),b=this.previousContent(),this._syncContent(),b))return b.merge(this)};a.prototype._keyDelete=function(b){var a=ContentSelect.Range.query(this._domElement);if(this._atEnd(a)&&a.isCollapsed()&&(b.preventDefault(),b=this.nextContent()))return this.merge(b)};
a.prototype._keyDown=function(b){return this._keyRight(b)};a.prototype._keyLeft=function(b){var a=ContentSelect.Range.query(this._domElement);if(0===a.get()[0]&&a.isCollapsed())return b.preventDefault(),(b=this.previousContent())?(b.focus(),a=new ContentSelect.Range(b.content.length(),b.content.length()),a.select(b.domElement())):f.Root.get().trigger("previous-region",this.closest(function(b){return"Fixture"===b.type()||"Region"===b.type()}))};a.prototype._keyReturn=function(b){b.preventDefault();
if(!(this.content.isWhitespace()&&!b.shiftKey^f.PREFER_LINE_BREAKS)){var a=ContentSelect.Range.query(this._domElement);var d=this.content.substring(0,a.get()[0]);var k=this.content.substring(a.get()[1]);if(b.shiftKey^f.PREFER_LINE_BREAKS)a=a.get()[0],d="<br>",this.content.length()===a&&(0!==this.content.length()&&this.content.characters[a-1].isTag("br")||(d="<br><br>")),this.content=this.content.insert(a,new HTMLString.String(d,!0),!0),this.updateInnerHTML(),a+=1,a=new ContentSelect.Range(a,a),a.select(this.domElement()),
this.taint();else if(this.can("spawn"))return this.content=d.trim(),this.updateInnerHTML(),b=new this.constructor("p",{},k.trim()),this.parent().attach(b,this.parent().children.indexOf(this)+1),d.length()?(b.focus(),a=new ContentSelect.Range(0,0),a.select(b.domElement())):(a=new ContentSelect.Range(0,d.length()),a.select(this._domElement)),this.taint()}};a.prototype._keyRight=function(b){var a=ContentSelect.Range.query(this._domElement);if(this._atEnd(a)&&a.isCollapsed())return b.preventDefault(),
(b=this.nextContent())?(b.focus(),a=new ContentSelect.Range(0,0),a.select(b.domElement())):f.Root.get().trigger("next-region",this.closest(function(b){return"Fixture"===b.type()||"Region"===b.type()}))};a.prototype._keyTab=function(b){b.preventDefault();if(this.isFixed())return b.shiftKey?f.Root.get().trigger("previous-region",this.closest(function(b){return"Fixture"===b.type()||"Region"===b.type()})):f.Root.get().trigger("next-region",this.closest(function(b){return"Fixture"===b.type()||"Region"===
b.type()}))};a.prototype._keyUp=function(b){return this._keyLeft(b)};a.prototype._atEnd=function(b){return b.get()[0]>=this.content.length()};a.prototype._flagIfEmpty=function(){return 0===this.content.length()?this._addCSSClass("ce-element--empty"):this._removeCSSClass("ce-element--empty")};a.prototype._syncContent=function(b){var a=this.content.html();this.content=new HTMLString.String(this._domElement.innerHTML,this.content.preserveWhitespace());b=this.content.html();a!==b&&this.taint();return this._flagIfEmpty()};
a.droppers={Static:f.Element._dropVert,Text:f.Element._dropVert};a.mergers={Text:function(b,a){var e=a.content.length();b.content.length()&&(a.content=a.content.concat(b.content));a.isMounted()&&a.updateInnerHTML();a.focus();(new ContentSelect.Range(e,e)).select(a._domElement);b.parent()&&b.parent().detach(b);return a.taint()}};a.fromDOMElement=function(b){return new this(b.tagName,this.getDOMElementAttributes(b),b.innerHTML)};return a}(f.Element);f.TagNames.get().register(f.Text,"address","blockquote",
"h1","h2","h3","h4","h5","h6","p");f.PreText=function(c){function a(b,a,d){this.content=d instanceof HTMLString.String?d:new HTMLString.String(d,!0);f.Element.call(this,b,a)}t(a,c);a.TAB_INDENT=" ";a.prototype.cssTypeName=function(){return"pre-text"};a.prototype.type=function(){return"PreText"};a.prototype.typeName=function(){return"Preformatted"};a.prototype.blur=function(){this.isMounted()&&(this._domElement.innerHTML=this.content.html());return a.__super__.blur.call(this)};a.prototype.html=
function(b){null==b&&(b="");if(!this._lastCached||this._lastCached<this._modified){var a=this.content.copy();a.optimize();this._lastCached=Date.now();this._cached=a.html()}return""+b+"<"+this._tagName+this._attributesToString()+">"+(""+this._cached+"</"+this._tagName+">")};a.prototype.updateInnerHTML=function(){var b=this.content.html();this._domElement.innerHTML=b;this._ensureEndZWS();ContentSelect.Range.prepareElement(this._domElement);return this._flagIfEmpty()};a.prototype._keyBack=function(b){var e=
ContentSelect.Range.query(this._domElement);if(e.get()[0]<=this.content.length())return a.__super__._keyBack.call(this,b);e.set(this.content.length(),this.content.length());return e.select(this._domElement)};a.prototype._keyReturn=function(b){b.preventDefault();var a=ContentSelect.Range.query(this._domElement);b=a.get()[0]+1;if(0===a.get()[0]&&a.isCollapsed())this.content=(new HTMLString.String("\n",!0)).concat(this.content);else if(this._atEnd(a)&&a.isCollapsed())this.content=this.content.concat(new HTMLString.String("\n",
!0));else if(0===a.get()[0]&&a.get()[1]===this.content.length())this.content=new HTMLString.String("\n",!0),b=0;else{var d=this.content.substring(0,a.get()[0]);var k=this.content.substring(a.get()[1]);this.content=d.concat(new HTMLString.String("\n",!0),k)}this.updateInnerHTML();a.set(b,b);a.select(this._domElement);return this.taint()};a.prototype._keyTab=function(b){var a,d,k;b.preventDefault();var h=this.content.length();var c=f.PreText.TAB_INDENT;var u=c.length;var g=this.content.split("\n");
var n=this.selection().get();n[0]=Math.min(n[0],h);n[1]=Math.min(n[1],h);var q=0;var p=a=-1;var l=d=0;for(k=g.length;d<k;l=++d){var w=g[l];w=w.length()+1;n[0]<q+w&&-1===a&&(a=l);n[1]<q+w&&-1===p&&(p=l);if(-1<a&&-1<p)break;q+=w}if(a===p)u-=(n[0]-q)%u,b=new HTMLString.String(Array(u+1).join(" "),!0),p=g[a].substring(0,n[0]-q),l=g[a].substring(n[1]-q),g[a]=p.concat(b,l);else if(b.shiftKey){b=0;for(l=d=a;a<=p?d<=p:d>=p;l=a<=p?++d:--d){var t=g[l].characters.slice();c=k=0;for(w=t.length;k<w;c=++k){q=t[c];
if(c>u-1)break;if(!q.isWhitespace())break;g[l].characters.shift()}l===a&&(b=c)}u=Math.max(-u,-b)}else for(b=new HTMLString.String(c,!0),l=q=a;a<=p?q<=p:q>=p;l=a<=p?++q:--q)g[l]=b.concat(g[l]);this.content=HTMLString.String.join(new HTMLString.String("\n",!0),g);this.updateInnerHTML();h=this.content.length()-h;return(new ContentSelect.Range(n[0]+u,n[1]+h)).select(this._domElement)};a.prototype._syncContent=function(b){this._ensureEndZWS();var a=this.content.html();this.content=new HTMLString.String(this._domElement.innerHTML.replace(/\u200B$/g,
""),this.content.preserveWhitespace());b=this.content.html();a!==b&&this.taint();return this._flagIfEmpty()};a.prototype._ensureEndZWS=function(){if(this._domElement.lastChild){var b=this._domElement.innerHTML;if(!("\u200b"===b[b.length-1]&&b.indexOf("\u200b")<b.length-1)){var a=function(a){return function(){-1<b.indexOf("\u200b")&&(a._domElement.innerHTML=b.replace(/\u200B/g,""));return a._domElement.lastChild.textContent+="\u200b"}}(this);if(this._savedSelection)return a();this.storeState();a();
return this.restoreState()}}};a.droppers={PreText:f.Element._dropVert,Static:f.Element._dropVert,Text:f.Element._dropVert};a.mergers={};a.fromDOMElement=function(b){return new this(b.tagName,this.getDOMElementAttributes(b),b.innerHTML)};return a}(f.Text);f.TagNames.get().register(f.PreText,"pre");f.Image=function(c){function a(b,e){a.__super__.constructor.call(this,"img",b);this.a=e?e:null;var d=this.size();this._aspectRatio=d[1]/d[0]}t(a,c);a.prototype.cssTypeName=function(){return"image"};a.prototype.type=
function(){return"Image"};a.prototype.typeName=function(){return"Image"};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=a.__super__.createDraggingDOMElement.call(this);b.style.backgroundImage="url('"+this._attributes.src+"')";return b}};a.prototype.html=function(b){null==b&&(b="");var a=""+b+"<img"+this._attributesToString()+">";if(this.a){var d=f.LINE_ENDINGS;var k=f.attributesToString(this.a);return""+b+"<a "+(""+k+' data-ce-tag="img"')+">"+d+(""+f.INDENT+a+d)+(""+b+
"</a>")}return a};a.prototype.mount=function(){this._domElement=document.createElement("div");var b="";this.a&&this.a["class"]&&(b+=" "+this.a["class"]);this._attributes["class"]&&(b+=" "+this._attributes["class"]);this._domElement.setAttribute("class",b);b=this._attributes.style?this._attributes.style:"";b+="background-image:url('"+this._attributes.src+"');";this._attributes.width&&(b+="width:"+this._attributes.width+"px;");this._attributes.height&&(b+="height:"+this._attributes.height+"px;");this._domElement.setAttribute("style",
b);return a.__super__.mount.call(this)};a.prototype.unmount=function(){if(this.isFixed()){var b=document.createElement("div");b.innerHTML=this.html();b=b.querySelector("a, img");this._domElement.parentNode.replaceChild(b,this._domElement);this._domElement=b}return a.__super__.unmount.call(this)};a.droppers={Image:f.Element._dropBoth,PreText:f.Element._dropBoth,Static:f.Element._dropBoth,Text:f.Element._dropBoth};a.placements=["above","below","left","right","center"];a.fromDOMElement=function(b){var a;
var d=null;if("a"===b.tagName.toLowerCase()){d=this.getDOMElementAttributes(b);var k=b.childNodes;var h=[];var c=0;for(a=k.length;c<a;c++){var f=k[c];h.push(f)}c=0;for(a=h.length;c<a;c++)if(f=h[c],1===f.nodeType&&"img"===f.tagName.toLowerCase()){b=f;break}"a"===b.tagName.toLowerCase()&&(b=document.createElement("img"))}h=this.getDOMElementAttributes(b);c=h.width;f=h.height;void 0===h.width&&(c=void 0===h.height?b.naturalWidth:b.clientWidth);void 0===h.height&&(f=void 0===h.width?b.naturalHeight:b.clientHeight);
h.width=c;h.height=f;return new this(h,d)};return a}(f.ResizableElement);f.TagNames.get().register(f.Image,"img");f.ImageFixture=function(c){function a(b,e,d){a.__super__.constructor.call(this,b,e);this._src=d}t(a,c);a.prototype.cssTypeName=function(){return"image-fixture"};a.prototype.type=function(){return"ImageFixture"};a.prototype.typeName=function(){return"ImageFixture"};a.prototype.html=function(b){null==b&&(b="");var a=f.LINE_ENDINGS;var d=this._attributesToString();var k="";void 0!==this._attributes.alt&&
(k='alt="'+this._attributes.alt+'"');k=""+b+'<img src="'+this.src()+'"'+k+">";return""+b+"<"+this.tagName()+" "+d+">"+a+(""+f.INDENT+k+a)+(""+b+"</"+this.tagName()+">")};a.prototype.mount=function(){this._domElement=document.createElement(this.tagName());var b=this._attributes;for(d in b){var e=b[d];"alt"!==d&&"style"!==d&&this._domElement.setAttribute(d,e)}var d="";this.a&&this.a["class"]&&(d+=" "+this.a["class"]);this._attributes["class"]&&(d+=" "+this._attributes["class"]);this._domElement.setAttribute("class",
d);d=this._attributes.style?this._attributes.style:"";e=document.createElement("div");e.setAttribute("style",d.trim());e.style.backgroundImage=null;d=e.getAttribute("style");d=[d.trim(),"background-image:url('"+this.src()+"');"].join(" ");this._domElement.setAttribute("style",d.trim());return a.__super__.mount.call(this)};a.prototype.src=function(b){if(void 0===b)return this._src;this._src=b;this.isMounted()&&(this.unmount(),this.mount());return this.taint()};a.prototype.unmount=function(){if(this.isFixed()){var b=
document.createElement("div");b.innerHTML=this.html();b=b.firstElementChild;this._domElement.parentNode.replaceChild(b,this._domElement);this._domElement=b;return this.parent()._domElement=this._domElement}return a.__super__.unmount.call(this)};a.prototype._attributesToString=function(){var b;if(this._attributes.style){var a=this._attributes.style?this._attributes.style:"";var d=document.createElement("div");d.setAttribute("style",a.trim());d.style.backgroundImage=null;a=d.getAttribute("style");a=
[a.trim(),"background-image:url('"+this.src()+"');"].join(" ");this._attributes.style=a.trim()}else this._attributes.style="background-image:url('"+this.src()+"');";a={};var k=this._attributes;for(b in k)d=k[b],"alt"!==b&&(a[b]=d);return" "+f.attributesToString(a)};a.droppers={ImageFixture:f.Element._dropVert,Image:f.Element._dropVert,PreText:f.Element._dropVert,Text:f.Element._dropVert};a.fromDOMElement=function(b){var a,d;this.getDOMElementAttributes(b);var k=a="";var h=b.childNodes;var c=[];var f=
0;for(d=h.length;f<d;f++){var g=h[f];c.push(g)}f=0;for(d=c.length;f<d;f++)if(g=c[f],1===g.nodeType&&"img"===g.tagName.toLowerCase()){a=g.getAttribute("src")||"";k=g.getAttribute("alt")||"";break}c=this.getDOMElementAttributes(b);c.alt=k;return new this(b.tagName,c,a)};return a}(f.Element);f.TagNames.get().register(f.ImageFixture,"img-fixture");f.Video=function(c){function a(b,e,d){null==d&&(d=[]);a.__super__.constructor.call(this,b,e);this.sources=d;b=this.size();this._aspectRatio=b[1]/b[0]}t(a,c);
a.prototype.cssTypeName=function(){return"video"};a.prototype.type=function(){return"Video"};a.prototype.typeName=function(){return"Video"};a.prototype._title=function(){var b="";this.attr("src")?b=this.attr("src"):this.sources.length&&(b=this.sources[0].src);b||(b="No video source set");80<b.length&&(b=b.substr(0,80)+"...");return b};a.prototype.createDraggingDOMElement=function(){if(this.isMounted()){var b=a.__super__.createDraggingDOMElement.call(this);b.innerHTML=this._title();return b}};a.prototype.html=
function(b){var a;null==b&&(b="");var d=f.LINE_ENDINGS;if("video"===this.tagName()){var k=[];var h=this.sources;var c=0;for(a=h.length;c<a;c++){var g=h[c];g=f.attributesToString(g);k.push(""+b+f.INDENT+"<source "+g+">")}return""+b+"<video"+this._attributesToString()+">"+d+k.join(d)+(""+d+b+"</video>")}return""+b+"<"+this._tagName+this._attributesToString()+">"+("</"+this._tagName+">")};a.prototype.mount=function(){this._domElement=document.createElement("div");this.a&&this.a["class"]?this._domElement.setAttribute("class",
this.a["class"]):this._attributes["class"]&&this._domElement.setAttribute("class",this._attributes["class"]);var b=this._attributes.style?this._attributes.style:"";this._attributes.width&&(b+="width:"+this._attributes.width+"px;");this._attributes.height&&(b+="height:"+this._attributes.height+"px;");this._domElement.setAttribute("style",b);this._domElement.setAttribute("data-ce-title",this._title());return a.__super__.mount.call(this)};a.prototype.unmount=function(){if(this.isFixed()){var b=document.createElement("div");
b.innerHTML=this.html();b=b.querySelector("iframe");this._domElement.parentNode.replaceChild(b,this._domElement);this._domElement=b}return a.__super__.unmount.call(this)};a.droppers={Image:f.Element._dropBoth,PreText:f.Element._dropBoth,Static:f.Element._dropBoth,Text:f.Element._dropBoth,Video:f.Element._dropBoth};a.placements=["above","below","left","right","center"];a.fromDOMElement=function(b){var a;var d=b.childNodes;var k=[];var h=0;for(a=d.length;h<a;h++){var c=d[h];k.push(c)}h=[];a=0;for(d=
k.length;a<d;a++)c=k[a],1===c.nodeType&&"source"===c.tagName.toLowerCase()&&h.push(this.getDOMElementAttributes(c));return new this(b.tagName,this.getDOMElementAttributes(b),h)};return a}(f.ResizableElement);f.TagNames.get().register(f.Video,"iframe","video");f.List=function(c){function a(b,e){a.__super__.constructor.call(this,b,e)}t(a,c);a.prototype.cssTypeName=function(){return"list"};a.prototype.type=function(){return"List"};a.prototype.typeName=function(){return"List"};a.prototype._onMouseOver=
function(b){if("ListItem"!==this.parent().type())return a.__super__._onMouseOver.call(this,b),this._removeCSSClass("ce-element--over")};a.droppers={Image:f.Element._dropBoth,ImageFixture:f.Element._dropVert,List:f.Element._dropVert,PreText:f.Element._dropVert,Static:f.Element._dropVert,Text:f.Element._dropVert,Video:f.Element._dropBoth};a.fromDOMElement=function(b){var a;var d=new this(b.tagName,this.getDOMElementAttributes(b));var k=b.childNodes;b=[];var h=0;for(a=k.length;h<a;h++){var c=k[h];b.push(c)}h=
0;for(a=b.length;h<a;h++)c=b[h],1===c.nodeType&&"li"===c.tagName.toLowerCase()&&d.attach(f.ListItem.fromDOMElement(c));return 0===d.children.length?null:d};return a}(f.ElementCollection);f.TagNames.get().register(f.List,"ol","ul");f.ListItem=function(c){function a(b){a.__super__.constructor.call(this,"li",b);this._behaviours.indent=!0}t(a,c);a.prototype.cssTypeName=function(){return"list-item"};a.prototype.list=function(){return 2===this.children.length?this.children[1]:null};a.prototype.listItemText=
function(){return 0<this.children.length?this.children[0]:null};a.prototype.type=function(){return"ListItem"};a.prototype.html=function(b){null==b&&(b="");var a=[""+b+"<li"+this._attributesToString()+">"];this.listItemText()&&a.push(this.listItemText().html(b+f.INDENT));this.list()&&a.push(this.list().html(b+f.INDENT));a.push(""+b+"</li>");return a.join(f.LINE_ENDINGS)};a.prototype.indent=function(){if(this.can("indent")&&0!==this.parent().children.indexOf(this)){var b=this.previousSibling();b.list()||
b.attach(new f.List(b.parent().tagName()));this.listItemText().storeState();this.parent().detach(this);b.list().attach(this);return this.listItemText().restoreState()}};a.prototype.remove=function(){var b,a;if(this.parent()){var d=this.parent().children.indexOf(this);if(this.list()){var k=this.list().children.slice();var h=b=0;for(a=k.length;b<a;h=++b){var c=k[h];c.parent().detach(c);this.parent().attach(c,h+d)}}return this.parent().detach(this)}};a.prototype.unindent=function(){var b,a;if(this.can("indent")){var d=
this.parent();var k=d.parent();var h=d.children.slice(d.children.indexOf(this)+1,d.children.length);if("ListItem"===k.type()){this.listItemText().storeState();d.detach(this);k.parent().attach(this,k.parent().children.indexOf(k)+1);h.length&&!this.list()&&this.attach(new f.List(d.tagName()));var c=0;for(b=h.length;c<b;c++)k=h[c],k.parent().detach(k),this.list().attach(k);return this.listItemText().restoreState()}b=new f.Text("p",this.attr("class")?{"class":this.attr("class")}:{},this.listItemText().content);
c=null;this.listItemText().isFocused()&&(c=ContentSelect.Range.query(this.listItemText().domElement()));var g=k.children.indexOf(d);var v=d.children.indexOf(this);if(0===v){if(v=null,1===d.children.length?(this.list()&&(v=new f.List(d.tagName())),k.detach(d)):d.detach(this),k.attach(b,g),v&&k.attach(v,g+1),this.list()){var n=this.list().children.slice();h=g=0;for(a=n.length;g<a;h=++g)k=n[h],k.parent().detach(k),v?v.attach(k):d.attach(k,h)}}else if(v===d.children.length-1)d.detach(this),k.attach(b,
g+1),this.list()&&k.attach(this.list(),g+2);else{d.detach(this);k.attach(b,g+1);v=new f.List(d.tagName());k.attach(v,g+2);if(this.list())for(a=this.list().children.slice(),d=0,g=a.length;d<g;d++)k=a[d],k.parent().detach(k),v.attach(k);d=0;for(g=h.length;d<g;d++)k=h[d],k.parent().detach(k),v.attach(k)}if(c)return b.focus(),c.select(b.domElement())}};a.prototype._onMouseOver=function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.prototype._addDOMEventListeners=
function(){};a.prototype._removeDOMEventListners=function(){};a.fromDOMElement=function(b){var a,d;var k=new this(this.getDOMElementAttributes(b));var h="";var c=null;var g=b.childNodes;var v=0;for(a=g.length;v<a;v++)b=g[v],1===b.nodeType?"ul"===(d=b.tagName.toLowerCase())||"ol"===d||"li"===d?c||(c=b):h+=b.outerHTML:h+=HTMLString.String.encode(b.textContent);h=h.replace(/^\s+|\s+$/g,"");h=new f.ListItemText(h);k.attach(h);c&&(c=f.List.fromDOMElement(c),k.attach(c));return k};return a}(f.ElementCollection);
f.ListItemText=function(c){function a(b){a.__super__.constructor.call(this,"div",{},b)}t(a,c);a.prototype.cssTypeName=function(){return"list-item-text"};a.prototype.type=function(){return"ListItemText"};a.prototype.typeName=function(){return"List item"};a.prototype.blur=function(){this.content.isWhitespace()&&this.can("remove")?this.parent().remove():this.isMounted()&&(this._domElement.blur(),this._domElement.removeAttribute("contenteditable"));return f.Element.prototype.blur.call(this)};a.prototype.can=
function(b,a){if(a)throw Error("Cannot set behaviour for ListItemText");return this.parent().can(b)};a.prototype.html=function(b){null==b&&(b="");if(!this._lastCached||this._lastCached<this._modified){var a=f.TRIM_WHITESPACE?this.content.copy().trim():this.content.copy();a.optimize();this._lastCached=Date.now();this._cached=a.html()}return""+b+this._cached};a.prototype._onMouseDown=function(b){f.Element.prototype._onMouseDown.call(this,b);var a=function(e){return function(){if(f.Root.get().dragging()===
e){f.Root.get().cancelDragging();var d=e.closest(function(b){return"Region"===b.parent().type()});return d.drag(b.pageX,b.pageY)}e.drag(b.pageX,b.pageY);return e._dragTimeout=setTimeout(a,2*f.DRAG_HOLD_DURATION)}}(this);clearTimeout(this._dragTimeout);return this._dragTimeout=setTimeout(a,f.DRAG_HOLD_DURATION)};a.prototype._onMouseMove=function(b){this._dragTimeout&&clearTimeout(this._dragTimeout);return f.Element.prototype._onMouseMove.call(this,b)};a.prototype._onMouseUp=function(b){this._dragTimeout&&
clearTimeout(this._dragTimeout);return f.Element.prototype._onMouseUp.call(this,b)};a.prototype._keyTab=function(b){b.preventDefault();return b.shiftKey?this.parent().unindent():this.parent().indent()};a.prototype._keyReturn=function(b){b.preventDefault();if(this.content.isWhitespace())this.parent().unindent();else if(this.can("spawn")){ContentSelect.Range.query(this._domElement);var a=ContentSelect.Range.query(this._domElement);var d=this.content.substring(0,a.get()[0]);var k=this.content.substring(a.get()[1]);
if(0===d.length()+k.length())this.parent().unindent();else{this.content=d.trim();this.updateInnerHTML();a=this.parent().parent();b=new f.ListItem(this.attr("class")?{"class":this.attr("class")}:{});a.attach(b,a.children.indexOf(this.parent())+1);b.attach(new f.ListItemText(k.trim()));if(a=this.parent().list())this.parent().detach(a),b.attach(a);d.length()?(b.listItemText().focus(),a=new ContentSelect.Range(0,0),a.select(b.listItemText().domElement())):(a=new ContentSelect.Range(0,d.length()),a.select(this._domElement));
return this.taint()}}};a.droppers={ListItemText:function(b,a,d){var e=b.parent();a=a.parent();e.remove();e.detach(b);e=new f.ListItem(e._attributes);e.attach(b);if(a.list()&&"below"===d[0])a.list().attach(e,0);else return b=a.parent().children.indexOf(a),"below"===d[0]&&(b+=1),a.parent().attach(e,b)},Text:function(b,a,d){if("Text"===b.type()){a=a.parent();b.parent().detach(b);var e=b.attr("class");var c=new f.ListItem(e?{"class":e}:{});c.attach(new f.ListItemText(b.content));if(a.list()&&"below"===
d[0])a.list().attach(c,0);else if(e=a.parent().children.indexOf(a),"below"===d[0]&&(e+=1),a.parent().attach(c,e),c.listItemText().focus(),b._savedSelection)return b._savedSelection.select(c.listItemText().domElement())}else if(e=b.attr("class"),c=new f.Text("p",e?{"class":e}:{},b.content),b.parent().remove(),e=a.parent().children.indexOf(a),"below"===d[0]&&(e+=1),a.parent().attach(c,e),c.focus(),b._savedSelection)return b._savedSelection.select(c.domElement())}};a.mergers={ListItemText:function(b,
a){var e=a.content.length();b.content.length()&&(a.content=a.content.concat(b.content));a.isMounted()&&(a._domElement.innerHTML=a.content.html());a.focus();(new ContentSelect.Range(e,e)).select(a._domElement);"Text"===b.type()?b.parent()&&b.parent().detach(b):b.parent().remove();return a.taint()}};return a}(f.Text);var z=f.ListItemText.mergers;z.Text=z.ListItemText;f.Table=function(c){function a(b){a.__super__.constructor.call(this,"table",b)}t(a,c);a.prototype.cssTypeName=function(){return"table"};
a.prototype.typeName=function(){return"Table"};a.prototype.type=function(){return"Table"};a.prototype.firstSection=function(){var b;return(b=this.thead())||(b=this.tbody())||(b=this.tfoot())?b:null};a.prototype.lastSection=function(){var b;return(b=this.tfoot())||(b=this.tbody())||(b=this.thead())?b:null};a.prototype.tbody=function(){return this._getChild("tbody")};a.prototype.tfoot=function(){return this._getChild("tfoot")};a.prototype.thead=function(){return this._getChild("thead")};a.prototype._onMouseOver=
function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.prototype._getChild=function(b){var a;var d=this.children;var k=0;for(a=d.length;k<a;k++){var c=d[k];if(c.tagName()===b)return c}return null};a.droppers={Image:f.Element._dropBoth,ImageFixture:f.Element._dropVert,List:f.Element._dropVert,PreText:f.Element._dropVert,Static:f.Element._dropVert,Table:f.Element._dropVert,Text:f.Element._dropVert,Video:f.Element._dropBoth};a.fromDOMElement=function(b){var a;
var d=new this(this.getDOMElementAttributes(b));var k=b.childNodes;b=[];var c=0;for(a=k.length;c<a;c++){var m=k[c];b.push(m)}m=[];c=0;for(a=b.length;c<a;c++)if(k=b[c],1===k.nodeType){var g=k.tagName.toLowerCase();if(!d._getChild(g))switch(g){case "tbody":case "tfoot":case "thead":k=f.TableSection.fromDOMElement(k);d.attach(k);break;case "tr":m.push(f.TableRow.fromDOMElement(k))}}if(0<m.length)for(d._getChild("tbody")||d.attach(new f.TableSection("tbody")),c=0,a=m.length;c<a;c++)b=m[c],d.tbody().attach(b);
return 0===d.children.length?null:d};return a}(f.ElementCollection);f.TagNames.get().register(f.Table,"table");f.TableSection=function(c){function a(b,e){a.__super__.constructor.call(this,b,e)}t(a,c);a.prototype.cssTypeName=function(){return"table-section"};a.prototype.type=function(){return"TableSection"};a.prototype._onMouseOver=function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.fromDOMElement=function(b){var a;var d=new this(b.tagName,this.getDOMElementAttributes(b));
var k=b.childNodes;b=[];var c=0;for(a=k.length;c<a;c++){var m=k[c];b.push(m)}c=0;for(a=b.length;c<a;c++)m=b[c],1===m.nodeType&&"tr"===m.tagName.toLowerCase()&&d.attach(f.TableRow.fromDOMElement(m));return d};return a}(f.ElementCollection);f.TableRow=function(c){function a(b){a.__super__.constructor.call(this,"tr",b)}t(a,c);a.prototype.cssTypeName=function(){return"table-row"};a.prototype.isEmpty=function(){var b;var a=this.children;var d=0;for(b=a.length;d<b;d++){var c=a[d];if((c=c.tableCellText())&&
0<c.content.length())return!1}return!0};a.prototype.type=function(){return"TableRow"};a.prototype.typeName=function(){return"Table row"};a.prototype._onMouseOver=function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.droppers={TableRow:f.Element._dropVert};a.fromDOMElement=function(b){var a;var d=new this(this.getDOMElementAttributes(b));var c=b.childNodes;b=[];var h=0;for(a=c.length;h<a;h++){var m=c[h];b.push(m)}a=0;for(c=b.length;a<c;a++)m=b[a],1===
m.nodeType&&(h=m.tagName.toLowerCase(),"td"!==h&&"th"!==h||d.attach(f.TableCell.fromDOMElement(m)));return d};return a}(f.ElementCollection);f.TableCell=function(c){function a(b,e){a.__super__.constructor.call(this,b,e)}t(a,c);a.prototype.cssTypeName=function(){return"table-cell"};a.prototype.tableCellText=function(){return 0<this.children.length?this.children[0]:null};a.prototype.type=function(){return"TableCell"};a.prototype.html=function(b){null==b&&(b="");var a=[""+b+"<"+this.tagName()+this._attributesToString()+
">"];this.tableCellText()&&a.push(this.tableCellText().html(b+f.INDENT));a.push(""+b+"</"+this.tagName()+">");return a.join(f.LINE_ENDINGS)};a.prototype._onMouseOver=function(b){a.__super__._onMouseOver.call(this,b);return this._removeCSSClass("ce-element--over")};a.prototype._addDOMEventListeners=function(){};a.prototype._removeDOMEventListners=function(){};a.fromDOMElement=function(b){var a=new this(b.tagName,this.getDOMElementAttributes(b));b=new f.TableCellText(b.innerHTML.replace(/^\s+|\s+$/g,
""));a.attach(b);return a};return a}(f.ElementCollection);f.TableCellText=function(c){function a(b){a.__super__.constructor.call(this,"div",{},b)}t(a,c);a.prototype.cssTypeName=function(){return"table-cell-text"};a.prototype.type=function(){return"TableCellText"};a.prototype._isInFirstRow=function(){var b=this.parent().parent();var a=b.parent();var d=a.parent();return a!==d.firstSection()?!1:b===a.children[0]};a.prototype._isInLastRow=function(){var b=this.parent().parent();var a=b.parent();var d=
a.parent();return a!==d.lastSection()?!1:b===a.children[a.children.length-1]};a.prototype._isLastInSection=function(){var b=this.parent();var a=b.parent();var d=a.parent();return a!==d.children[d.children.length-1]?!1:b===a.children[a.children.length-1]};a.prototype.blur=function(){this.isMounted()&&(this._domElement.blur(),this._domElement.removeAttribute("contenteditable"));return f.Element.prototype.blur.call(this)};a.prototype.can=function(b,a){if(a)throw Error("Cannot set behaviour for ListItemText");
return this.parent().can(b)};a.prototype.html=function(b){null==b&&(b="");if(!this._lastCached||this._lastCached<this._modified){var a=f.TRIM_WHITESPACE?this.content.copy().trim():this.content.copy();a.optimize();this._lastCached=Date.now();this._cached=a.html()}return""+b+this._cached};a.prototype._onMouseDown=function(b){f.Element.prototype._onMouseDown.call(this,b);var a=function(e){return function(){var d=e.parent();if(f.Root.get().dragging()===d.parent())return f.Root.get().cancelDragging(),
d=d.parent().parent().parent(),d.drag(b.pageX,b.pageY);d.parent().drag(b.pageX,b.pageY);return e._dragTimeout=setTimeout(a,2*f.DRAG_HOLD_DURATION)}}(this);clearTimeout(this._dragTimeout);return this._dragTimeout=setTimeout(a,f.DRAG_HOLD_DURATION)};a.prototype._keyBack=function(b){var a;var d=ContentSelect.Range.query(this._domElement);if(0===d.get()[0]&&d.isCollapsed()&&(b.preventDefault(),d=this.parent(),b=d.parent(),b.isEmpty()&&b.can("remove")&&0===this.content.length()&&0===b.children.indexOf(d))){if(a=
this.previousContent())a.focus(),d=new ContentSelect.Range(a.content.length(),a.content.length()),d.select(a.domElement());return b.parent().detach(b)}};a.prototype._keyDelete=function(b){var a=this.parent().parent();if(a.isEmpty()&&a.can("remove")){b.preventDefault();if(b=a.children[a.children.length-1].tableCellText().nextContent()){b.focus();var d=new ContentSelect.Range(0,0);d.select(b.domElement())}return a.parent().detach(a)}};a.prototype._keyDown=function(b){var a=ContentSelect.Range.query(this._domElement);
if(this._atEnd(a)&&a.isCollapsed()){b.preventDefault();a=this.parent();if(this._isInLastRow())return b=a.parent(),b=b.children[b.children.length-1].tableCellText(),(b=b.nextContent())?b.focus():f.Root.get().trigger("next-region",this.closest(function(b){return"Fixture"===b.type()||"Region"===b.type()}));b=a.parent().nextWithTest(function(b){return"TableRow"===b.type()});a=a.parent().children.indexOf(a);a=Math.min(a,b.children.length);return b.children[a].tableCellText().focus()}};a.prototype._keyReturn=
function(b){b.preventDefault();return this._keyTab({shiftKey:!1,preventDefault:function(){}})};a.prototype._keyTab=function(b){var a;b.preventDefault();var d=this.parent();if(b.shiftKey)return this._isInFirstRow()&&d.parent().children[0]===d?void 0:this.previousContent().focus();if(this.can("spawn")){b=d.parent().parent();if("tbody"===b.tagName()&&this._isLastInSection()){b=new f.TableRow;var c=d.parent().children;d=0;for(a=c.length;d<a;d++){var h=c[d];h=new f.TableCell(h.tagName(),h._attributes);
var m=new f.TableCellText("");h.attach(m);b.attach(h)}d=this.closest(function(b){return"TableSection"===b.type()});d.attach(b);return b.children[0].tableCellText().focus()}return this.nextContent().focus()}};a.prototype._keyUp=function(b){var a=ContentSelect.Range.query(this._domElement);if(0===a.get()[0]&&a.isCollapsed()){b.preventDefault();a=this.parent();if(this._isInFirstRow())return b=a.parent(),(b=b.children[0].previousContent())?b.focus():f.Root.get().trigger("previous-region",this.closest(function(b){return"Fixture"===
b.type()||"Region"===b.type()}));b=a.parent().previousWithTest(function(b){return"TableRow"===b.type()});a=a.parent().children.indexOf(a);a=Math.min(a,b.children.length);return b.children[a].tableCellText().focus()}};a.droppers={};a.mergers={};return a}(f.Text)}).call(this);
(function(){var x={}.hasOwnProperty,l=function(c,a){function b(){this.constructor=c}for(var e in a)x.call(a,e)&&(c[e]=a[e]);b.prototype=a.prototype;c.prototype=new b;c.__super__=a.prototype;return c},r=function(c,a){return function(){return c.apply(a,arguments)}},t=[].slice;var g={Tools:{},CANCEL_MESSAGE:"Your changes have not been saved, do you really want to lose them?",DEFAULT_TOOLS:["bold italic link align-left align-center align-right".split(" "),"heading subheading paragraph unordered-list ordered-list table indent unindent line-break".split(" "),
["image","video","preformatted"],["undo","redo","remove"]],DEFAULT_VIDEO_HEIGHT:300,DEFAULT_VIDEO_WIDTH:400,HIGHLIGHT_HOLD_DURATION:2E3,IMAGE_UPLOADER:null,INLINE_TAGS:"a address b code del em i ins span strong sup u".split(" "),INSPECTOR_IGNORED_ELEMENTS:["Fixture","ListItemText","Region","TableCellText"],MIN_CROP:10,RESTRICTED_ATTRIBUTES:{"*":["style"],img:["height","src","width","data-ce-max-width","data-ce-min-width"],iframe:["height","width"]},getEmbedVideoURL:function(c){var a,b,e;var d=document.createElement("a");
d.href=c;c=d.hostname.toLowerCase();var k=d.pathname;null!==k&&"/"!==k.substr(0,1)&&(k="/"+k);var h={};var f=d.search.slice(1).split("&");var g=0;for(e=f.length;g<e;g++)d=f[g],d=d.split("="),d[0]&&(h[d[0]]=d[1]);switch({"www.youtube.com":"youtube","youtu.be":"youtube","vimeo.com":"vimeo","player.vimeo.com":"vimeo"}[c]){case "youtube":if("/watch"===k.toLowerCase()){if(!h.v)break;c=h.v;delete h.v}else{c=k.match(/\/([A-Za-z0-9_-]+)$/i);if(!c)break;c=c[1]}c="https://www.youtube.com/embed/"+c;(k=function(){var e=
[];for(a in h)b=h[a],e.push(""+a+"="+b);return e}().join("&"))&&(c+="?"+k);return c;case "vimeo":if(c=k.match(/\/(\w+\/\w+\/){0,1}(\d+)/i))return c="https://player.vimeo.com/video/"+c[2],(k=function(){var e=[];for(a in h)b=h[a],e.push(""+a+"="+b);return e}().join("&"))&&(c+="?"+k),c}return null},getHTMLCleaner:function(){return new g.HTMLCleaner},getRestrictedAtributes:function(c){var a=[];g.RESTRICTED_ATTRIBUTES[c]&&(a=a.concat(g.RESTRICTED_ATTRIBUTES[c]));g.RESTRICTED_ATTRIBUTES["*"]&&(a=a.concat(g.RESTRICTED_ATTRIBUTES["*"]));
return a},getScrollPosition:function(){var c=void 0!==window.pageXOffset;var a=4===(document.compatMode||4);return c?[window.pageXOffset,window.pageYOffset]:a?[document.documentElement.scrollLeft,document.documentElement.scrollTop]:[document.body.scrollLeft,document.body.scrollTop]}};"undefined"!==typeof window&&(window.ContentTools=g);"undefined"!==typeof module&&module.exports&&(module.exports=g);g.ComponentUI=function(){function c(){this._bindings={};this._parent=null;this._children=[];this._domElement=
null}c.prototype.children=function(){return this._children.slice()};c.prototype.domElement=function(){return this._domElement};c.prototype.isMounted=function(){return null!==this._domElement};c.prototype.parent=function(){return this._parent};c.prototype.attach=function(a,b){a.parent()&&a.parent().detach(a);a._parent=this;return void 0!==b?this._children.splice(b,0,a):this._children.push(a)};c.prototype.addCSSClass=function(a){if(this.isMounted())return ContentEdit.addCSSClass(this._domElement,a)};
c.prototype.detach=function(a){a=this._children.indexOf(a);if(-1!==a)return this._children.splice(a,1)};c.prototype.mount=function(){};c.prototype.removeCSSClass=function(a){if(this.isMounted())return ContentEdit.removeCSSClass(this._domElement,a)};c.prototype.unmount=function(){if(this.isMounted())return this._removeDOMEventListeners(),this._domElement.parentNode&&this._domElement.parentNode.removeChild(this._domElement),this._domElement=null};c.prototype.addEventListener=function(a,b){void 0===
this._bindings[a]&&(this._bindings[a]=[]);this._bindings[a].push(b)};c.prototype.createEvent=function(a,b){return new g.Event(a,b)};c.prototype.dispatchEvent=function(a){var b;if(!this._bindings[a.name()])return!a.defaultPrevented();var e=this._bindings[a.name()];var d=0;for(b=e.length;d<b;d++){var c=e[d];if(a.propagationStopped())break;c&&c.call(this,a)}return!a.defaultPrevented()};c.prototype.removeEventListener=function(a,b){var e,d;if(!a)this._bindings={};else if(!b)this._bindings[a]=void 0;else if(this._bindings[a]){var c=
this._bindings[a];var h=[];var f=e=0;for(d=c.length;e<d;f=++e){var g=c[f];g===b?h.push(this._bindings[a].splice(f,1)):h.push(void 0)}return h}};c.prototype._addDOMEventListeners=function(){};c.prototype._removeDOMEventListeners=function(){};c.createDiv=function(a,b,e){var d;var c=document.createElement("div");a&&0<a.length&&c.setAttribute("class",a.join(" "));if(b)for(d in b)a=b[d],c.setAttribute(d,a);e&&(c.innerHTML=e);return c};return c}();g.WidgetUI=function(c){function a(){return a.__super__.constructor.apply(this,
arguments)}l(a,c);a.prototype.attach=function(b,e){a.__super__.attach.call(this,b,e);if(!this.isMounted())return b.mount()};a.prototype.detach=function(b){a.__super__.detach.call(this,b);if(this.isMounted())return b.unmount()};a.prototype.detatch=function(b){console.log("Please call detach, detatch will be removed in release 1.4.x");return this.detach(b)};a.prototype.show=function(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null,this.unmount());this.isMounted()||this.mount();
var b=function(b){return function(){b.addCSSClass("ct-widget--active");return b._showTimeout=null}}(this);return this._showTimeout=setTimeout(b,100)};a.prototype.hide=function(){this._showTimeout&&(clearTimeout(this._showTimeout),this._showTimeout=null);this.removeCSSClass("ct-widget--active");var b=function(a){return function(){a._hideTimeout=null;if(window.getComputedStyle)return.01>parseFloat(window.getComputedStyle(a._domElement).opacity)?a.unmount():a._hideTimeout=setTimeout(b,250);a.unmount()}}(this);
if(this.isMounted())return this._hideTimeout=setTimeout(b,250)};return a}(g.ComponentUI);g.AnchoredComponentUI=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);a.prototype.mount=function(b,a){null==a&&(a=null);b.insertBefore(this._domElement,a);return this._addDOMEventListeners()};return a}(g.ComponentUI);g.Event=function(){function c(a,b){this._name=a;this._detail=b;this._timeStamp=Date.now();this._propagationStopped=this._defaultPrevented=!1}c.prototype.defaultPrevented=
function(){return this._defaultPrevented};c.prototype.detail=function(){return this._detail};c.prototype.name=function(){return this._name};c.prototype.propagationStopped=function(){return this._propagationStopped};c.prototype.timeStamp=function(){return this._timeStamp};c.prototype.preventDefault=function(){return this._defaultPrevented=!0};c.prototype.stopImmediatePropagation=function(){return this._propagationStopped=!0};return c}();g.FlashUI=function(c){function a(b){a.__super__.constructor.call(this);
this.mount(b)}l(a,c);a.prototype.mount=function(b){this._domElement=this.constructor.createDiv(["ct-flash","ct-flash--active","ct-flash--"+b,"ct-widget","ct-widget--active"]);a.__super__.mount.call(this,g.EditorApp.get().domElement());var e=function(b){return function(){if(window.getComputedStyle)return.01>parseFloat(window.getComputedStyle(b._domElement).opacity)?b.unmount():setTimeout(e,250);b.unmount()}}(this);return setTimeout(e,250)};return a}(g.AnchoredComponentUI);g.IgnitionUI=function(c){function a(){a.__super__.constructor.call(this);
this._state=this._revertToState="ready"}l(a,c);a.prototype.busy=function(b){if(this.dispatchEvent(this.createEvent("busy",{busy:b}))&&b!==("busy"===this._state))return b?(this._revertToState=this._state,this.state("busy")):this.state(this._revertToState)};a.prototype.cancel=function(){if(this.dispatchEvent(this.createEvent("cancel")))return this.state("ready")};a.prototype.confirm=function(){if(this.dispatchEvent(this.createEvent("confirm")))return this.state("ready")};a.prototype.edit=function(){if(this.dispatchEvent(this.createEvent("edit")))return this.state("editing")};
a.prototype.mount=function(){a.__super__.mount.call(this);this._domElement=this.constructor.createDiv(["ct-widget","ct-ignition","ct-ignition--ready"]);this.parent().domElement().appendChild(this._domElement);this._domEdit=this.constructor.createDiv(["ct-ignition__button","ct-ignition__button--edit"]);this._domElement.appendChild(this._domEdit);this._domConfirm=this.constructor.createDiv(["ct-ignition__button","ct-ignition__button--confirm"]);this._domElement.appendChild(this._domConfirm);this._domCancel=
this.constructor.createDiv(["ct-ignition__button","ct-ignition__button--cancel"]);this._domElement.appendChild(this._domCancel);this._domBusy=this.constructor.createDiv(["ct-ignition__button","ct-ignition__button--busy"]);this._domElement.appendChild(this._domBusy);return this._addDOMEventListeners()};a.prototype.state=function(b){if(void 0===b)return this._state;if(this._state!==b&&this.dispatchEvent(this.createEvent("statechange",{state:b}))){this._state=b;this.removeCSSClass("ct-ignition--busy");
this.removeCSSClass("ct-ignition--editing");this.removeCSSClass("ct-ignition--ready");if("busy"===this._state)return this.addCSSClass("ct-ignition--busy");if("editing"===this._state)return this.addCSSClass("ct-ignition--editing");if("ready"===this._state)return this.addCSSClass("ct-ignition--ready")}};a.prototype.unmount=function(){a.__super__.unmount.call(this);return this._domCancel=this._domConfirm=this._domEdit=null};a.prototype._addDOMEventListeners=function(){this._domEdit.addEventListener("click",
function(b){return function(a){a.preventDefault();return b.edit()}}(this));this._domConfirm.addEventListener("click",function(b){return function(a){a.preventDefault();return b.confirm()}}(this));return this._domCancel.addEventListener("click",function(b){return function(a){a.preventDefault();return b.cancel()}}(this))};return a}(g.WidgetUI);g.InspectorUI=function(c){function a(){a.__super__.constructor.call(this);this._tagUIs=[]}l(a,c);a.prototype.mount=function(){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(b){return function(){return b.updateTags()}}(this);ContentEdit.Root.get().bind("blur",this._handleFocusChange);
ContentEdit.Root.get().bind("focus",this._handleFocusChange);return ContentEdit.Root.get().bind("mount",this._handleFocusChange)};a.prototype.unmount=function(){a.__super__.unmount.call(this);this._domTags=null;ContentEdit.Root.get().unbind("blur",this._handleFocusChange);ContentEdit.Root.get().unbind("focus",this._handleFocusChange);return ContentEdit.Root.get().unbind("mount",this._handleFocusChange)};a.prototype.updateCounter=function(){var b,a;if(this.isMounted()){var d="";var c=g.EditorApp.get().orderedRegions();
var h=0;for(a=c.length;h<a;h++)(b=c[h])&&(d+=b.domElement().textContent);d=d.trim();d=d.replace(/<\/?[a-z][^>]*>/gi,"");d=d.replace(/[\u200B]+/,"");d=d.replace(/['";:,.?\u00bf\-!\u00a1]+/g,"");d=(d.match(/\S+/g)||[]).length;d=d.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");if((b=ContentEdit.Root.get().focused())&&"PreText"===b.type()&&b.selection().isCollapsed())return h=b.content.substring(0,b.selection().get()[0]).text().split("\n"),b=h.length,h=h[h.length-1].length+1,b=b.toString().replace(/\B(?=(\d{3})+(?!\d))/g,
","),h=h.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),this._domCounter.textContent=""+d+" / "+b+":"+h;this._domCounter.textContent=d}};a.prototype.updateTags=function(){var b;var a=ContentEdit.Root.get().focused();var d=this._tagUIs;var c=0;for(b=d.length;c<b;c++){var h=d[c];h.unmount()}this._tagUIs=[];if(a){c=a.parents();c.reverse();c.push(a);var f=[];b=0;for(d=c.length;b<d;b++)a=c[b],-1===g.INSPECTOR_IGNORED_ELEMENTS.indexOf(a.type())&&(h=new g.TagUI(a),this._tagUIs.push(h),f.push(h.mount(this._domTags)));
return f}};a.prototype._addDOMEventListeners=function(){return this._updateCounterInterval=setInterval(function(b){return function(){return b.updateCounter()}}(this),250)};a.prototype._removeDOMEventListeners=function(){return clearInterval(this._updateCounterInterval)};return a}(g.WidgetUI);g.TagUI=function(c){function a(b){this.element=b;this._onMouseDown=r(this._onMouseDown,this);a.__super__.constructor.call(this)}l(a,c);a.prototype.mount=function(b,e){null==e&&(e=null);this._domElement=this.constructor.createDiv(["ct-tag"]);
this._domElement.textContent=this.element.tagName();return a.__super__.mount.call(this,b,e)};a.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("mousedown",this._onMouseDown)};a.prototype._onMouseDown=function(b){b.preventDefault();this.element.storeState&&this.element.storeState();b=g.EditorApp.get();var a=new g.ModalUI;var d=new g.PropertiesDialog(this.element);d.addEventListener("cancel",function(b){return function(){a.hide();d.hide();if(b.element.restoreState)return b.element.restoreState()}}(this));
d.addEventListener("save",function(b){return function(e){var c,k;e=e.detail();var h=e.changedAttributes;var f=e.changedStyles;e=e.innerHTML;for(c in h){var g=h[c];if("class"===c){null===g&&(g="");var l={};var t=g.split(" ");var w=0;for(k=t.length;w<k;w++)if(g=t[w],g=g.trim())l[g]=!0,b.element.hasCSSClass(g)||b.element.addCSSClass(g);t=b.element.attr("class").split(" ");w=0;for(k=t.length;w<k;w++)g=t[w],g=g.trim(),void 0===l[g]&&b.element.removeCSSClass(g)}else null===g?b.element.removeAttr(c):b.element.attr(c,
g)}for(r in f)(c=f[r])?b.element.addCSSClass(r):b.element.removeCSSClass(r);if(null!==e&&e!==d.getElementInnerHTML()){var r=b.element;r.content||(r=r.children[0]);r.content=new HTMLString.String(e,r.content.preserveWhitespace());r.updateInnerHTML();r.taint();r.selection(new ContentSelect.Range(0,0));r.storeState()}a.hide();d.hide();if(b.element.restoreState)return b.element.restoreState()}}(this));b.attach(a);b.attach(d);a.show();return d.show()};return a}(g.AnchoredComponentUI);g.ModalUI=function(c){function a(b,
e){a.__super__.constructor.call(this);this._transparent=b;this._allowScrolling=e}l(a,c);a.prototype.mount=function(){this._domElement=this.constructor.createDiv(["ct-widget","ct-modal"]);this.parent().domElement().appendChild(this._domElement);this._transparent&&this.addCSSClass("ct-modal--transparent");this._allowScrolling||ContentEdit.addCSSClass(document.body,"ct--no-scroll");return this._addDOMEventListeners()};a.prototype.unmount=function(){this._allowScrolling||ContentEdit.removeCSSClass(document.body,
"ct--no-scroll");return a.__super__.unmount.call(this)};a.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("click",function(b){return function(a){return b.dispatchEvent(b.createEvent("click"))}}(this))};return a}(g.WidgetUI);g.ToolboxUI=function(c){function a(b){this._onStopDragging=r(this._onStopDragging,this);this._onStartDragging=r(this._onStartDragging,this);this._onDrag=r(this._onDrag,this);a.__super__.constructor.call(this);this._tools=b;this._dragging=!1;
this._domGrip=this._draggingOffset=null;this._toolUIs={}}l(a,c);a.prototype.isDragging=function(){return this._dragging};a.prototype.hide=function(){this._removeDOMEventListeners();return a.__super__.hide.call(this)};a.prototype.mount=function(){var b;this._domElement=this.constructor.createDiv(["ct-widget","ct-toolbox"]);this.parent().domElement().appendChild(this._domElement);this._domGrip=this.constructor.createDiv(["ct-toolbox__grip","ct-grip"]);this._domElement.appendChild(this._domGrip);this._domGrip.appendChild(this.constructor.createDiv(["ct-grip__bump"]));
this._domGrip.appendChild(this.constructor.createDiv(["ct-grip__bump"]));this._domGrip.appendChild(this.constructor.createDiv(["ct-grip__bump"]));this._domToolGroups=this.constructor.createDiv(["ct-tool-groups"]);this._domElement.appendChild(this._domToolGroups);this.tools(this._tools);if((b=window.localStorage.getItem("ct-toolbox-position"))&&/^\d+,\d+$/.test(b)){var a;var d=b.split(",");var c=[];var h=0;for(a=d.length;h<a;h++)b=d[h],c.push(parseInt(b));this._domElement.style.left=""+c[0]+"px";this._domElement.style.top=
""+c[1]+"px";this._contain()}return this._addDOMEventListeners()};a.prototype.tools=function(b){var a,d,c;if(void 0===b)return this._tools;this._tools=b;if(this.isMounted()){var h=this._toolUIs;for(d in h)b=h[d],b.unmount();for(this._toolUIs={};this._domToolGroups.lastChild;)this._domToolGroups.removeChild(this._domToolGroups.lastChild);var f=this._tools;var u=[];b=h=0;for(c=f.length;h<c;b=++h){var v=f[b];var n=this.constructor.createDiv(["ct-tool-group"]);this._domToolGroups.appendChild(n);u.push(function(){var b;
var e=[];var c=0;for(b=v.length;c<b;c++)d=v[c],a=g.ToolShelf.fetch(d),this._toolUIs[d]=new g.ToolUI(a),this._toolUIs[d].mount(n),this._toolUIs[d].disabled(!0),e.push(this._toolUIs[d].addEventListener("applied",function(b){return function(){return b.updateTools()}}(this)));return e}.call(this))}return u}};a.prototype.updateTools=function(){var b;var a=ContentEdit.Root.get().focused();var d=null;a&&a.selection&&(d=a.selection());var c=this._toolUIs;var h=[];for(b in c){var f=c[b];h.push(f.update(a,
d))}return h};a.prototype.unmount=function(){a.__super__.unmount.call(this);return this._domGrip=null};a.prototype._addDOMEventListeners=function(){this._domGrip.addEventListener("mousedown",this._onStartDragging);this._handleResize=function(b){return function(a){b._resizeTimeout&&clearTimeout(b._resizeTimeout);return b._resizeTimeout=setTimeout(function(){return b._contain()},250)}}(this);window.addEventListener("resize",this._handleResize);this._updateTools=function(b){return function(){var a;var d=
g.EditorApp.get();var c=!1;var h=ContentEdit.Root.get().focused();var f=null;h===b._lastUpdateElement?h&&h.selection&&(f=h.selection(),b._lastUpdateSelection?f.eq(b._lastUpdateSelection)||(c=!0):c=!0):c=!0;d.history&&(b._lastUpdateHistoryLength!==d.history.length()&&(c=!0),b._lastUpdateHistoryLength=d.history.length(),b._lastUpdateHistoryIndex!==d.history.index()&&(c=!0),b._lastUpdateHistoryIndex=d.history.index());b._lastUpdateElement=h;b._lastUpdateSelection=f;if(c){c=b._toolUIs;var u=[];for(a in c)d=
c[a],u.push(d.update(h,f));return u}}}(this);this._updateToolsInterval=setInterval(this._updateTools,100);this._handleKeyDown=function(b){return function(b){var a;if((a=ContentEdit.Root.get().focused())&&!a.content){if(46===b.keyCode)return b.preventDefault(),g.Tools.Remove.apply(a,null,function(){});if(13===b.keyCode)return b.preventDefault(),b=g.Tools.Paragraph,b.apply(a,null,function(){})}var e=navigator.appVersion;a="linux";-1!==e.indexOf("Mac")?a="mac":-1!==e.indexOf("Win")&&(a="windows");var c=
e=!1;switch(a){case "linux":!b.altKey&&90===b.keyCode&&b.ctrlKey&&(e=b.shiftKey,c=!e);break;case "mac":b.altKey||b.ctrlKey||90!==b.keyCode||!b.metaKey||(e=b.shiftKey,c=!e);break;case "windows":if(!b.altKey||b.shiftKey)89===b.keyCode&&b.ctrlKey&&(e=!0),90===b.keyCode&&b.ctrlKey&&(c=!0)}c&&g.Tools.Undo.canApply(null,null)&&g.Tools.Undo.apply(null,null,function(){});if(e&&g.Tools.Redo.canApply(null,null))return g.Tools.Redo.apply(null,null,function(){})}}(this);return window.addEventListener("keydown",
this._handleKeyDown)};a.prototype._contain=function(){if(this.isMounted()){var b=this._domElement.getBoundingClientRect();b.left+b.width>window.innerWidth&&(this._domElement.style.left=""+(window.innerWidth-b.width)+"px");b.top+b.height>window.innerHeight&&(this._domElement.style.top=""+(window.innerHeight-b.height)+"px");0>b.left&&(this._domElement.style.left="0px");0>b.top&&(this._domElement.style.top="0px");b=this._domElement.getBoundingClientRect();return window.localStorage.setItem("ct-toolbox-position",
""+b.left+","+b.top)}};a.prototype._removeDOMEventListeners=function(){this.isMounted()&&this._domGrip.removeEventListener("mousedown",this._onStartDragging);window.removeEventListener("keydown",this._handleKeyDown);window.removeEventListener("resize",this._handleResize);return clearInterval(this._updateToolsInterval)};a.prototype._onDrag=function(b){ContentSelect.Range.unselectAll();this._domElement.style.left=""+(b.clientX-this._draggingOffset.x)+"px";return this._domElement.style.top=""+(b.clientY-
this._draggingOffset.y)+"px"};a.prototype._onStartDragging=function(b){b.preventDefault();if(!this.isDragging()){this._dragging=!0;this.addCSSClass("ct-toolbox--dragging");var a=this._domElement.getBoundingClientRect();this._draggingOffset={x:b.clientX-a.left,y:b.clientY-a.top};document.addEventListener("mousemove",this._onDrag);document.addEventListener("mouseup",this._onStopDragging);return ContentEdit.addCSSClass(document.body,"ce--dragging")}};a.prototype._onStopDragging=function(b){if(this.isDragging())return this._contain(),
document.removeEventListener("mousemove",this._onDrag),document.removeEventListener("mouseup",this._onStopDragging),this._draggingOffset=null,this._dragging=!1,this.removeCSSClass("ct-toolbox--dragging"),ContentEdit.removeCSSClass(document.body,"ce--dragging")};return a}(g.WidgetUI);g.ToolUI=function(c){function a(b){this._onMouseUp=r(this._onMouseUp,this);this._onMouseLeave=r(this._onMouseLeave,this);this._onMouseDown=r(this._onMouseDown,this);this._addDOMEventListeners=r(this._addDOMEventListeners,
this);a.__super__.constructor.call(this);this.tool=b;this._disabled=this._mouseDown=!1}l(a,c);a.prototype.apply=function(b,a){if(this.tool.canApply(b,a)){var e={element:b,selection:a};var c=function(b){return function(a){if(a)return b.dispatchEvent(b.createEvent("applied",e))}}(this);if(this.dispatchEvent(this.createEvent("apply",e)))return this.tool.apply(b,a,c)}};a.prototype.disabled=function(b){if(void 0===b)return this._disabled;if(this._disabled!==b)return(this._disabled=b)?(this._mouseDown=
!1,this.addCSSClass("ct-tool--disabled"),this.removeCSSClass("ct-tool--applied")):this.removeCSSClass("ct-tool--disabled")};a.prototype.mount=function(b,e){null==e&&(e=null);this._domElement=this.constructor.createDiv(["ct-tool","ct-tool--"+this.tool.icon]);this._domElement.setAttribute("data-ct-tooltip",ContentEdit._(this.tool.label));return a.__super__.mount.call(this,b,e)};a.prototype.update=function(b,a){if((!this.tool.requiresElement||b&&b.isMounted())&&this.tool.canApply(b,a))return this.disabled(!1),
this.tool.isApplied(b,a)?this.addCSSClass("ct-tool--applied"):this.removeCSSClass("ct-tool--applied");this.disabled(!0)};a.prototype._addDOMEventListeners=function(){this._domElement.addEventListener("mousedown",this._onMouseDown);this._domElement.addEventListener("mouseleave",this._onMouseLeave);return this._domElement.addEventListener("mouseup",this._onMouseUp)};a.prototype._onMouseDown=function(b){b.preventDefault();if(!this.disabled())return this._mouseDown=!0,this.addCSSClass("ct-tool--down")};
a.prototype._onMouseLeave=function(b){this._mouseDown=!1;return this.removeCSSClass("ct-tool--down")};a.prototype._onMouseUp=function(b){if(this._mouseDown){b=ContentEdit.Root.get().focused();if(this.tool.requiresElement&&(!b||!b.isMounted()))return;var a=null;b&&b.selection&&(a=b.selection());this.apply(b,a)}this._mouseDown=!1;return this.removeCSSClass("ct-tool--down")};return a}(g.AnchoredComponentUI);g.AnchoredDialogUI=function(c){function a(){a.__super__.constructor.call(this);this._position=
[0,0]}l(a,c);a.prototype.mount=function(){this._domElement=this.constructor.createDiv(["ct-widget","ct-anchored-dialog"]);this.parent().domElement().appendChild(this._domElement);this._contain();this._domElement.style.top=""+this._position[1]+"px";return this._domElement.style.left=""+this._position[0]+"px"};a.prototype.position=function(b){if(void 0===b)return this._position.slice();this._position=b.slice();if(this.isMounted())return this._contain(),this._domElement.style.top=""+this._position[1]+
"px",this._domElement.style.left=""+this._position[0]+"px"};a.prototype._contain=function(){if(this.isMounted()){var b=this._domElement.getBoundingClientRect();var a=b.width/2+5;var d=document.documentElement.clientWidth||document.body.clientWidth;this._position[0]+a>d&&(this._position[0]=d-a);this._position[0]<a&&(this._position[0]=a);if(5>this._position[1]+b.top)return this._position[1]=Math.abs(b.top)+5}};return a}(g.WidgetUI);g.DialogUI=function(c){function a(b){null==b&&(b="");a.__super__.constructor.call(this);
this._busy=!1;this._caption=b}l(a,c);a.prototype.busy=function(b){if(void 0===b)return this._busy;if(this._busy!==b&&(this._busy=b,this.isMounted()))return this._busy?ContentEdit.addCSSClass(this._domElement,"ct-dialog--busy"):ContentEdit.removeCSSClass(this._domElement,"ct-dialog--busy")};a.prototype.caption=function(b){if(void 0===b)return this._caption;this._caption=b;return this._domCaption.textContent=ContentEdit._(b)};a.prototype.mount=function(){document.activeElement&&(document.activeElement.blur(),
window.getSelection().removeAllRanges());var b=["ct-widget","ct-dialog"];this._busy&&b.push("ct-dialog--busy");this._domElement=this.constructor.createDiv(b);this.parent().domElement().appendChild(this._domElement);b=this.constructor.createDiv(["ct-dialog__header"]);this._domElement.appendChild(b);this._domCaption=this.constructor.createDiv(["ct-dialog__caption"]);b.appendChild(this._domCaption);this.caption(this._caption);this._domClose=this.constructor.createDiv(["ct-dialog__close"]);b.appendChild(this._domClose);
b=this.constructor.createDiv(["ct-dialog__body"]);this._domElement.appendChild(b);this._domView=this.constructor.createDiv(["ct-dialog__view"]);b.appendChild(this._domView);this._domControls=this.constructor.createDiv(["ct-dialog__controls"]);b.appendChild(this._domControls);this._domBusy=this.constructor.createDiv(["ct-dialog__busy"]);return this._domElement.appendChild(this._domBusy)};a.prototype.unmount=function(){a.__super__.unmount.call(this);return this._domView=this._domControls=this._domClose=
this._domCaption=this._domBusy=null};a.prototype._addDOMEventListeners=function(){this._handleEscape=function(b){return function(a){if(!b._busy&&27===a.keyCode)return b.dispatchEvent(b.createEvent("cancel"))}}(this);document.addEventListener("keyup",this._handleEscape);return this._domClose.addEventListener("click",function(b){return function(a){a.preventDefault();if(!b._busy)return b.dispatchEvent(b.createEvent("cancel"))}}(this))};a.prototype._removeDOMEventListeners=function(){return document.removeEventListener("keyup",
this._handleEscape)};return a}(g.WidgetUI);g.ImageDialog=function(c){function a(){a.__super__.constructor.call(this,"Insert image");this._imageSize=this._imageURL=this._cropMarks=null;this._progress=0;this._state="empty";g.IMAGE_UPLOADER&&g.IMAGE_UPLOADER(this)}l(a,c);a.prototype.cropRegion=function(){return this._cropMarks?this._cropMarks.region():[0,0,1,1]};a.prototype.addCropMarks=function(){if(!this._cropMarks)return this._cropMarks=new f(this._imageSize),this._cropMarks.mount(this._domView),
ContentEdit.addCSSClass(this._domCrop,"ct-control--active")};a.prototype.clear=function(){this._domImage&&(this._domImage.parentNode.removeChild(this._domImage),this._domImage=null);this._imageSize=this._imageURL=null;return this.state("empty")};a.prototype.mount=function(){a.__super__.mount.call(this);ContentEdit.addCSSClass(this._domElement,"ct-image-dialog");ContentEdit.addCSSClass(this._domElement,"ct-image-dialog--empty");ContentEdit.addCSSClass(this._domView,"ct-image-dialog__view");var b=this.constructor.createDiv(["ct-control-group",
"ct-control-group--left"]);this._domControls.appendChild(b);this._domRotateCCW=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--rotate-ccw"]);this._domRotateCCW.setAttribute("data-ct-tooltip",ContentEdit._("Rotate")+" -90\u00b0");b.appendChild(this._domRotateCCW);this._domRotateCW=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--rotate-cw"]);this._domRotateCW.setAttribute("data-ct-tooltip",ContentEdit._("Rotate")+" 90\u00b0");b.appendChild(this._domRotateCW);
this._domCrop=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--crop"]);this._domCrop.setAttribute("data-ct-tooltip",ContentEdit._("Crop marks"));b.appendChild(this._domCrop);var e=this.constructor.createDiv(["ct-progress-bar"]);b.appendChild(e);this._domProgress=this.constructor.createDiv(["ct-progress-bar__progress"]);e.appendChild(this._domProgress);e=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]);this._domControls.appendChild(e);this._domUpload=
this.constructor.createDiv(["ct-control","ct-control--text","ct-control--upload"]);this._domUpload.textContent=ContentEdit._("Upload");e.appendChild(this._domUpload);this._domInput=document.createElement("input");this._domInput.setAttribute("class","ct-image-dialog__file-upload");this._domInput.setAttribute("name","file");this._domInput.setAttribute("type","file");this._domInput.setAttribute("accept","image/*");this._domUpload.appendChild(this._domInput);this._domInsert=this.constructor.createDiv(["ct-control",
"ct-control--text","ct-control--insert"]);this._domInsert.textContent=ContentEdit._("Insert");e.appendChild(this._domInsert);this._domCancelUpload=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--cancel"]);this._domCancelUpload.textContent=ContentEdit._("Cancel");e.appendChild(this._domCancelUpload);this._domClear=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--clear"]);this._domClear.textContent=ContentEdit._("Clear");e.appendChild(this._domClear);
this._addDOMEventListeners();return this.dispatchEvent(this.createEvent("imageuploader.mount"))};a.prototype.populate=function(b,a){this._imageURL=b;this._imageSize=a;this._domImage||(this._domImage=this.constructor.createDiv(["ct-image-dialog__image"]),this._domView.appendChild(this._domImage));this._domImage.style["background-image"]="url("+b+")";return this.state("populated")};a.prototype.progress=function(b){if(void 0===b)return this._progress;this._progress=b;if(this.isMounted())return this._domProgress.style.width=
""+this._progress+"%"};a.prototype.removeCropMarks=function(){if(this._cropMarks)return this._cropMarks.unmount(),this._cropMarks=null,ContentEdit.removeCSSClass(this._domCrop,"ct-control--active")};a.prototype.save=function(b,a,d){return this.dispatchEvent(this.createEvent("save",{imageURL:b,imageSize:a,imageAttrs:d}))};a.prototype.state=function(b){if(void 0===b)return this._state;if(this._state!==b){var a=this._state;this._state=b;if(this.isMounted())return ContentEdit.addCSSClass(this._domElement,
"ct-image-dialog--"+this._state),ContentEdit.removeCSSClass(this._domElement,"ct-image-dialog--"+a)}};a.prototype.unmount=function(){a.__super__.unmount.call(this);this._domUpload=this._domRotateCW=this._domRotateCCW=this._domProgress=this._domInsert=this._domInput=this._domCrop=this._domClear=this._domCancelUpload=null;return this.dispatchEvent(this.createEvent("imageuploader.unmount"))};a.prototype._addDOMEventListeners=function(){a.__super__._addDOMEventListeners.call(this);this._domInput.addEventListener("change",
function(b){return function(a){var d;if(d=a.target.files[0])return a.target.value="",a.target.value&&(a.target.type="text",a.target.type="file"),b.dispatchEvent(b.createEvent("imageuploader.fileready",{file:d}))}}(this));this._domCancelUpload.addEventListener("click",function(b){return function(a){return b.dispatchEvent(b.createEvent("imageuploader.cancelupload"))}}(this));this._domClear.addEventListener("click",function(b){return function(a){b.removeCropMarks();return b.dispatchEvent(b.createEvent("imageuploader.clear"))}}(this));
this._domRotateCCW.addEventListener("click",function(b){return function(a){b.removeCropMarks();return b.dispatchEvent(b.createEvent("imageuploader.rotateccw"))}}(this));this._domRotateCW.addEventListener("click",function(b){return function(a){b.removeCropMarks();return b.dispatchEvent(b.createEvent("imageuploader.rotatecw"))}}(this));this._domCrop.addEventListener("click",function(b){return function(a){return b._cropMarks?b.removeCropMarks():b.addCropMarks()}}(this));return this._domInsert.addEventListener("click",
function(b){return function(a){return b.dispatchEvent(b.createEvent("imageuploader.save"))}}(this))};return a}(g.DialogUI);var f=function(c){function a(b){a.__super__.constructor.call(this);this._draggingOrigin=this._dragging=this._bounds=null;this._imageSize=b}l(a,c);a.prototype.mount=function(b,e){null==e&&(e=null);this._domElement=this.constructor.createDiv(["ct-crop-marks"]);this._domClipper=this.constructor.createDiv(["ct-crop-marks__clipper"]);this._domElement.appendChild(this._domClipper);
this._domRulers=[this.constructor.createDiv(["ct-crop-marks__ruler","ct-crop-marks__ruler--top-left"]),this.constructor.createDiv(["ct-crop-marks__ruler","ct-crop-marks__ruler--bottom-right"])];this._domClipper.appendChild(this._domRulers[0]);this._domClipper.appendChild(this._domRulers[1]);this._domHandles=[this.constructor.createDiv(["ct-crop-marks__handle","ct-crop-marks__handle--top-left"]),this.constructor.createDiv(["ct-crop-marks__handle","ct-crop-marks__handle--bottom-right"])];this._domElement.appendChild(this._domHandles[0]);
this._domElement.appendChild(this._domHandles[1]);a.__super__.mount.call(this,b,e);return this._fit(b)};a.prototype.region=function(){return[parseFloat(this._domHandles[0].style.top)/this._bounds[1],parseFloat(this._domHandles[0].style.left)/this._bounds[0],parseFloat(this._domHandles[1].style.top)/this._bounds[1],parseFloat(this._domHandles[1].style.left)/this._bounds[0]]};a.prototype.unmount=function(){a.__super__.unmount.call(this);return this._domRulers=this._domHandles=this._domClipper=null};
a.prototype._addDOMEventListeners=function(){a.__super__._addDOMEventListeners.call(this);this._domHandles[0].addEventListener("mousedown",function(b){return function(a){if(0===a.button)return b._startDrag(0,a.clientY,a.clientX)}}(this));return this._domHandles[1].addEventListener("mousedown",function(b){return function(a){if(0===a.button)return b._startDrag(1,a.clientY,a.clientX)}}(this))};a.prototype._drag=function(b,a){if(null!==this._dragging){ContentSelect.Range.unselectAll();var d=b-this._draggingOrigin[1];
var e=a-this._draggingOrigin[0];var c=this._bounds[1];b=a=0;var f=this._bounds[0];var u=Math.min(Math.min(g.MIN_CROP,c),f);0===this._dragging?(c=parseInt(this._domHandles[1].style.top)-u,f=parseInt(this._domHandles[1].style.left)-u):(a=parseInt(this._domHandles[0].style.left)+u,b=parseInt(this._domHandles[0].style.top)+u);d=Math.min(Math.max(b,d),c);e=Math.min(Math.max(a,e),f);this._domHandles[this._dragging].style.top=""+d+"px";this._domHandles[this._dragging].style.left=""+e+"px";this._domRulers[this._dragging].style.top=
""+d+"px";return this._domRulers[this._dragging].style.left=""+e+"px"}};a.prototype._fit=function(b){var a=b.getBoundingClientRect();var d=Math.min(a.width/this._imageSize[0],a.height/this._imageSize[1]);b=d*this._imageSize[0];d*=this._imageSize[1];var c=(a.width-b)/2;a=(a.height-d)/2;this._domElement.style.width=""+b+"px";this._domElement.style.height=""+d+"px";this._domElement.style.top=""+a+"px";this._domElement.style.left=""+c+"px";this._domHandles[0].style.top="0px";this._domHandles[0].style.left=
"0px";this._domHandles[1].style.top=""+d+"px";this._domHandles[1].style.left=""+b+"px";this._domRulers[0].style.top="0px";this._domRulers[0].style.left="0px";this._domRulers[1].style.top=""+d+"px";this._domRulers[1].style.left=""+b+"px";return this._bounds=[b,d]};a.prototype._startDrag=function(b,a,d){var e=this._domHandles[b];this._dragging=b;this._draggingOrigin=[d-parseInt(e.style.left),a-parseInt(e.style.top)];this._onMouseMove=function(b){return function(a){return b._drag(a.clientY,a.clientX)}}(this);
document.addEventListener("mousemove",this._onMouseMove);this._onMouseUp=function(b){return function(a){return b._stopDrag()}}(this);return document.addEventListener("mouseup",this._onMouseUp)};a.prototype._stopDrag=function(){document.removeEventListener("mousemove",this._onMouseMove);document.removeEventListener("mouseup",this._onMouseUp);return this._draggingOrigin=this._dragging=null};return a}(g.AnchoredComponentUI);g.LinkDialog=function(c){function a(b,e){null==b&&(b="");null==e&&(e="");a.__super__.constructor.call(this);
this._href=b;this._target=e}l(a,c);a.prototype.mount=function(){a.__super__.mount.call(this);this._domInput=document.createElement("input");this._domInput.setAttribute("class","ct-anchored-dialog__input");this._domInput.setAttribute("name","href");this._domInput.setAttribute("placeholder",ContentEdit._("Enter a link")+"...");this._domInput.setAttribute("type","text");this._domInput.setAttribute("value",this._href);this._domElement.appendChild(this._domInput);this._domTargetButton=this.constructor.createDiv(["ct-anchored-dialog__target-button"]);
this._domElement.appendChild(this._domTargetButton);"_blank"===this._target&&ContentEdit.addCSSClass(this._domTargetButton,"ct-anchored-dialog__target-button--active");this._domButton=this.constructor.createDiv(["ct-anchored-dialog__button"]);this._domElement.appendChild(this._domButton);return this._addDOMEventListeners()};a.prototype.save=function(){if(this.isMounted()){var b={href:this._domInput.value.trim()};this._target&&(b.target=this._target);return this.dispatchEvent(this.createEvent("save",
b))}this.dispatchEvent(this.createEvent("save"))};a.prototype.show=function(){a.__super__.show.call(this);this._domInput.focus();if(this._href)return this._domInput.select()};a.prototype.unmount=function(){this.isMounted()&&this._domInput.blur();a.__super__.unmount.call(this);return this._domInput=this._domButton=null};a.prototype._addDOMEventListeners=function(){this._domInput.addEventListener("keypress",function(b){return function(a){if(13===a.keyCode)return b.save()}}(this));this._domTargetButton.addEventListener("click",
function(b){return function(a){a.preventDefault();if("_blank"===b._target)return b._target="",ContentEdit.removeCSSClass(b._domTargetButton,"ct-anchored-dialog__target-button--active");b._target="_blank";return ContentEdit.addCSSClass(b._domTargetButton,"ct-anchored-dialog__target-button--active")}}(this));return this._domButton.addEventListener("click",function(b){return function(a){a.preventDefault();return b.save()}}(this))};return a}(g.AnchoredDialogUI);g.PropertiesDialog=function(c){function a(b){var e;
this.element=b;a.__super__.constructor.call(this,"Properties");this._attributeUIs=[];this._focusedAttributeUI=null;this._styleUIs=[];this._supportsCoding=this.element.content;if("ListItem"===(e=this.element.type())||"TableCell"===e)this._supportsCoding=!0}l(a,c);a.prototype.caption=function(b){if(void 0===b)return this._caption;this._caption=b;return this._domCaption.textContent=ContentEdit._(b)+(": "+this.element.tagName())};a.prototype.changedAttributes=function(){var b;var a={};var d={};var c=
this._attributeUIs;var h=0;for(b=c.length;h<b;h++){var f=c[h];var u=f.name();f=f.value();""!==u&&(a[u.toLowerCase()]=!0,this.element.attr(u)!==f&&(d[u]=f))}h=g.getRestrictedAtributes(this.element.tagName());b=this.element.attributes();for(u in b)h&&-1!==h.indexOf(u.toLowerCase())||void 0===a[u]&&(d[u]=null);return d};a.prototype.changedStyles=function(){var b;var a={};var d=this._styleUIs;var c=0;for(b=d.length;c<b;c++){var h=d[c];var f=h.style.cssClass();this.element.hasCSSClass(f)!==h.applied()&&
(a[f]=h.applied())}return a};a.prototype.getElementInnerHTML=function(){return this._supportsCoding?this.element.content?this.element.content.html():this.element.children[0].content.html():null};a.prototype.mount=function(){var b,e;a.__super__.mount.call(this);ContentEdit.addCSSClass(this._domElement,"ct-properties-dialog");ContentEdit.addCSSClass(this._domView,"ct-properties-dialog__view");this._domStyles=this.constructor.createDiv(["ct-properties-dialog__styles"]);this._domStyles.setAttribute("data-ct-empty",
ContentEdit._("No styles available for this tag"));this._domView.appendChild(this._domStyles);var d=g.StylePalette.styles(this.element);var c=0;for(b=d.length;c<b;c++){var h=d[c];h=new A(h,this.element.hasCSSClass(h.cssClass()));this._styleUIs.push(h);h.mount(this._domStyles)}this._domAttributes=this.constructor.createDiv(["ct-properties-dialog__attributes"]);this._domView.appendChild(this._domAttributes);d=g.getRestrictedAtributes(this.element.tagName());b=this.element.attributes();c=[];for(f in b)d&&
-1!==d.indexOf(f.toLowerCase())||c.push(f);c.sort();h=0;for(e=c.length;h<e;h++){var f=c[h];d=b[f];this._addAttributeUI(f,d)}this._addAttributeUI("","");this._domCode=this.constructor.createDiv(["ct-properties-dialog__code"]);this._domView.appendChild(this._domCode);this._domInnerHTML=document.createElement("textarea");this._domInnerHTML.setAttribute("class","ct-properties-dialog__inner-html");this._domInnerHTML.setAttribute("name","code");this._domInnerHTML.value=this.getElementInnerHTML();this._domCode.appendChild(this._domInnerHTML);
f=this.constructor.createDiv(["ct-control-group","ct-control-group--left"]);this._domControls.appendChild(f);this._domStylesTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--styles"]);this._domStylesTab.setAttribute("data-ct-tooltip",ContentEdit._("Styles"));f.appendChild(this._domStylesTab);this._domAttributesTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--attributes"]);this._domAttributesTab.setAttribute("data-ct-tooltip",ContentEdit._("Attributes"));
f.appendChild(this._domAttributesTab);this._domCodeTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--code"]);this._domCodeTab.setAttribute("data-ct-tooltip",ContentEdit._("Code"));f.appendChild(this._domCodeTab);this._supportsCoding||ContentEdit.addCSSClass(this._domCodeTab,"ct-control--muted");this._domRemoveAttribute=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--remove","ct-control--muted"]);this._domRemoveAttribute.setAttribute("data-ct-tooltip",
ContentEdit._("Remove"));f.appendChild(this._domRemoveAttribute);f=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]);this._domControls.appendChild(f);this._domApply=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--apply"]);this._domApply.textContent=ContentEdit._("Apply");f.appendChild(this._domApply);f=window.localStorage.getItem("ct-properties-dialog-tab");"attributes"===f?(ContentEdit.addCSSClass(this._domElement,"ct-properties-dialog--attributes"),
ContentEdit.addCSSClass(this._domAttributesTab,"ct-control--active")):"code"===f&&this._supportsCoding?(ContentEdit.addCSSClass(this._domElement,"ct-properties-dialog--code"),ContentEdit.addCSSClass(this._domCodeTab,"ct-control--active")):(ContentEdit.addCSSClass(this._domElement,"ct-properties-dialog--styles"),ContentEdit.addCSSClass(this._domStylesTab,"ct-control--active"));return this._addDOMEventListeners()};a.prototype.save=function(){var b=null;this._supportsCoding&&(b=this._domInnerHTML.value);
b={changedAttributes:this.changedAttributes(),changedStyles:this.changedStyles(),innerHTML:b};return this.dispatchEvent(this.createEvent("save",b))};a.prototype._addAttributeUI=function(b,a){var d=this;var e=new y(b,a);this._attributeUIs.push(e);e.addEventListener("blur",function(b){d._focusedAttributeUI=null;ContentEdit.addCSSClass(d._domRemoveAttribute,"ct-control--muted");b=d._attributeUIs.indexOf(this);var a=d._attributeUIs.length;""===this.name()&&b<a-1&&(this.unmount(),d._attributeUIs.splice(b,
1));if((b=d._attributeUIs[a-1])&&b.name()&&b.value())return d._addAttributeUI("","")});e.addEventListener("focus",function(b){d._focusedAttributeUI=this;return ContentEdit.removeCSSClass(d._domRemoveAttribute,"ct-control--muted")});e.addEventListener("namechange",function(a){var e;a=d.element;b=this.name().toLowerCase();var c=g.getRestrictedAtributes(a.tagName());a=!0;c&&-1!==c.indexOf(b)&&(a=!1);var h=d._attributeUIs;var k=0;for(e=h.length;k<e;k++)c=h[k],""!==b&&c!==this&&c.name().toLowerCase()===
b&&(a=!1);this.valid(a);return a?ContentEdit.removeCSSClass(d._domApply,"ct-control--muted"):ContentEdit.addCSSClass(d._domApply,"ct-control--muted")});e.mount(this._domAttributes);return e};a.prototype._addDOMEventListeners=function(){a.__super__._addDOMEventListeners.call(this);var b=function(b){return function(a){var d;var e=["attributes","code","styles"];var c=0;for(d=e.length;c<d;c++){var k=e[c];if(k!==a){var f=k.charAt(0).toUpperCase()+k.slice(1);ContentEdit.removeCSSClass(b._domElement,"ct-properties-dialog--"+
k);ContentEdit.removeCSSClass(b["_dom"+f+"Tab"],"ct-control--active")}}k=a.charAt(0).toUpperCase()+a.slice(1);ContentEdit.addCSSClass(b._domElement,"ct-properties-dialog--"+a);ContentEdit.addCSSClass(b["_dom"+k+"Tab"],"ct-control--active");return window.localStorage.setItem("ct-properties-dialog-tab",a)}}(this);this._domStylesTab.addEventListener("mousedown",function(a){return function(){return b("styles")}}(this));this._domAttributesTab.addEventListener("mousedown",function(a){return function(){return b("attributes")}}(this));
this._supportsCoding&&this._domCodeTab.addEventListener("mousedown",function(a){return function(){return b("code")}}(this));this._domRemoveAttribute.addEventListener("mousedown",function(b){return function(a){a.preventDefault();if(b._focusedAttributeUI){a=b._attributeUIs.indexOf(b._focusedAttributeUI);var d=a===b._attributeUIs.length-1;b._focusedAttributeUI.unmount();b._attributeUIs.splice(a,1);if(d)return b._addAttributeUI("","")}}}(this));var e=function(b){return function(a){try{return new HTMLString.String(b._domInnerHTML.value),
ContentEdit.removeCSSClass(b._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.removeCSSClass(b._domApply,"ct-control--muted")}catch(h){return ContentEdit.addCSSClass(b._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.addCSSClass(b._domApply,"ct-control--muted")}}}(this);this._domInnerHTML.addEventListener("input",e);this._domInnerHTML.addEventListener("propertychange",e);return this._domApply.addEventListener("click",function(b){return function(a){a.preventDefault();
if(-1===b._domApply.getAttribute("class").indexOf("ct-control--muted"))return b.save()}}(this))};return a}(g.DialogUI);var A=function(c){function a(b,e){this.style=b;a.__super__.constructor.call(this);this._applied=e}l(a,c);a.prototype.applied=function(b){if(void 0===b)return this._applied;if(this._applied!==b)return(this._applied=b)?ContentEdit.addCSSClass(this._domElement,"ct-section--applied"):ContentEdit.removeCSSClass(this._domElement,"ct-section--applied")};a.prototype.mount=function(b,e){null==
e&&(e=null);this._domElement=this.constructor.createDiv(["ct-section"]);this._applied&&ContentEdit.addCSSClass(this._domElement,"ct-section--applied");var d=this.constructor.createDiv(["ct-section__label"]);d.textContent=this.style.name();this._domElement.appendChild(d);this._domElement.appendChild(this.constructor.createDiv(["ct-section__switch"]));return a.__super__.mount.call(this,b,e)};a.prototype._addDOMEventListeners=function(){var b=function(b){return function(a){a.preventDefault();return b.applied()?
b.applied(!1):b.applied(!0)}}(this);return this._domElement.addEventListener("click",b)};return a}(g.AnchoredComponentUI);var y=function(c){function a(b,e){a.__super__.constructor.call(this);this._initialName=b;this._initialValue=e}l(a,c);a.prototype.name=function(){return this._domName.value.trim()};a.prototype.value=function(){return this._domValue.value.trim()};a.prototype.mount=function(b,e){null==e&&(e=null);this._domElement=this.constructor.createDiv(["ct-attribute"]);this._domName=document.createElement("input");
this._domName.setAttribute("class","ct-attribute__name");this._domName.setAttribute("name","name");this._domName.setAttribute("placeholder",ContentEdit._("Name"));this._domName.setAttribute("type","text");this._domName.setAttribute("value",this._initialName);this._domElement.appendChild(this._domName);this._domValue=document.createElement("input");this._domValue.setAttribute("class","ct-attribute__value");this._domValue.setAttribute("name","value");this._domValue.setAttribute("placeholder",ContentEdit._("Value"));
this._domValue.setAttribute("type","text");this._domValue.setAttribute("value",this._initialValue);this._domElement.appendChild(this._domValue);return a.__super__.mount.call(this,b,e)};a.prototype.valid=function(b){return b?ContentEdit.removeCSSClass(this._domName,"ct-attribute__name--invalid"):ContentEdit.addCSSClass(this._domName,"ct-attribute__name--invalid")};a.prototype._addDOMEventListeners=function(){this._domName.addEventListener("blur",function(b){return function(){var a=b.name();var d=b._domElement.nextSibling;
b.dispatchEvent(b.createEvent("blur"));if(""===a&&d)return a=d.querySelector(".ct-attribute__name"),a.focus()}}(this));this._domName.addEventListener("focus",function(b){return function(){return b.dispatchEvent(b.createEvent("focus"))}}(this));this._domName.addEventListener("input",function(b){return function(){return b.dispatchEvent(b.createEvent("namechange"))}}(this));this._domName.addEventListener("keydown",function(b){return function(a){if(13===a.keyCode)return b._domValue.focus()}}(this));this._domValue.addEventListener("blur",
function(b){return function(){return b.dispatchEvent(b.createEvent("blur"))}}(this));this._domValue.addEventListener("focus",function(b){return function(){return b.dispatchEvent(b.createEvent("focus"))}}(this));return this._domValue.addEventListener("keydown",function(b){return function(a){if(13===a.keyCode||9===a.keyCode&&!a.shiftKey)if(a.preventDefault(),a=b._domElement.nextSibling,a||(b._domValue.blur(),a=b._domElement.nextSibling),a)return a=a.querySelector(".ct-attribute__name"),a.focus()}}(this))};
return a}(g.AnchoredComponentUI);g.TableDialog=function(c){function a(b){(this.table=b)?a.__super__.constructor.call(this,"Update table"):a.__super__.constructor.call(this,"Insert table")}l(a,c);a.prototype.mount=function(){a.__super__.mount.call(this);var b=3;var e=!1;var d=!0;this.table&&(b=this.table.firstSection().children[0].children.length,e=this.table.tfoot(),d=this.table.thead());ContentEdit.addCSSClass(this._domElement,"ct-table-dialog");ContentEdit.addCSSClass(this._domView,"ct-table-dialog__view");
var c=["ct-section"];d&&c.push("ct-section--applied");this._domHeadSection=this.constructor.createDiv(c);this._domView.appendChild(this._domHeadSection);d=this.constructor.createDiv(["ct-section__label"]);d.textContent=ContentEdit._("Table head");this._domHeadSection.appendChild(d);this._domHeadSwitch=this.constructor.createDiv(["ct-section__switch"]);this._domHeadSection.appendChild(this._domHeadSwitch);this._domBodySection=this.constructor.createDiv(["ct-section","ct-section--applied","ct-section--contains-input"]);
this._domView.appendChild(this._domBodySection);d=this.constructor.createDiv(["ct-section__label"]);d.textContent=ContentEdit._("Table body (columns)");this._domBodySection.appendChild(d);this._domBodyInput=document.createElement("input");this._domBodyInput.setAttribute("class","ct-section__input");this._domBodyInput.setAttribute("maxlength","2");this._domBodyInput.setAttribute("name","columns");this._domBodyInput.setAttribute("type","text");this._domBodyInput.setAttribute("value",b);this._domBodySection.appendChild(this._domBodyInput);
b=["ct-section"];e&&b.push("ct-section--applied");this._domFootSection=this.constructor.createDiv(b);this._domView.appendChild(this._domFootSection);e=this.constructor.createDiv(["ct-section__label"]);e.textContent=ContentEdit._("Table foot");this._domFootSection.appendChild(e);this._domFootSwitch=this.constructor.createDiv(["ct-section__switch"]);this._domFootSection.appendChild(this._domFootSwitch);e=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]);this._domControls.appendChild(e);
this._domApply=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--apply"]);this._domApply.textContent="Apply";e.appendChild(this._domApply);return this._addDOMEventListeners()};a.prototype.save=function(){var b=this._domFootSection.getAttribute("class");var a=this._domHeadSection.getAttribute("class");b={columns:parseInt(this._domBodyInput.value),foot:-1<b.indexOf("ct-section--applied"),head:-1<a.indexOf("ct-section--applied")};return this.dispatchEvent(this.createEvent("save",
b))};a.prototype.unmount=function(){a.__super__.unmount.call(this);return this._domFootSwitch=this._domFootSection=this._domHeadSwitch=this._domHeadSection=this._domApply=this._domBodySection=this._domBodyInput=null};a.prototype._addDOMEventListeners=function(){a.__super__._addDOMEventListeners.call(this);var b=function(b){b.preventDefault();return-1<this.getAttribute("class").indexOf("ct-section--applied")?ContentEdit.removeCSSClass(this,"ct-section--applied"):ContentEdit.addCSSClass(this,"ct-section--applied")};
this._domHeadSection.addEventListener("click",b);this._domFootSection.addEventListener("click",b);this._domBodySection.addEventListener("click",function(b){return function(a){return b._domBodyInput.focus()}}(this));this._domBodyInput.addEventListener("input",function(b){return function(a){if(/^[1-9]\d{0,1}$/.test(a.target.value))return ContentEdit.removeCSSClass(b._domBodyInput,"ct-section__input--invalid"),ContentEdit.removeCSSClass(b._domApply,"ct-control--muted");ContentEdit.addCSSClass(b._domBodyInput,
"ct-section__input--invalid");return ContentEdit.addCSSClass(b._domApply,"ct-control--muted")}}(this));return this._domApply.addEventListener("click",function(b){return function(a){a.preventDefault();if(-1===b._domApply.getAttribute("class").indexOf("ct-control--muted"))return b.save()}}(this))};return a}(g.DialogUI);g.VideoDialog=function(c){function a(){a.__super__.constructor.call(this,"Insert video")}l(a,c);a.prototype.clearPreview=function(){if(this._domPreview)return this._domPreview.parentNode.removeChild(this._domPreview),
this._domPreview=void 0};a.prototype.mount=function(){a.__super__.mount.call(this);ContentEdit.addCSSClass(this._domElement,"ct-video-dialog");ContentEdit.addCSSClass(this._domView,"ct-video-dialog__preview");var b=this.constructor.createDiv(["ct-control-group"]);this._domControls.appendChild(b);this._domInput=document.createElement("input");this._domInput.setAttribute("class","ct-video-dialog__input");this._domInput.setAttribute("name","url");this._domInput.setAttribute("placeholder",ContentEdit._("Paste YouTube or Vimeo URL")+
"...");this._domInput.setAttribute("type","text");b.appendChild(this._domInput);this._domButton=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--insert","ct-control--muted"]);this._domButton.textContent=ContentEdit._("Insert");b.appendChild(this._domButton);return this._addDOMEventListeners()};a.prototype.preview=function(b){this.clearPreview();this._domPreview=document.createElement("iframe");this._domPreview.setAttribute("frameborder","0");this._domPreview.setAttribute("height",
"100%");this._domPreview.setAttribute("src",b);this._domPreview.setAttribute("width","100%");return this._domView.appendChild(this._domPreview)};a.prototype.save=function(){var b;var a=this._domInput.value.trim();return(b=g.getEmbedVideoURL(a))?this.dispatchEvent(this.createEvent("save",{url:b})):this.dispatchEvent(this.createEvent("save",{url:a}))};a.prototype.show=function(){a.__super__.show.call(this);return this._domInput.focus()};a.prototype.unmount=function(){this.isMounted()&&this._domInput.blur();
a.__super__.unmount.call(this);return this._domPreview=this._domInput=this._domButton=null};a.prototype._addDOMEventListeners=function(){a.__super__._addDOMEventListeners.call(this);this._domInput.addEventListener("input",function(b){return function(a){a.target.value?ContentEdit.removeCSSClass(b._domButton,"ct-control--muted"):ContentEdit.addCSSClass(b._domButton,"ct-control--muted");b._updatePreviewTimeout&&clearTimeout(b._updatePreviewTimeout);return b._updatePreviewTimeout=setTimeout(function(){var a=
b._domInput.value.trim();return(a=g.getEmbedVideoURL(a))?b.preview(a):b.clearPreview()},500)}}(this));this._domInput.addEventListener("keypress",function(b){return function(a){if(13===a.keyCode)return b.save()}}(this));return this._domButton.addEventListener("click",function(b){return function(a){a.preventDefault();if(-1===b._domButton.getAttribute("class").indexOf("ct-control--muted"))return b.save()}}(this))};return a}(g.DialogUI);g.HTMLCleaner=function(){function c(a,b){this.tagWhitelist=a||this.constructor.DEFAULT_TAG_WHITELIST;
this.attributeWhitelist=b||this.constructor.DEFAULT_ATTRIBUTE_WHITELIST}c.DEFAULT_ATTRIBUTE_WHITELIST={a:["href"],td:["colspan"]};c.DEFAULT_TAG_WHITELIST="a address b blockquote code del em h1 h2 h3 h4 h5 h6 i ins li ol p pre strong sup table tbody td tfoot th thead tr u ul #text".split(" ");c.NO_CONTENT_TAGS=["head","meta","style","script","title"];c.prototype.clean=function(a){var b,e,d,c;var h=document.implementation.createHTMLDocument();var f=h.createElement("div");f.innerHTML=a;for(a=function(){var b;
var a=f.childNodes;var d=[];var c=0;for(b=a.length;c<b;c++)e=a[c],d.push(e);return d}();0<a.length;){var g=a.shift();var v=g.nodeName.toLowerCase();if(0>this.tagWhitelist.indexOf(v)){if(!(-1<this.constructor.NO_CONTENT_TAGS.indexOf(v))){var n=g.childNodes;var l=0;for(d=n.length;l<d;l++)if(v=n[l])v=v.cloneNode(!0),v.nodeName.toLowerCase(),g.parentNode.insertBefore(v,g),a.push(v)}g.remove()}else if("#text"!==v&&""===g.textContent.trim())""===g.textContent||g.parentNode===f?g.remove():g.parentNode.replaceChild(h.createTextNode(" "),
g);else{"td"!==v&&"th"!==v&&"li"!==v||!g.querySelector("p")||(g.innerHTML=g.textContent);if(g.attributes){d=this.attributeWhitelist[v]||[];l=function(){var a;var d=g.attributes;var e=[];var c=0;for(a=d.length;c<a;c++)b=d[c],e.push(b);return e}();var p=0;for(c=l.length;p<c;p++)v=l[p],0>d.indexOf(v.name.toLowerCase())?g.removeAttribute(v.name):"href"===v.name.toLowerCase()&&(n=g.getAttribute(v.name),n.startsWith("javascript:")&&g.removeAttribute(v.name))}a.push.apply(a,function(){var b;var a=g.childNodes;
var d=[];var c=0;for(b=a.length;c<b;c++)e=a[c],d.push(e);return d}())}}return f.innerHTML};return c}();var z=function(c){function a(){a.__super__.constructor.call(this);this.history=null;this._state="dormant";this._busy=!1;this._namingProp=null;this._fixtureTest=function(b){return b.hasAttribute("data-fixture")};this._domRegions=this._regionQuery=null;this._regions={};this._orderedRegions=[];this._rootLastModified=null;this._regionsLastModified={};this._toolbox=this._inspector=this._ignition=null;
this._emptyRegionsAllowed=!1}l(a,c);a.prototype.ctrlDown=function(){return this._ctrlDown};a.prototype.domRegions=function(){return this._domRegions};a.prototype.getState=function(){return this._state};a.prototype.ignition=function(){return this._ignition};a.prototype.inspector=function(){return this._inspector};a.prototype.isDormant=function(){return"dormant"===this._state};a.prototype.isReady=function(){return"ready"===this._state};a.prototype.isEditing=function(){return"editing"===this._state};
a.prototype.orderedRegions=function(){var b;var a=this._orderedRegions;var d=[];var c=0;for(b=a.length;c<b;c++){var h=a[c];d.push(this._regions[h])}return d};a.prototype.regions=function(){return this._regions};a.prototype.shiftDown=function(){return this._shiftDown};a.prototype.toolbox=function(){return this._toolbox};a.prototype.busy=function(b){if(void 0===b)return this._busy;this._busy=b;if(this._ignition)return this._ignition.busy(b)};a.prototype.createPlaceholderElement=function(b){return new ContentEdit.Text("p",
{},"")};a.prototype.init=function(b,a,d,c){null==a&&(a="id");null==d&&(d=null);null==c&&(c=!0);this._namingProp=a;d&&(this._fixtureTest=d);this.mount();c&&(this._ignition=new g.IgnitionUI,this.attach(this._ignition),this._ignition.addEventListener("edit",function(b){return function(a){a.preventDefault();b.start();return b._ignition.state("editing")}}(this)),this._ignition.addEventListener("confirm",function(b){return function(a){a.preventDefault();if("editing"===b._ignition.state())return b._ignition.state("ready"),
b.stop(!0)}}(this)),this._ignition.addEventListener("cancel",function(b){return function(a){a.preventDefault();if("editing"===b._ignition.state())return b.stop(!1),b.isEditing()?b._ignition.state("editing"):b._ignition.state("ready")}}(this)));this._toolbox=new g.ToolboxUI(g.DEFAULT_TOOLS);this.attach(this._toolbox);this._inspector=new g.InspectorUI;this.attach(this._inspector);this._state="ready";this._handleDetach=function(b){return function(a){return b._preventEmptyRegions()}}(this);this._handleClipboardPaste=
function(b){return function(a,d){if(d.clipboardData)d.clipboardData.getData("text/html")&&"PreText"!==a.type()?b.pasteHTML(a,d.clipboardData.getData("text/html")):b.pasteText(a,d.clipboardData.getData("text/plain"));else if(window.clipboardData)return window.clipboardData.getData("TEXT"),b.pasteText(a,window.clipboardData.getData("TEXT"))}}(this);this._handleNextRegionTransition=function(b){return function(a){var d;var e=b.orderedRegions();a=e.indexOf(a);if(!(a>=e.length-1)){a=e[a+1];var c=null;var h=
a.descendants();var k=0;for(d=h.length;k<d;k++)if(e=h[k],void 0!==e.content){c=e;break}if(c)c.focus(),c.selection(new ContentSelect.Range(0,0));else return ContentEdit.Root.get().trigger("next-region",a)}}}(this);this._handlePreviousRegionTransition=function(b){return function(a){var d;var e=b.orderedRegions();a=e.indexOf(a);if(!(0>=a)){a=e[a-1];e=null;var c=a.descendants();c.reverse();var h=0;for(d=c.length;h<d;h++){var k=c[h];if(void 0!==k.content){e=k;break}}if(e)a=e.content.length(),e.focus(),
e.selection(new ContentSelect.Range(a,a));else return ContentEdit.Root.get().trigger("previous-region",a)}}}(this);ContentEdit.Root.get().bind("detach",this._handleDetach);ContentEdit.Root.get().bind("paste",this._handleClipboardPaste);ContentEdit.Root.get().bind("next-region",this._handleNextRegionTransition);ContentEdit.Root.get().bind("previous-region",this._handlePreviousRegionTransition);return this.syncRegions(b)};a.prototype.destroy=function(){ContentEdit.Root.get().unbind("detach",this._handleDetach);
ContentEdit.Root.get().unbind("paste",this._handleClipboardPaste);ContentEdit.Root.get().unbind("next-region",this._handleNextRegionTransition);ContentEdit.Root.get().unbind("previous-region",this._handlePreviousRegionTransition);this.removeEventListener();this.unmount();return this._children=[]};a.prototype.highlightRegions=function(b){var a;var d=this._domRegions;var c=[];var h=0;for(a=d.length;h<a;h++){var f=d[h];b?c.push(ContentEdit.addCSSClass(f,"ct--highlight")):c.push(ContentEdit.removeCSSClass(f,
"ct--highlight"))}return c};a.prototype.mount=function(){this._domElement=this.constructor.createDiv(["ct-app"]);document.body.insertBefore(this._domElement,null);return this._addDOMEventListeners()};a.prototype.unmount=function(){var b;if(this.isMounted()){var a=this._children;var d=0;for(b=a.length;d<b;d++){var c=a[d];c.unmount()}this._domElement.parentNode.removeChild(this._domElement);this._domElement=null;this._removeDOMEventListeners();return this._toolbox=this._inspector=this._ignition=null}};
a.prototype.pasteHTML=function(b,a){var d,c;var e=ContentEdit.TagNames.get();var f=document.implementation.createHTMLDocument().createElement("div");f.innerHTML=g.getHTMLCleaner().clean(a.trim());var u=[];var l=f.childNodes;var n=0;for(c=l.length;n<c;n++)(d=l[n])&&("#text"!==d.nodeName.toLowerCase()||""!==d.textContent.trim())&&u.push(d);if(u.length){c=g.INLINE_TAGS.slice();c.push("#text");n=u[0].nodeName.toLowerCase();l=u[u.length-1].nodeName.toLowerCase();if(b.isFixed()||-1<c.indexOf(n)&&-1<c.indexOf(l)){-1<
c.indexOf(n)&&-1<c.indexOf(l)?a=new HTMLString.String(f.innerHTML):(console.log(f.textContent),a=new HTMLString.String(HTMLString.String.encode(f.textContent)));if(b.content){u=b.selection();e=u.get()[0]+a.length();f=b.content.substring(0,u.get()[0]);d=b.content.substring(u.get()[1]);n=b.content.substring(u.get()[0],u.get()[1]);n.length()&&(n=n.characters[0],c=n.tags(),n.isTag()&&c.shift(),1<=c.length&&(a=a.format.apply(a,[0,a.length()].concat(t.call(c)))));b.content=f.concat(a);b.content=b.content.concat(d,
!1);b.updateInnerHTML();b.taint();u.set(e,e);b.selection(u);return}f.innerHTML="<p>"+a.html()+"</p>"}u=b;"Region"!==b.parent().type()&&(b=b.closest(function(b){return"Region"===b.parent().type()}));d=b.parent();if(-1<c.indexOf(n)&&-1<c.indexOf(l)){for(n=f.createElement("p");0<f.childNodes.length;)n.appendChild(f.childNodes[0]);f.appendChild(n)}n=0;var q=u;var p=f.childNodes;c=0;for(l=p.length;c<l;c++)!(f=p[c])||"#text"===f.nodeName&&""===f.textContent.trim()||(q=e.match(f.nodeName),q===ContentEdit.Static&&
(q=document.createElement("p"),q.appendChild(f),f=q,q=ContentEdit.Text),q=q.fromDOMElement(f),d.attach(q,d.children.indexOf(b)+(1+n)),n+=1);if(q.focus)return q.focus();if(q.nextSibling()){if(q=q.nextSibling().previousWithTest(function(b){if(b.focus)return b}))return q.focus()}else return(q=q.nextWithTest(function(b){if(b.focus)return b}))?q.focus():u.focus()}};a.prototype.pasteText=function(b,a){var d,c;var e="PreText"!==b.type()?a.split("\n"):[a];if(e=e.filter(function(b){return""!==b.trim()})){var f=
HTMLString.String.encode;var g=!0;var l=b.type();1===e.length&&(g=!1);"PreText"===l&&(g=!1);b.can("spawn")||(g=!1);if(g){if("ListItemText"===l){var n=b.parent();g=b.parent().parent()}else n=b,"Region"!==n.parent().type()&&(n=b.closest(function(b){return"Region"===b.parent().type()})),g=n.parent();var q=g.children.indexOf(n)+1;n=d=0;for(c=e.length;d<c;n=++d){var p=e[n];p=f(p);if("ListItemText"===l){var r=new ContentEdit.ListItem;p=new ContentEdit.ListItemText(p);r.attach(p)}else p=r=new ContentEdit.Text("p",
{},p);g.attach(r,q+n)}f=p.content.length();p.focus();return p.selection(new ContentSelect.Range(f,f))}a=f(a);a=new HTMLString.String(a,"PreText"===l);e=b.selection();f=e.get()[0]+a.length();g=b.content.substring(0,e.get()[0]);l=b.content.substring(e.get()[1]);p=b.content.substring(e.get()[0],e.get()[1]);p.length()&&(p=p.characters[0],n=p.tags(),p.isTag()&&n.shift(),1<=n.length&&(a=a.format.apply(a,[0,a.length()].concat(t.call(n)))));b.content=g.concat(a);b.content=b.content.concat(l,!1);b.updateInnerHTML();
b.taint();e.set(f,f);return b.selection(e)}};a.prototype.revert=function(){if(this.dispatchEvent(this.createEvent("revert"))){if(g.CANCEL_MESSAGE){var b=ContentEdit._(g.CANCEL_MESSAGE);if(ContentEdit.Root.get().lastModified()>this._rootLastModified&&!window.confirm(b))return!1}this.revertToSnapshot(this.history.goTo(0),!1);return!0}};a.prototype.revertToSnapshot=function(b,a){var d,c;null==a&&(a=!0);var e=[];var f=this._regions;for(d in f){var g=f[d];var l=g.children;var n=0;for(c=l.length;n<c;n++){var q=
l[n];q.unmount()}void 0!==b.regions[d]?1===g.children.length&&g.children[0].isFixed()?(q=this.constructor.createDiv(),q.innerHTML=b.regions[d],e.push(q.firstElementChild),g.domElement().parentNode.replaceChild(q.firstElementChild,g.domElement())):(e.push(g.domElement()),g.domElement().innerHTML=b.regions[d]):(g.domElement().remove(),delete this._regions[d])}this._domRegions=e;if(a){ContentEdit.Root.get().focused()&&ContentEdit.Root.get().focused().blur();this._regions={};this.syncRegions(null,!0);
ContentEdit.Root.get()._modified=b.rootModified;e=this._regions;for(d in e)g=e[d],b.regionModifieds[d]&&(g._modified=b.regionModifieds[d]);this.history.replaceRegions(this._regions);this.history.restoreSelection(b);return this._inspector.updateTags()}};a.prototype.save=function(b){var a,d;if(this.dispatchEvent(this.createEvent("save",{passive:b}))){var c=ContentEdit.Root.get();c.focused()&&!b&&c.focused().blur();if(c.lastModified()===this._rootLastModified&&b)this.dispatchEvent(this.createEvent("saved",
{regions:{},passive:b}));else{c=[];var h={};var f=this._regions;for(a in f){var g=f[a];var l=g.html();if(1===g.children.length&&"Fixture"===!g.type()){var n=g.children[0];n.content&&!n.content.html()&&(l="")}if(!b){var q=g.children;var p=0;for(d=q.length;p<d;p++)n=q[p],n.unmount();1===g.children.length&&g.children[0].isFixed()?(n=this.constructor.createDiv(),n.innerHTML=l,c.push(n.firstElementChild),g.domElement().parentNode.replaceChild(n.firstElementChild,g.domElement())):(c.push(g.domElement()),
g.domElement().innerHTML=l)}g.lastModified()!==this._regionsLastModified[a]&&(h[a]=l,this._regionsLastModified[a]=g.lastModified())}this._domRegions=c;return this.dispatchEvent(this.createEvent("saved",{regions:h,passive:b}))}}};a.prototype.setRegionOrder=function(b){return this._orderedRegions=b.slice()};a.prototype.start=function(){if(this.dispatchEvent(this.createEvent("start")))return this.busy(!0),this.syncRegions(),this._initRegions(),this._preventEmptyRegions(),this._rootLastModified=ContentEdit.Root.get().lastModified(),
this.history=new g.History(this._regions),this.history.watch(),this._state="editing",this._toolbox.show(),this._inspector.show(),this.busy(!1),this.dispatchEvent(this.createEvent("started"))};a.prototype.stop=function(b){var a;if(this.dispatchEvent(this.createEvent("stop",{save:b}))){(a=ContentEdit.Root.get().focused())&&a.isMounted()&&void 0!==a._syncContent&&a._syncContent();if(b)this.save();else if(!this.revert())return;this.history.stopWatching();this.history=null;this._toolbox.hide();this._inspector.hide();
this._regions={};this._state="ready";ContentEdit.Root.get().focused()&&this._allowEmptyRegions(function(b){return function(){return ContentEdit.Root.get().focused().blur()}}(this));return this.dispatchEvent(this.createEvent("stopped"))}};a.prototype.syncRegions=function(b,a){b&&(this._regionQuery=b);this._domRegions=[];this._regionQuery&&(this._domRegions="string"===typeof this._regionQuery||this._regionQuery instanceof String?document.querySelectorAll(this._regionQuery):this._regionQuery);"editing"===
this._state&&(this._initRegions(a),this._preventEmptyRegions());if(this._ignition)return this._domRegions.length?this._ignition.show():this._ignition.hide()};a.prototype._addDOMEventListeners=function(){this._handleHighlightOn=function(b){return function(a){var d;if(17===(d=a.keyCode)||224===d||91===d||93===d)b._ctrlDown=!0;if(16!==a.keyCode||b._ctrlDown)return clearTimeout(b._highlightTimeout),b.highlightRegions(!1);b._highlightTimeout||(b._shiftDown=!0,b._highlightTimeout=setTimeout(function(){return b.highlightRegions(!0)},
g.HIGHLIGHT_HOLD_DURATION))}}(this);this._handleHighlightOff=function(b){return function(a){var d;if(17===(d=a.keyCode)||224===d||91===d||93===d)b._ctrlDown=!1;else if(16===a.keyCode)return b._shiftDown=!1,b._highlightTimeout&&(clearTimeout(b._highlightTimeout),b._highlightTimeout=null),b.highlightRegions(!1)}}(this);this._handleVisibility=function(b){return function(a){if(!document.hasFocus())return clearTimeout(b._highlightTimeout),b.highlightRegions(!1)}}(this);document.addEventListener("keydown",
this._handleHighlightOn);document.addEventListener("keyup",this._handleHighlightOff);document.addEventListener("visibilitychange",this._handleVisibility);this._handleBeforeUnload=function(b){return function(a){if("editing"===b._state&&g.CANCEL_MESSAGE){var d=ContentEdit._(g.CANCEL_MESSAGE);return(a||window.event).returnValue=d}}}(this);window.addEventListener("beforeunload",this._handleBeforeUnload);this._handleUnload=function(b){return function(a){return b.destroy()}}(this);return window.addEventListener("unload",
this._handleUnload)};a.prototype._allowEmptyRegions=function(b){this._emptyRegionsAllowed=!0;b();return this._emptyRegionsAllowed=!1};a.prototype._preventEmptyRegions=function(){var b,a;if(!this._emptyRegionsAllowed){var d=this._regions;var c=[];for(b in d){var h=d[b];var f=h.lastModified();var g=!1;var l=h.children;var n=0;for(a=l.length;n<a;n++){var q=l[n];if("Static"!==q.type()){g=!0;break}}g||(q=this.createPlaceholderElement(h),h.attach(q),c.push(h._modified=f))}return c}};a.prototype._removeDOMEventListeners=
function(){document.removeEventListener("keydown",this._handleHighlightOn);document.removeEventListener("keyup",this._handleHighlightOff);window.removeEventListener("beforeunload",this._handleBeforeUnload);return window.removeEventListener("unload",this._handleUnload)};a.prototype._initRegions=function(b){var a,d,c;null==b&&(b=!1);var h={};var f=[];this._orderedRegions=[];var g=this._domRegions;var l=d=0;for(c=g.length;d<c;l=++d){var n=g[l];(a=n.getAttribute(this._namingProp))||(a=l);h[a]=!0;this._orderedRegions.push(a);
this._regions[a]&&this._regions[a].domElement()===n||(this._fixtureTest(n)?this._regions[a]=new ContentEdit.Fixture(n):this._regions[a]=new ContentEdit.Region(n),f.push(this._regions[a].domElement()),b||(this._regionsLastModified[a]=this._regions[a].lastModified()))}this._domRegions=f;n=this._regions;b=[];for(a in n)h[a]||(delete this._regions[a],delete this._regionsLastModified[a],n=this._orderedRegions.indexOf(a),-1<n?b.push(this._orderedRegions.splice(n,1)):b.push(void 0));return b};return a}(g.ComponentUI);
g.EditorApp=function(){function c(){}var a=null;c.get=function(){var b=g.EditorApp.getCls();return null!=a?a:a=new b};c.getCls=function(){return z};return c}();g.History=function(){function c(a){this._lastSnapshotTaken=null;this._regions={};this.replaceRegions(a);this._snapshotIndex=-1;this._snapshots=[];this._store()}c.prototype.canRedo=function(){return this._snapshotIndex<this._snapshots.length-1};c.prototype.canUndo=function(){return 0<this._snapshotIndex};c.prototype.index=function(){return this._snapshotIndex};
c.prototype.length=function(){return this._snapshots.length};c.prototype.snapshot=function(){return this._snapshots[this._snapshotIndex]};c.prototype.goTo=function(a){this._snapshotIndex=Math.min(this._snapshots.length-1,Math.max(0,a));return this.snapshot()};c.prototype.redo=function(){return this.goTo(this._snapshotIndex+1)};c.prototype.replaceRegions=function(a){var b;this._regions={};var c=[];for(b in a){var d=a[b];c.push(this._regions[b]=d)}return c};c.prototype.restoreSelection=function(a){if(a.selected){var b=
this._regions[a.selected.region].descendants()[a.selected.element];b.focus();if(b.selection&&a.selected.selection)return b.selection(a.selected.selection)}};c.prototype.stopWatching=function(){this._watchInterval&&clearInterval(this._watchInterval);if(this._delayedStoreTimeout)return clearTimeout(this._delayedStoreTimeout)};c.prototype.undo=function(){return this.goTo(this._snapshotIndex-1)};c.prototype.watch=function(){this._lastSnapshotTaken=Date.now();var a=function(b){return function(){var a=
ContentEdit.Root.get().lastModified();if(null!==a&&a>b._lastSnapshotTaken&&b._delayedStoreRequested!==a)return b._delayedStoreTimeout&&clearTimeout(b._delayedStoreTimeout),b._delayedStoreRequested=a,b._delayedStoreTimeout=setTimeout(function(){b._lastSnapshotTaken=a;return b._store()},500)}}(this);return this._watchInterval=setInterval(a,50)};c.prototype._store=function(){var a;var b={regions:{},regionModifieds:{},rootModified:ContentEdit.Root.get().lastModified(),selected:null};var c=this._regions;
for(a in c){var d=c[a];b.regions[a]=d.html();b.regionModifieds[a]=d.lastModified()}if(c=ContentEdit.Root.get().focused()){b.selected={};d=c.closest(function(b){return"Region"===b.type()||"Fixture"===b.type()});if(!d)return;var f=this._regions;for(a in f){var h=f[a];if(d===h){b.selected.region=a;break}}b.selected.element=d.descendants().indexOf(c);c.selection&&(b.selected.selection=c.selection())}this._snapshotIndex<this._snapshots.length-1&&(this._snapshots=this._snapshots.slice(0,this._snapshotIndex+
1));this._snapshotIndex++;return this._snapshots.splice(this._snapshotIndex,0,b)};return c}();g.StylePalette=function(){function c(){}c._styles=[];c.add=function(a){return this._styles=this._styles.concat(a)};c.styles=function(a){if(void 0===a)return this._styles.slice();var b=a.tagName();return this._styles.filter(function(a){return a._applicableTo?-1!==a._applicableTo.indexOf(b):!0})};return c}();g.Style=function(){function c(a,b,c){this._name=a;this._cssClass=b;this._applicableTo=c?c:null}c.prototype.applicableTo=
function(){return this._applicableTo};c.prototype.cssClass=function(){return this._cssClass};c.prototype.name=function(){return this._name};return c}();g.ToolShelf=function(){function c(){}c._tools={};c.stow=function(a,b){return this._tools[b]=a};c.fetch=function(a){if(!this._tools[a])throw Error("`"+a+"` has not been stowed on the tool shelf");return this._tools[a]};return c}();g.Tool=function(){function c(){}c.label="Tool";c.icon="tool";c.requiresElement=!0;c.canApply=function(a,b){return!1};c.isApplied=
function(a,b){return!1};c.apply=function(a,b,c){throw Error("Not implemented");};c.editor=function(){return g.EditorApp.get()};c.dispatchEditorEvent=function(a,b){return this.editor().dispatchEvent(this.editor().createEvent(a,b))};c._insertAt=function(a){var b=a;"Region"!==b.parent().type()&&(b=a.closest(function(b){return"Region"===b.parent().type()}));a=b.parent().children.indexOf(b)+1;return[b,a]};return c}();g.Tools.Bold=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}
l(a,c);g.ToolShelf.stow(a,"bold");a.label="Bold";a.icon="bold";a.tagName="b";a.canApply=function(b,a){return b.content?a&&!a.isCollapsed():!1};a.isApplied=function(b,a){if(void 0===b.content||!b.content.length())return!1;var d=a.get();var c=d[0];d=d[1];c===d&&(d+=1);return b.content.slice(c,d).hasTags(this.tagName,!0)};a.apply=function(b,a,d){var c={tool:this,element:b,selection:a};if(this.dispatchEditorEvent("tool-apply",c)){b.storeState();var e=a.get();var f=e[0];e=e[1];this.isApplied(b,a)?b.content=
b.content.unformat(f,e,new HTMLString.Tag(this.tagName)):b.content=b.content.format(f,e,new HTMLString.Tag(this.tagName));b.content.optimize();b.updateInnerHTML();b.taint();b.restoreState();d(!0);return this.dispatchEditorEvent("tool-applied",c)}};return a}(g.Tool);g.Tools.Italic=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"italic");a.label="Italic";a.icon="italic";a.tagName="i";return a}(g.Tools.Bold);g.Tools.Link=function(c){function a(){return a.__super__.constructor.apply(this,
arguments)}l(a,c);g.ToolShelf.stow(a,"link");a.label="Link";a.icon="link";a.tagName="a";a.getAttr=function(b,a,d){var c;if("Image"===a.type()){if(a.a)return a.a[b]}else{if(a.isFixed()&&"a"===a.tagName())return a.attr(b);var e=d.get();d=e[0];e=e[1];a=a.content.slice(d,e);e=a.characters;a=0;for(d=e.length;a<d;a++){var f=e[a];if(f.hasTags("a")){var g=f.tags();var l=0;for(c=g.length;l<c;l++)if(f=g[l],"a"===f.name())return f.attr(b)}}}return""};a.canApply=function(b,a){if("Image"!==b.type()&&(!b.isFixed()||
"a"!==b.tagName())){if(!b.content||!a)return!1;if(a.isCollapsed()){var c=b.content.characters[a.get()[0]];if(!c||!c.hasTags("a"))return!1}}return!0};a.isApplied=function(b,c){return"Image"===b.type()?b.a:b.isFixed()&&"a"===b.tagName()?!0:a.__super__.constructor.isApplied.call(this,b,c)};a.apply=function(b,a,c){var d={tool:this,element:b,selection:a};if(this.dispatchEditorEvent("tool-apply",d)){var e=!1;if("Image"===b.type())var f=b.domElement().getBoundingClientRect();else if(b.isFixed()&&"a"===b.tagName())f=
b.domElement().getBoundingClientRect();else{if(a.isCollapsed()){var l=b.content.characters;for(a=f=a.get(0)[0];0<f&&l[f-1].hasTags("a");)--f;for(;a<l.length&&l[a].hasTags("a");)a+=1;a=new ContentSelect.Range(f,a);a.select(b.domElement())}b.storeState();var v=new HTMLString.Tag("span",{"class":"ct--pseudo-select"});l=a.get();var n=l[0];var q=l[1];b.content=b.content.format(n,q,v);b.updateInnerHTML();l=b.domElement();l=l.getElementsByClassName("ct--pseudo-select");f=l[0].getBoundingClientRect()}l=g.EditorApp.get();
var p=new g.ModalUI(!0,!0);p.addEventListener("click",function(){this.unmount();t.hide();b.content&&(b.content=b.content.unformat(n,q,v),b.updateInnerHTML(),b.restoreState());c(e);if(e)return g.Tools.Link.dispatchEditorEvent("tool-applied",d)});var t=new g.LinkDialog(this.getAttr("href",b,a),this.getAttr("target",b,a));var r=g.getScrollPosition();a=r[0];r=r[1];t.position([f.left+f.width/2+a,f.top+f.height/2+r]);t.addEventListener("save",function(a){var c,d;var f=a.detail();e=!0;if("Image"===b.type()){a=
["align-center","align-left","align-right"];if(f.href){b.a={href:f.href};b.a&&(b.a["class"]=b.a["class"]);f.target&&(b.a.target=f.target);var h=0;for(c=a.length;h<c;h++)if(f=a[h],b.hasCSSClass(f)){b.removeCSSClass(f);b.a["class"]=f;break}}else{h=[];b.a["class"]&&(h=b.a["class"].split(" "));c=0;for(d=a.length;c<d;c++)if(f=a[c],-1<h.indexOf(f)){b.addCSSClass(f);break}b.a=null}b.unmount();b.mount()}else b.isFixed()&&"a"===b.tagName()?b.attr("href",f.href):(b.content=b.content.unformat(n,q,"a"),f.href&&
(a=new HTMLString.Tag("a",f),b.content=b.content.format(n,q,a),b.content.optimize()),b.updateInnerHTML());b.taint();return p.dispatchEvent(p.createEvent("click"))});l.attach(p);l.attach(t);p.show();return t.show()}};return a}(g.Tools.Bold);g.Tools.Heading=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"heading");a.label="Heading";a.icon="heading";a.tagName="h1";a.canApply=function(a,c){return a.isFixed()?!1:void 0!==a.content&&-1!==["Text",
"PreText"].indexOf(a.type())};a.isApplied=function(a,c){return a.content&&-1!==["Text","PreText"].indexOf(a.type())?a.tagName()===this.tagName:!1};a.apply=function(a,c,d){var b={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b)){a.storeState();if("PreText"===a.type()){var e=a.content.html().replace(/&nbsp;/g," ");var f=new ContentEdit.Text(this.tagName,{},e);var g=a.parent();e=g.children.indexOf(a);g.detach(a);g.attach(f,e);a.blur();f.focus();f.selection(c)}else a.removeAttr("class"),
a.tagName()===this.tagName?a.tagName("p"):a.tagName(this.tagName),a.restoreState();this.dispatchEditorEvent("tool-applied",b);return d(!0)}};return a}(g.Tool);g.Tools.Subheading=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"subheading");a.label="Subheading";a.icon="subheading";a.tagName="h2";return a}(g.Tools.Heading);g.Tools.Paragraph=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,
"paragraph");a.label="Paragraph";a.icon="paragraph";a.tagName="p";a.canApply=function(a,c){return a.isFixed()?!1:void 0!==a};a.apply=function(b,c,d){var e=this.editor().ctrlDown();if(g.Tools.Heading.canApply(b)&&!e)return a.__super__.constructor.apply.call(this,b,c,d);var f={tool:this,element:b,selection:c};if(this.dispatchEditorEvent("tool-apply",f))return"Region"!==b.parent().type()&&(b=b.closest(function(a){return"Region"===a.parent().type()})),e=b.parent(),c=new ContentEdit.Text("p"),e.attach(c,
e.children.indexOf(b)+1),c.focus(),d(!0),this.dispatchEditorEvent("tool-applied",f)};return a}(g.Tools.Heading);g.Tools.Preformatted=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"preformatted");a.label="Preformatted";a.icon="preformatted";a.tagName="pre";a.apply=function(a,c,d){var b={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b))if("PreText"===a.type())g.Tools.Paragraph.apply(a,c,d);else{var e=a.content.text();
var f=new ContentEdit.PreText("pre",{},HTMLString.String.encode(e));var l=a.parent();e=l.children.indexOf(a);l.detach(a);l.attach(f,e);a.blur();f.focus();f.selection(c);d(!0);return this.dispatchEditorEvent("tool-applied",b)}};return a}(g.Tools.Heading);g.Tools.AlignLeft=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"align-left");a.label="Align left";a.icon="align-left";a.className="text-left";a.canApply=function(a,c){return void 0!==a.content};
a.isApplied=function(a,c){var b;if(!this.canApply(a))return!1;if("ListItemText"===(b=a.type())||"TableCellText"===b)a=a.parent();return a.hasCSSClass(this.className)};a.apply=function(a,c,d){var b,e;c={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",c)){if("ListItemText"===(b=a.type())||"TableCellText"===b)a=a.parent();b=[g.Tools.AlignLeft.className,g.Tools.AlignCenter.className,g.Tools.AlignRight.className];var f=0;for(e=b.length;f<e;f++){var l=b[f];if(a.hasCSSClass(l)&&
(a.removeCSSClass(l),l===this.className))return d(!0)}a.addCSSClass(this.className);d(!0);return this.dispatchEditorEvent("tool-applied",c)}};return a}(g.Tool);g.Tools.AlignCenter=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"align-center");a.label="Align center";a.icon="align-center";a.className="text-center";return a}(g.Tools.AlignLeft);g.Tools.AlignRight=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,
c);g.ToolShelf.stow(a,"align-right");a.label="Align right";a.icon="align-right";a.className="text-right";return a}(g.Tools.AlignLeft);g.Tools.UnorderedList=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"unordered-list");a.label="Bullet list";a.icon="unordered-list";a.listTag="ul";a.canApply=function(a,c){var b;return a.isFixed()?!1:void 0!==a.content&&("Region"===(b=a.parent().type())||"ListItem"===b)};a.apply=function(a,c,d){var b={tool:this,
element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b)){if("ListItem"===a.parent().type()){a.storeState();var e=a.closest(function(a){return"List"===a.type()});e.tagName(this.listTag);a.restoreState()}else{var f=new ContentEdit.ListItemText(a.content.copy());var g=new ContentEdit.ListItem;g.attach(f);e=new ContentEdit.List(this.listTag,{});e.attach(g);var l=a.parent();g=l.children.indexOf(a);l.detach(a);l.attach(e,g);f.focus();f.selection(c)}d(!0);return this.dispatchEditorEvent("tool-applied",
b)}};return a}(g.Tool);g.Tools.OrderedList=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"ordered-list");a.label="Numbers list";a.icon="ordered-list";a.listTag="ol";return a}(g.Tools.UnorderedList);g.Tools.Table=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"table");a.label="Table";a.icon="table";a.canApply=function(a,c){return a.isFixed()?!1:void 0!==a};a.apply=function(a,c,d){var b=
{tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b)){a.storeState&&a.storeState();c=g.EditorApp.get();var e=new g.ModalUI;var f=a.closest(function(a){return a&&"Table"===a.type()});var l=new g.TableDialog(f);l.addEventListener("cancel",function(b){return function(){e.hide();l.hide();a.restoreState&&a.restoreState();return d(!1)}}(this));l.addEventListener("save",function(c){return function(h){var g=h.detail();h=!0;f?(c._updateTable(g,f),h=a.closest(function(a){return a&&
"Table"===a.type()})):(f=c._createTable(g),g=c._insertAt(a),h=g[0],g=g[1],h.parent().attach(f,g),h=!1);h?a.restoreState():f.firstSection().children[0].children[0].children[0].focus();e.hide();l.hide();d(!0);return c.dispatchEditorEvent("tool-applied",b)}}(this));c.attach(e);c.attach(l);e.show();return l.show()}};a._adjustColumns=function(a,c){var b,e,f;var g=a.children;var l=[];var t=0;for(f=g.length;t<f;t++){var n=g[t];var q=n.children[0].tagName();var p=n.children.length;var r=c-p;0>r?l.push(function(){var a;
var c=[];for(a=r;0>=r?0>a:0<a;0>=r?++a:--a)b=n.children[n.children.length-1],c.push(n.detach(b));return c}()):0<r?l.push(function(){var a;var c=[];for(a=0;0<=r?a<r:a>r;0<=r?++a:--a)b=new ContentEdit.TableCell(q),n.attach(b),e=new ContentEdit.TableCellText(""),c.push(b.attach(e));return c}()):l.push(void 0)}return l};a._createTable=function(a){var b=new ContentEdit.Table;if(a.head){var c=this._createTableSection("thead","th",a.columns);b.attach(c)}c=this._createTableSection("tbody","td",a.columns);
b.attach(c);a.foot&&(a=this._createTableSection("tfoot","td",a.columns),b.attach(a));return b};a._createTableSection=function(a,c,d){var b;var e=new ContentEdit.TableSection(a);var f=new ContentEdit.TableRow;e.attach(f);for(b=0;0<=d?b<d:b>d;0<=d?++b:--b){a=new ContentEdit.TableCell(c);f.attach(a);var g=new ContentEdit.TableCellText("");a.attach(g)}return e};a._updateTable=function(a,c){var b;!a.head&&c.thead()&&c.detach(c.thead());!a.foot&&c.tfoot()&&c.detach(c.tfoot());var e=c.firstSection().children[0].children.length;
if(a.columns!==e){var f=c.children;var g=0;for(b=f.length;g<b;g++)e=f[g],this._adjustColumns(e,a.columns)}a.head&&!c.thead()&&(e=this._createTableSection("thead","th",a.columns),c.attach(e,0));if(a.foot&&!c.tfoot())return e=this._createTableSection("tfoot","td",a.columns),c.attach(e)};return a}(g.Tool);g.Tools.Indent=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"indent");a.label="Indent";a.icon="indent";a.canApply=function(a,c){return"ListItem"===
a.parent().type()&&0<a.parent().parent().children.indexOf(a.parent())};a.apply=function(a,c,d){c={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",c))return a.parent().indent(),d(!0),this.dispatchEditorEvent("tool-applied",c)};return a}(g.Tool);g.Tools.Unindent=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"unindent");a.label="Unindent";a.icon="unindent";a.canApply=function(a,c){return"ListItem"===a.parent().type()};
a.apply=function(a,c,d){c={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",c))return a.parent().unindent(),d(!0),this.dispatchEditorEvent("tool-applied",c)};return a}(g.Tool);g.Tools.LineBreak=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"line-break");a.label="Line break";a.icon="line-break";a.canApply=function(a,c){return a.content};a.apply=function(a,c,d){var b={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",
b)){var e=c.get()[0]+1;var f=a.content.substring(0,c.get()[0]);var g=a.content.substring(c.get()[1]);var l=new HTMLString.String("<br>",a.content.preserveWhitespace());a.content=f.concat(l,g);a.updateInnerHTML();a.taint();c.set(e,e);a.selection(c);d(!0);return this.dispatchEditorEvent("tool-applied",b)}};return a}(g.Tool);g.Tools.Image=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"image");a.label="Image";a.icon="image";a.canApply=function(a,
c){return a.isFixed()&&"ImageFixture"!==a.type()?!1:!0};a.apply=function(a,c,d){var b={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b)){a.storeState&&a.storeState();c=g.EditorApp.get();var e=new g.ModalUI;var f=new g.ImageDialog;f.addEventListener("cancel",function(b){return function(){e.hide();f.hide();a.restoreState&&a.restoreState();return d(!1)}}(this));f.addEventListener("save",function(c){return function(g){var h=g.detail();var k=h.imageURL;g=h.imageSize;(h=h.imageAttrs)||
(h={});h.height=g[1];h.src=k;h.width=g[0];"ImageFixture"===a.type()?a.src(k):(g=new ContentEdit.Image(h),h=c._insertAt(a),k=h[0],h=h[1],k.parent().attach(g,h),g.focus());e.hide();f.hide();d(!0);return c.dispatchEditorEvent("tool-applied",b)}}(this));c.attach(e);c.attach(f);e.show();return f.show()}};return a}(g.Tool);g.Tools.Video=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"video");a.label="Video";a.icon="video";a.canApply=function(a,c){return!a.isFixed()};
a.apply=function(a,c,d){var b={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",b)){a.storeState&&a.storeState();c=g.EditorApp.get();var e=new g.ModalUI;var f=new g.VideoDialog;f.addEventListener("cancel",function(b){return function(){e.hide();f.hide();a.restoreState&&a.restoreState();return d(!1)}}(this));f.addEventListener("save",function(c){return function(h){var k;if(k=h.detail().url){var l=new ContentEdit.Video("iframe",{frameborder:0,height:g.DEFAULT_VIDEO_HEIGHT,src:k,
width:g.DEFAULT_VIDEO_WIDTH});var m=c._insertAt(a);h=m[0];m=m[1];h.parent().attach(l,m);l.focus()}else a.restoreState&&a.restoreState();e.hide();f.hide();h=""!==k;d(h);if(h)return c.dispatchEditorEvent("tool-applied",b)}}(this));c.attach(e);c.attach(f);e.show();return f.show()}};return a}(g.Tool);g.Tools.Undo=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"undo");a.label="Undo";a.icon="undo";a.requiresElement=!1;a.canApply=function(a,c){var b=
g.EditorApp.get();return b.history&&b.history.canUndo()};a.apply=function(a,c,d){d={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",d))return a=this.editor(),a.history.stopWatching(),c=a.history.undo(),a.revertToSnapshot(c),a.history.watch(),this.dispatchEditorEvent("tool-applied",d)};return a}(g.Tool);g.Tools.Redo=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"redo");a.label="Redo";a.icon="redo";a.requiresElement=
!1;a.canApply=function(a,c){var b=g.EditorApp.get();return b.history&&b.history.canRedo()};a.apply=function(a,c,d){d={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",d))return a=g.EditorApp.get(),a.history.stopWatching(),c=a.history.redo(),a.revertToSnapshot(c),a.history.watch(),this.dispatchEditorEvent("tool-applied",d)};return a}(g.Tool);g.Tools.Remove=function(c){function a(){return a.__super__.constructor.apply(this,arguments)}l(a,c);g.ToolShelf.stow(a,"remove");a.label=
"Remove";a.icon="remove";a.canApply=function(a,c){return!a.isFixed()};a.apply=function(a,c,d){c={tool:this,element:a,selection:c};if(this.dispatchEditorEvent("tool-apply",c)){var b=this.editor();a.blur();a.nextContent()?a.nextContent().focus():a.previousContent()&&a.previousContent().focus();if(a.isMounted()){switch(a.type()){case "ListItemText":b.ctrlDown()?(a=a.closest(function(a){return"Region"===a.parent().type()}),a.parent().detach(a)):a.parent().parent().detach(a.parent());break;case "TableCellText":b.ctrlDown()?
(a=a.closest(function(a){return"Table"===a.type()}),a.parent().detach(a)):(a=a.parent().parent(),a.parent().detach(a));break;default:a.parent().detach(a)}d(!0);return this.dispatchEditorEvent("tool-applied",c)}d(!0);this.dispatchEditorEvent("tool-applied",c)}};return a}(g.Tool)}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment