text: /*! ContentTools v0.1.0 by Anthony Blackshaw <ant@getme.co.uk> (https://github.com/anthonyjb) */
  (function(){window.FSM={},FSM.Machine=function(){function Machine(context){this.context=context,this._stateTransitions={},this._stateTransitionsAny={},this._defaultTransition=null,this._initialState=null,this._currentState=null}return Machine.prototype.addTransition=function(action,state,nextState,callback){return nextState||(nextState=state),this._stateTransitions[[action,state]]=[nextState,callback]},Machine.prototype.addTransitions=function(actions,state,nextState,callback){var action,_i,_len,_results;for(nextState||(nextState=state),_results=[],_i=0,_len=actions.length;_len>_i;_i++)action=actions[_i],_results.push(this.addTransition(action,state,nextState,callback));return _results},Machine.prototype.addTransitionAny=function(state,nextState,callback){return nextState||(nextState=state),this._stateTransitionsAny[state]=[nextState,callback]},Machine.prototype.setDefaultTransition=function(state,callback){return this._defaultTransition=[state,callback]},Machine.prototype.getTransition=function(action,state){if(this._stateTransitions[[action,state]])return this._stateTransitions[[action,state]];if(this._stateTransitionsAny[state])return this._stateTransitionsAny[state];if(this._defaultTransition)return this._defaultTransition;throw new Error("Transition is undefined: ("+action+", "+state+")")},Machine.prototype.getCurrentState=function(){return this._currentState},Machine.prototype.setInitialState=function(state){return this._initialState=state,this._currentState?void 0:this.reset()},Machine.prototype.reset=function(){return this._currentState=this._initialState},Machine.prototype.process=function(action){var result;return result=this.getTransition(action,this._currentState),result[1]&&result[1].call(this.context||(this.context=this),action),this._currentState=result[0]},Machine}()}).call(this),function(){var ALPHA_CHARS,ALPHA_NUMERIC_CHARS,ATTR_DELIM,ATTR_ENTITY_DOUBLE_DELIM,ATTR_ENTITY_NO_DELIM,ATTR_ENTITY_SINGLE_DELIM,ATTR_NAME,ATTR_NAME_FIND_VALUE,ATTR_OR_TAG_END,ATTR_VALUE_DOUBLE_DELIM,ATTR_VALUE_NO_DELIM,ATTR_VALUE_SINGLE_DELIM,CHAR_OR_ENTITY_OR_TAG,CLOSING_TAG,ENTITY,ENTITY_CHARS,OPENING_TAG,OPENNING_OR_CLOSING_TAG,TAG_NAME_CLOSING,TAG_NAME_MUST_CLOSE,TAG_NAME_OPENING,TAG_OPENING_SELF_CLOSING,_Parser,__slice=[].slice,__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;l>i;i++)if(i in this&&this[i]===item)return i;return-1};window.HTMLString={},HTMLString.String=function(){function String(html,preserveWhitespace){null==preserveWhitespace&&(preserveWhitespace=!1),this._preserveWhitespace=preserveWhitespace,html?(null===HTMLString.String._parser&&(HTMLString.String._parser=new _Parser),this.characters=HTMLString.String._parser.parse(html,this._preserveWhitespace).characters):this.characters=[]}return String._parser=null,String.prototype.isWhitespace=function(){var c,_i,_len,_ref;for(_ref=this.characters,_i=0,_len=_ref.length;_len>_i;_i++)if(c=_ref[_i],!c.isWhitespace())return!1;return!0},String.prototype.length=function(){return this.characters.length},String.prototype.preserveWhitespace=function(){return this._preserveWhitespace},String.prototype.capitalize=function(){var c,newString;return newString=this.copy(),newString.length()&&(c=newString.characters[0]._c.toUpperCase(),newString.characters[0]._c=c),newString},String.prototype.charAt=function(index){return this.characters[index].copy()},String.prototype.concat=function(){var c,indexChar,inheritFormat,inheritedTags,newString,string,strings,tail,_i,_j,_k,_l,_len,_len1,_len2,_ref,_ref1;for(strings=2<=arguments.length?__slice.call(arguments,0,_i=arguments.length-1):(_i=0,[]),inheritFormat=arguments[_i++],"undefined"!=typeof inheritFormat&&"boolean"!=typeof inheritFormat&&(strings.push(inheritFormat),inheritFormat=!0),newString=this.copy(),_j=0,_len=strings.length;_len>_j;_j++)if(string=strings[_j],0!==string.length){if(tail=string,"string"==typeof string&&(tail=new HTMLString.String(string,this._preserveWhitespace)),inheritFormat&&newString.length())for(indexChar=newString.charAt(newString.length()-1),inheritedTags=indexChar.tags(),indexChar.isTag()&&inheritedTags.shift(),"string"!=typeof string&&(tail=tail.copy()),_ref=tail.characters,_k=0,_len1=_ref.length;_len1>_k;_k++)c=_ref[_k],c.addTags.apply(c,inheritedTags);for(_ref1=tail.characters,_l=0,_len2=_ref1.length;_len2>_l;_l++)c=_ref1[_l],newString.characters.push(c)}return newString},String.prototype.contains=function(substring){var c,found,from,i,_i,_len,_ref;if("string"==typeof substring)return this.text().indexOf(substring)>-1;for(from=0;from<=this.length()-substring.length();){for(found=!0,_ref=substring.characters,i=_i=0,_len=_ref.length;_len>_i;i=++_i)if(c=_ref[i],!c.eq(this.characters[i+from])){found=!1;break}if(found)return!0;from++}return!1},String.prototype.endsWith=function(substring){var c,characters,i,_i,_len,_ref;if("string"==typeof substring)return""===substring||this.text().slice(-substring.length)===substring;for(characters=this.characters.slice().reverse(),_ref=substring.characters.slice().reverse(),i=_i=0,_len=_ref.length;_len>_i;i=++_i)if(c=_ref[i],!c.eq(characters[i]))return!1;return!0},String.prototype.format=function(){var c,from,i,newString,tags,to,_i;for(from=arguments[0],to=arguments[1],tags=3<=arguments.length?__slice.call(arguments,2):[],0>to&&(to=this.length()+to+1),0>from&&(from=this.length()+from),newString=this.copy(),i=_i=from;to>=from?to>_i:_i>to;i=to>=from?++_i:--_i)c=newString.characters[i],c.addTags.apply(c,tags);return newString},String.prototype.hasTags=function(){var c,found,strict,tags,_i,_j,_len,_ref;for(tags=2<=arguments.length?__slice.call(arguments,0,_i=arguments.length-1):(_i=0,[]),strict=arguments[_i++],"undefined"!=typeof strict&&"boolean"!=typeof strict&&(tags.push(strict),strict=!1),found=!1,_ref=this.characters,_j=0,_len=_ref.length;_len>_j;_j++)if(c=_ref[_j],c.hasTags.apply(c,tags))found=!0;else if(strict)return!1;return found},String.prototype.html=function(){var c,closingTag,closingTags,head,html,openHeads,openTag,openTags,tag,_i,_j,_k,_l,_len,_len1,_len2,_len3,_len4,_m,_ref,_ref1,_ref2,_ref3;for(html="",openTags=[],openHeads=[],closingTags=[],_ref=this.characters,_i=0,_len=_ref.length;_len>_i;_i++){for(c=_ref[_i],closingTags=[],_ref1=openTags.slice().reverse(),_j=0,_len1=_ref1.length;_len1>_j;_j++)if(openTag=_ref1[_j],closingTags.push(openTag),!c.hasTags(openTag)){for(_k=0,_len2=closingTags.length;_len2>_k;_k++)closingTag=closingTags[_k],html+=closingTag.tail(),openTags.pop(),openHeads.pop();closingTags=[]}for(_ref2=c._tags,_l=0,_len3=_ref2.length;_len3>_l;_l++)tag=_ref2[_l],-1===openHeads.indexOf(tag.head())&&(tag.selfClosing()||(head=tag.head(),html+=head,openTags.push(tag),openHeads.push(head)));c._tags.length>0&&c._tags[0].selfClosing()&&(html+=c._tags[0].head()),html+=c.c()}for(_ref3=openTags.reverse(),_m=0,_len4=_ref3.length;_len4>_m;_m++)tag=_ref3[_m],html+=tag.tail();return html},String.prototype.indexOf=function(substring,from){var c,found,i,_i,_len,_ref;if(null==from&&(from=0),0>from&&(from=0),"string"==typeof substring)return this.text().indexOf(substring,from);for(;from<=this.length()-substring.length();){for(found=!0,_ref=substring.characters,i=_i=0,_len=_ref.length;_len>_i;i=++_i)if(c=_ref[i],!c.eq(this.characters[i+from])){found=!1;break}if(found)return from;from++}return-1},String.prototype.insert=function(index,substring,inheritFormat){var c,head,indexChar,inheritedTags,middle,newString,tail,_i,_j,_k,_len,_len1,_len2,_ref,_ref1,_ref2;if(null==inheritFormat&&(inheritFormat=!0),head=this.slice(0,index),tail=this.slice(index),0>index&&(index=this.length()+index),middle=substring,"string"==typeof substring&&(middle=new HTMLString.String(substring,this._preserveWhitespace)),inheritFormat&&index>0)for(indexChar=this.charAt(index-1),inheritedTags=indexChar.tags(),indexChar.isTag()&&inheritedTags.shift(),"string"!=typeof substring&&(middle=middle.copy()),_ref=middle.characters,_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],c.addTags.apply(c,inheritedTags);for(newString=head,_ref1=middle.characters,_j=0,_len1=_ref1.length;_len1>_j;_j++)c=_ref1[_j],newString.characters.push(c);for(_ref2=tail.characters,_k=0,_len2=_ref2.length;_len2>_k;_k++)c=_ref2[_k],newString.characters.push(c);return newString},String.prototype.lastIndexOf=function(substring,from){var c,characters,found,i,skip,_i,_j,_len,_len1;if(null==from&&(from=0),0>from&&(from=0),characters=this.characters.slice(from).reverse(),from=0,"string"==typeof substring){if(!this.contains(substring))return-1;for(substring=substring.split("").reverse();from<=characters.length-substring.length;){for(found=!0,skip=0,i=_i=0,_len=substring.length;_len>_i;i=++_i)if(c=substring[i],characters[i+from].isTag()&&(skip+=1),c!==characters[skip+i+from].c()){found=!1;break}if(found)return from;from++}return-1}for(substring=substring.characters.slice().reverse();from<=characters.length-substring.length;){for(found=!0,i=_j=0,_len1=substring.length;_len1>_j;i=++_j)if(c=substring[i],!c.eq(characters[i+from])){found=!1;break}if(found)return from;from++}return-1},String.prototype.optimize=function(){var c,closingTag,closingTags,head,lastC,len,openHeads,openTag,openTags,runLength,runLengthSort,runLengths,run_length,t,tag,_i,_j,_k,_l,_len,_len1,_len2,_len3,_len4,_len5,_len6,_m,_n,_o,_ref,_ref1,_ref2,_ref3,_ref4,_ref5,_results;for(openTags=[],openHeads=[],lastC=null,_ref=this.characters.slice().reverse(),_i=0,_len=_ref.length;_len>_i;_i++){for(c=_ref[_i],c._runLengthMap={},c._runLengthMapSize=0,closingTags=[],_ref1=openTags.slice().reverse(),_j=0,_len1=_ref1.length;_len1>_j;_j++)if(openTag=_ref1[_j],closingTags.push(openTag),!c.hasTags(openTag)){for(_k=0,_len2=closingTags.length;_len2>_k;_k++)closingTag=closingTags[_k],openTags.pop(),openHeads.pop();closingTags=[]}for(_ref2=c._tags,_l=0,_len3=_ref2.length;_len3>_l;_l++)tag=_ref2[_l],-1===openHeads.indexOf(tag.head())&&(tag.selfClosing()||(openTags.push(tag),openHeads.push(tag.head())));for(_m=0,_len4=openTags.length;_len4>_m;_m++)tag=openTags[_m],head=tag.head(),lastC?(c._runLengthMap[head]||(c._runLengthMap[head]=[tag,0]),run_length=0,lastC._runLengthMap[head]&&(run_length=lastC._runLengthMap[head][1]),c._runLengthMap[head][1]=run_length+1):c._runLengthMap[head]=[tag,1];lastC=c}for(runLengthSort=function(a,b){return b[1]-a[1]},_ref3=this.characters,_results=[],_n=0,_len5=_ref3.length;_len5>_n;_n++)if(c=_ref3[_n],len=c._tags.length,!(len>0&&c._tags[0].selfClosing()&&3>len||2>len)){runLengths=[],_ref4=c._runLengthMap;for(tag in _ref4)runLength=_ref4[tag],runLengths.push(runLength);for(runLengths.sort(runLengthSort),_ref5=c._tags.slice(),_o=0,_len6=_ref5.length;_len6>_o;_o++)tag=_ref5[_o],tag.selfClosing()||c.removeTags(tag);_results.push(c.addTags.apply(c,function(){var _len7,_p,_results1;for(_results1=[],_p=0,_len7=runLengths.length;_len7>_p;_p++)t=runLengths[_p],_results1.push(t[0]);return _results1}()))}return _results},String.prototype.slice=function(from,to){var c,newString;return newString=new HTMLString.String("",this._preserveWhitespace),newString.characters=function(){var _i,_len,_ref,_results;for(_ref=this.characters.slice(from,to),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c.copy());return _results}.call(this),newString},String.prototype.split=function(separator,limit){var count,i,index,indexes,lastIndex,substrings,_i,_ref;for(null==separator&&(separator=""),null==limit&&(limit=0),lastIndex=0,count=0,indexes=[0];;){if(limit>0&&count>limit)break;if(index=this.indexOf(separator,lastIndex),-1===index||index===this.length()-1)break;indexes.push(index),lastIndex=index+1}for(indexes.push(this.length()),substrings=[],i=_i=0,_ref=indexes.length-2;_ref>=0?_ref>=_i:_i>=_ref;i=_ref>=0?++_i:--_i)substrings.push(this.slice(indexes[i],indexes[i+1]));return substrings},String.prototype.startsWith=function(substring){var c,i,_i,_len,_ref;if("string"==typeof substring)return this.text().slice(0,substring.length)===substring;for(_ref=substring.characters,i=_i=0,_len=_ref.length;_len>_i;i=++_i)if(c=_ref[i],!c.eq(this.characters[i]))return!1;return!0},String.prototype.substr=function(from,length){return 0>=length?new HTMLString.String("",this._preserveWhitespace):(0>from&&(from=this.length()+from),void 0===length&&(length=this.length()-from),this.slice(from,from+length))},String.prototype.substring=function(from,to){return void 0===to&&(to=this.length()),this.slice(from,to)},String.prototype.text=function(){var c,text,_i,_len,_ref;for(text="",_ref=this.characters,_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],c.isTag()?c.isTag("br")&&(text+="\n"):text+=("&nbsp;"!==c.c(),c.c());return this.constructor.decode(text)},String.prototype.toLowerCase=function(){var c,newString,_i,_len,_ref;for(newString=this.copy(),_ref=newString.characters,_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],1===c._c.length&&(c._c=c._c.toLowerCase());return newString},String.prototype.toUpperCase=function(){var c,newString,_i,_len,_ref;for(newString=this.copy(),_ref=newString.characters,_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],1===c._c.length&&(c._c=c._c.toUpperCase());return newString},String.prototype.trim=function(){var c,from,newString,to,_i,_j,_len,_len1,_ref,_ref1;for(_ref=this.characters,from=_i=0,_len=_ref.length;_len>_i&&(c=_ref[from],c.isWhitespace());from=++_i);for(_ref1=this.characters.slice().reverse(),to=_j=0,_len1=_ref1.length;_len1>_j&&(c=_ref1[to],c.isWhitespace());to=++_j);return to=this.length()-to-1,newString=new HTMLString.String("",this._preserveWhitespace),newString.characters=function(){var _k,_len2,_ref2,_results;for(_ref2=this.characters.slice(from,+to+1||9e9),_results=[],_k=0,_len2=_ref2.length;_len2>_k;_k++)c=_ref2[_k],_results.push(c.copy());return _results}.call(this),newString},String.prototype.trimLeft=function(){var c,from,newString,to,_i,_len,_ref;for(to=this.length()-1,_ref=this.characters,from=_i=0,_len=_ref.length;_len>_i&&(c=_ref[from],c.isWhitespace());from=++_i);return newString=new HTMLString.String("",this._preserveWhitespace),newString.characters=function(){var _j,_len1,_ref1,_results;for(_ref1=this.characters.slice(from,+to+1||9e9),_results=[],_j=0,_len1=_ref1.length;_len1>_j;_j++)c=_ref1[_j],_results.push(c.copy());return _results}.call(this),newString},String.prototype.trimRight=function(){var c,from,newString,to,_i,_len,_ref;for(from=0,_ref=this.characters.slice().reverse(),to=_i=0,_len=_ref.length;_len>_i&&(c=_ref[to],c.isWhitespace());to=++_i);return to=this.length()-to-1,newString=new HTMLString.String("",this._preserveWhitespace),newString.characters=function(){var _j,_len1,_ref1,_results;for(_ref1=this.characters.slice(from,+to+1||9e9),_results=[],_j=0,_len1=_ref1.length;_len1>_j;_j++)c=_ref1[_j],_results.push(c.copy());return _results}.call(this),newString},String.prototype.unformat=function(){var c,from,i,newString,tags,to,_i;for(from=arguments[0],to=arguments[1],tags=3<=arguments.length?__slice.call(arguments,2):[],0>to&&(to=this.length()+to+1),0>from&&(from=this.length()+from),newString=this.copy(),i=_i=from;to>=from?to>_i:_i>to;i=to>=from?++_i:--_i)c=newString.characters[i],c.removeTags.apply(c,tags);return newString},String.prototype.copy=function(){var c,stringCopy;return stringCopy=new HTMLString.String("",this._preserveWhitespace),stringCopy.characters=function(){var _i,_len,_ref,_results;for(_ref=this.characters,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c.copy());return _results}.call(this),stringCopy},String.encode=function(string){var textarea;return textarea=document.createElement("textarea"),textarea.textContent=string,textarea.innerHTML},String.decode=function(string){var textarea;return textarea=document.createElement("textarea"),textarea.innerHTML=string,textarea.textContent},String}(),ALPHA_CHARS="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-_$".split(""),ALPHA_NUMERIC_CHARS=ALPHA_CHARS.concat("1234567890".split("")),ENTITY_CHARS=ALPHA_NUMERIC_CHARS.concat(["#"]),CHAR_OR_ENTITY_OR_TAG=1,ENTITY=2,OPENNING_OR_CLOSING_TAG=3,OPENING_TAG=4,CLOSING_TAG=5,TAG_NAME_OPENING=6,TAG_NAME_CLOSING=7,TAG_OPENING_SELF_CLOSING=8,TAG_NAME_MUST_CLOSE=9,ATTR_OR_TAG_END=10,ATTR_NAME=11,ATTR_NAME_FIND_VALUE=12,ATTR_DELIM=13,ATTR_VALUE_SINGLE_DELIM=14,ATTR_VALUE_DOUBLE_DELIM=15,ATTR_VALUE_NO_DELIM=16,ATTR_ENTITY_NO_DELIM=17,ATTR_ENTITY_SINGLE_DELIM=18,ATTR_ENTITY_DOUBLE_DELIM=19,_Parser=function(){function _Parser(){this.fsm=new FSM.Machine(this),this.fsm.setInitialState(CHAR_OR_ENTITY_OR_TAG),this.fsm.addTransitionAny(CHAR_OR_ENTITY_OR_TAG,null,function(c){return this._pushChar(c)}),this.fsm.addTransition("<",CHAR_OR_ENTITY_OR_TAG,OPENNING_OR_CLOSING_TAG),this.fsm.addTransition("&",CHAR_OR_ENTITY_OR_TAG,ENTITY),this.fsm.addTransitions(ENTITY_CHARS,ENTITY,null,function(c){return this.entity+=c}),this.fsm.addTransition(";",ENTITY,CHAR_OR_ENTITY_OR_TAG,function(){return this._pushChar("&"+this.entity+";"),this.entity=""}),this.fsm.addTransitions([" ","\n"],OPENNING_OR_CLOSING_TAG),this.fsm.addTransitions(ALPHA_CHARS,OPENNING_OR_CLOSING_TAG,OPENING_TAG,function(){return this._back()}),this.fsm.addTransition("/",OPENNING_OR_CLOSING_TAG,CLOSING_TAG),this.fsm.addTransitions([" ","\n"],OPENING_TAG),this.fsm.addTransitions(ALPHA_CHARS,OPENING_TAG,TAG_NAME_OPENING,function(){return this._back()}),this.fsm.addTransitions([" ","\n"],CLOSING_TAG),this.fsm.addTransitions(ALPHA_CHARS,CLOSING_TAG,TAG_NAME_CLOSING,function(){return this._back()}),this.fsm.addTransitions(ALPHA_NUMERIC_CHARS,TAG_NAME_OPENING,null,function(c){return this.tagName+=c}),this.fsm.addTransitions([" ","\n"],TAG_NAME_OPENING,ATTR_OR_TAG_END),this.fsm.addTransition("/",TAG_NAME_OPENING,TAG_OPENING_SELF_CLOSING,function(){return this.selfClosing=!0}),this.fsm.addTransition(">",TAG_NAME_OPENING,CHAR_OR_ENTITY_OR_TAG,function(){return this._pushTag()}),this.fsm.addTransitions([" ","\n"],TAG_OPENING_SELF_CLOSING),this.fsm.addTransition(">",TAG_OPENING_SELF_CLOSING,CHAR_OR_ENTITY_OR_TAG,function(){return this._pushTag()}),this.fsm.addTransitions([" ","\n"],ATTR_OR_TAG_END),this.fsm.addTransition("/",ATTR_OR_TAG_END,TAG_OPENING_SELF_CLOSING,function(){return this.selfClosing=!0}),this.fsm.addTransition(">",ATTR_OR_TAG_END,CHAR_OR_ENTITY_OR_TAG,function(){return this._pushTag()}),this.fsm.addTransitions(ALPHA_CHARS,ATTR_OR_TAG_END,ATTR_NAME,function(){return this._back()}),this.fsm.addTransitions(ALPHA_NUMERIC_CHARS,TAG_NAME_CLOSING,null,function(c){return this.tagName+=c}),this.fsm.addTransitions([" ","\n"],TAG_NAME_CLOSING,TAG_NAME_MUST_CLOSE),this.fsm.addTransition(">",TAG_NAME_CLOSING,CHAR_OR_ENTITY_OR_TAG,function(){return this._popTag()}),this.fsm.addTransitions([" ","\n"],TAG_NAME_MUST_CLOSE),this.fsm.addTransition(">",TAG_NAME_MUST_CLOSE,CHAR_OR_ENTITY_OR_TAG,function(){return this._popTag()}),this.fsm.addTransitions(ALPHA_NUMERIC_CHARS,ATTR_NAME,null,function(c){return this.attributeName+=c}),this.fsm.addTransitions([" ","\n"],ATTR_NAME,ATTR_NAME_FIND_VALUE),this.fsm.addTransition("=",ATTR_NAME,ATTR_DELIM),this.fsm.addTransitions([" ","\n"],ATTR_NAME_FIND_VALUE),this.fsm.addTransition("=",ATTR_NAME_FIND_VALUE,ATTR_DELIM),this.fsm.addTransitions(">",ATTR_NAME,ATTR_OR_TAG_END,function(){return this._pushAttribute(),this._back()}),this.fsm.addTransitionAny(ATTR_NAME_FIND_VALUE,ATTR_OR_TAG_END,function(){return this._pushAttribute(),this._back()}),this.fsm.addTransitions([" ","\n"],ATTR_DELIM),this.fsm.addTransition("'",ATTR_DELIM,ATTR_VALUE_SINGLE_DELIM),this.fsm.addTransition('"',ATTR_DELIM,ATTR_VALUE_DOUBLE_DELIM),this.fsm.addTransitions(ALPHA_NUMERIC_CHARS.concat(["&"],ATTR_DELIM,ATTR_VALUE_NO_DELIM,function(){return this._back()})),this.fsm.addTransition(" ",ATTR_VALUE_NO_DELIM,ATTR_OR_TAG_END,function(){return this._pushAttribute()}),this.fsm.addTransitions(["/",">"],ATTR_VALUE_NO_DELIM,ATTR_OR_TAG_END,function(){return this._back(),this._pushAttribute()}),this.fsm.addTransition("&",ATTR_VALUE_NO_DELIM,ATTR_ENTITY_NO_DELIM),this.fsm.addTransitionAny(ATTR_VALUE_NO_DELIM,null,function(c){return this.attributeValue+=c}),this.fsm.addTransition("'",ATTR_VALUE_SINGLE_DELIM,ATTR_OR_TAG_END,function(){return this._pushAttribute()}),this.fsm.addTransition("&",ATTR_VALUE_SINGLE_DELIM,ATTR_ENTITY_SINGLE_DELIM),this.fsm.addTransitionAny(ATTR_VALUE_SINGLE_DELIM,null,function(c){return this.attributeValue+=c}),this.fsm.addTransition('"',ATTR_VALUE_DOUBLE_DELIM,ATTR_OR_TAG_END,function(){return this._pushAttribute()}),this.fsm.addTransition("&",ATTR_VALUE_DOUBLE_DELIM,ATTR_ENTITY_DOUBLE_DELIM),this.fsm.addTransitionAny(ATTR_VALUE_DOUBLE_DELIM,null,function(c){return this.attributeValue+=c}),this.fsm.addTransitions(ENTITY_CHARS,ATTR_ENTITY_NO_DELIM,null,function(c){return this.entity+=c}),this.fsm.addTransitions(ENTITY_CHARS,ATTR_ENTITY_SINGLE_DELIM,function(c){return this.entity+=c}),this.fsm.addTransitions(ENTITY_CHARS,ATTR_ENTITY_DOUBLE_DELIM,null,function(c){return this.entity+=c}),this.fsm.addTransition(";",ATTR_ENTITY_NO_DELIM,ATTR_VALUE_NO_DELIM,function(){return this.attributeValue+="&"+this.entity+";",this.entity=""}),this.fsm.addTransition(";",ATTR_ENTITY_SINGLE_DELIM,ATTR_VALUE_SINGLE_DELIM,function(){return this.attributeValue+="&"+this.entity+";",this.entity=""}),this.fsm.addTransition(";",ATTR_ENTITY_DOUBLE_DELIM,ATTR_VALUE_DOUBLE_DELIM,function(){return this.attributeValue+="&"+this.entity+";",this.entity=""})}return _Parser.prototype._back=function(){return this.head--},_Parser.prototype._pushAttribute=function(){return this.attributes[this.attributeName]=this.attributeValue,this.attributeName="",this.attributeValue=""},_Parser.prototype._pushChar=function(c){var character,lastCharacter;return character=new HTMLString.Character(c,this.tags),this._preserveWhitespace?void this.string.characters.push(character):!this.string.length()||character.isTag()||character.isEntity()||!character.isWhitespace()||(lastCharacter=this.string.characters[this.string.length()-1],!lastCharacter.isWhitespace()||lastCharacter.isTag()||lastCharacter.isEntity())?this.string.characters.push(character):void 0},_Parser.prototype._pushTag=function(){var tag,_ref;return tag=new HTMLString.Tag(this.tagName,this.attributes),this.tags.push(tag),tag.selfClosing()&&(this._pushChar(""),this.tags.pop(),!this.selfClosed&&(_ref=this.tagName,__indexOf.call(HTMLString.Tag.SELF_CLOSING,_ref)>=0)&&this.fsm.reset()),this.tagName="",this.selfClosed=!1,this.attributes=[]},_Parser.prototype._popTag=function(){for(var character,tag;;)if(tag=this.tags.pop(),this.string.length()&&(character=this.string.characters[this.string.length()-1],character.isTag()||character.isEntity()||!character.isWhitespace()||character.removeTags(tag)),tag.name()===this.tagName.toLowerCase())break;return this.tagName=""},_Parser.prototype.parse=function(html,preserveWhitespace){var character,error;for(this._preserveWhitespace=preserveWhitespace,this.reset(),html=this.preprocess(html),this.fsm.parser=this;this.head<html.length;){character=html[this.head];try{this.fsm.process(character)}catch(_error){throw error=_error,new Error("Error at char "+this.head+" >> "+error)}this.head++}return this.string},_Parser.prototype.preprocess=function(html){return html=html.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),html=html.replace(/<!--[\s\S]*?-->/g,""),this._preserveWhitespace||(html=html.replace(/\s+/g," ")),html},_Parser.prototype.reset=function(){return this.fsm.reset(),this.head=0,this.string=new HTMLString.String,this.entity="",this.tags=[],this.tagName="",this.selfClosing=!1,this.attributes={},this.attributeName="",this.attributeValue=""},_Parser}(),HTMLString.Tag=function(){function Tag(name,attributes){var k,v;this._name=name.toLowerCase(),this._selfClosing=HTMLString.Tag.SELF_CLOSING[this._name]===!0,this._head=null,this._attributes={};for(k in attributes)v=attributes[k],this._attributes[k]=v}return Tag.SELF_CLOSING={area:!0,base:!0,br:!0,hr:!0,img:!0,input:!0,"link meta":!0,wbr:!0},Tag.prototype.head=function(){var components,k,v,_ref;if(!this._head){components=[],_ref=this._attributes;for(k in _ref)v=_ref[k],components.push(v?""+k+'="'+v+'"':""+k);components.sort(),components.unshift(this._name),this._head="<"+components.join(" ")+">"}return this._head},Tag.prototype.name=function(){return this._name},Tag.prototype.selfClosing=function(){return this._selfClosing},Tag.prototype.tail=function(){return this._selfClosing?"":"</"+this._name+">"},Tag.prototype.attr=function(name,value){return void 0===value?this._attributes[name]:(this._attributes[name]=value,this._head=null)},Tag.prototype.removeAttr=function(name){return void 0!==this._attributes[name]?delete this._attributes[name]:void 0},Tag.prototype.copy=function(){return new HTMLString.Tag(this._name,this._attributes)},Tag}(),HTMLString.Character=function(){function Character(c,tags){this._c=c,c.length>1&&(this._c=c.toLowerCase()),this._tags=[],this.addTags.apply(this,tags)}return Character.prototype.c=function(){return this._c},Character.prototype.isEntity=function(){return this._c.length>1},Character.prototype.isTag=function(tagName){return 0!==this._tags.length&&this._tags[0].selfClosing()?tagName&&this._tags[0].name()!==tagName?!1:!0:!1},Character.prototype.isWhitespace=function(){var _ref;return" "===(_ref=this._c)||"\n"===_ref||"&nbsp;"===_ref||this.isTag("br")},Character.prototype.tags=function(){var t;return function(){var _i,_len,_ref,_results;for(_ref=this._tags,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)t=_ref[_i],_results.push(t.copy());return _results}.call(this)},Character.prototype.addTags=function(){var tag,tags,_i,_len,_results;for(tags=1<=arguments.length?__slice.call(arguments,0):[],_results=[],_i=0,_len=tags.length;_len>_i;_i++)tag=tags[_i],tag.selfClosing()?this.isTag()||this._tags.unshift(tag.copy()):_results.push(this._tags.push(tag.copy()));return _results},Character.prototype.eq=function(c){var tag,tags,_i,_j,_len,_len1,_ref,_ref1;if(this.c()!==c.c())return!1;if(this._tags.length!==c._tags.length)return!1;for(tags={},_ref=this._tags,_i=0,_len=_ref.length;_len>_i;_i++)tag=_ref[_i],tags[tag.head()]=!0;for(_ref1=c._tags,_j=0,_len1=_ref1.length;_len1>_j;_j++)if(tag=_ref1[_j],!tags[tag.head()])return!1;return!0},Character.prototype.hasTags=function(){var tag,tagHeads,tagNames,tags,_i,_j,_len,_len1,_ref;for(tags=1<=arguments.length?__slice.call(arguments,0):[],tagNames={},tagHeads={},_ref=this._tags,_i=0,_len=_ref.length;_len>_i;_i++)tag=_ref[_i],tagNames[tag.name()]=!0,tagHeads[tag.head()]=!0;for(_j=0,_len1=tags.length;_len1>_j;_j++)if(tag=tags[_j],"string"==typeof tag){if(void 0===tagNames[tag])return!1}else if(void 0===tagHeads[tag.head()])return!1;return!0},Character.prototype.removeTags=function(){var heads,names,newTags,tag,tags,_i,_len;if(tags=1<=arguments.length?__slice.call(arguments,0):[],0===tags.length)return void(this._tags=[]);for(names={},heads={},_i=0,_len=tags.length;_len>_i;_i++)tag=tags[_i],"string"==typeof tag?names[tag]=tag:heads[tag.head()]=tag;return newTags=[],this._tags=this._tags.filter(function(tag){return heads[tag.head()]||names[tag.name()]?void 0:tag})},Character.prototype.copy=function(){var t;return new HTMLString.Character(this._c,function(){var _i,_len,_ref,_results;for(_ref=this._tags,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)t=_ref[_i],_results.push(t.copy());return _results}.call(this))},Character}()}.call(this),function(){var SELF_CLOSING_NODE_NAMES,_containedBy,_getChildNodeAndOffset,_getNodeRange,_getOffsetOfChildNode,__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;l>i;i++)if(i in this&&this[i]===item)return i;return-1};window.ContentSelect={},ContentSelect.Range=function(){function Range(from,to){this.set(from,to)}return Range.prototype.isCollapsed=function(){return this._from===this._to},Range.prototype.span=function(){return this._to-this._from},Range.prototype.collapse=function(){return this._to=this._from},Range.prototype.eq=function(range){return this.get()[0]===range.get()[0]&&this.get()[1]===range.get()[1]},Range.prototype.get=function(){return[this._from,this._to]},Range.prototype.select=function(element){var docRange,endNode,endOffset,startNode,startOffset,_ref,_ref1;return ContentSelect.Range.unselectAll(),docRange=document.createRange(),_ref=_getChildNodeAndOffset(element,this._from),startNode=_ref[0],startOffset=_ref[1],_ref1=_getChildNodeAndOffset(element,this._to),endNode=_ref1[0],endOffset=_ref1[1],docRange.setStart(startNode,startOffset),docRange.setEnd(endNode,endOffset),window.getSelection().addRange(docRange)},Range.prototype.set=function(from,to){return from=Math.max(0,from),to=Math.max(0,to),this._from=Math.min(from,to),this._to=Math.max(from,to)},Range.prepareElement=function(element){var i,node,selfClosingNodes,_i,_len,_results;for(selfClosingNodes=element.querySelectorAll(SELF_CLOSING_NODE_NAMES.join(", ")),_results=[],i=_i=0,_len=selfClosingNodes.length;_len>_i;i=++_i)node=selfClosingNodes[i],node.parentNode.insertBefore(document.createTextNode(""),node),_results.push(i<selfClosingNodes.length-1?node.parentNode.insertBefore(document.createTextNode(""),node.nextSibling):void 0);return _results},Range.query=function(element){var docRange,endNode,endOffset,range,startNode,startOffset,_ref;range=new ContentSelect.Range(0,0);try{docRange=window.getSelection().getRangeAt(0)}catch(_error){return range}return null===element.firstChild&&null===element.lastChild?range:_containedBy(docRange.startContainer,element)&&_containedBy(docRange.endContainer,element)?(_ref=_getNodeRange(element,docRange),startNode=_ref[0],startOffset=_ref[1],endNode=_ref[2],endOffset=_ref[3],range.set(_getOffsetOfChildNode(element,startNode)+startOffset,_getOffsetOfChildNode(element,endNode)+endOffset),range):range},Range.rect=function(){var docRange,marker,rect;try{docRange=window.getSelection().getRangeAt(0)}catch(_error){return null}return docRange.collapsed?(marker=document.createElement("span"),docRange.insertNode(marker),rect=marker.getBoundingClientRect(),marker.parentNode.removeChild(marker),rect):docRange.getBoundingClientRect()},Range.unselectAll=function(){return window.getSelection()?window.getSelection().removeAllRanges():void 0},Range}(),SELF_CLOSING_NODE_NAMES=["br","img","input"],_containedBy=function(nodeA,nodeB){for(;nodeA;){if(nodeA===nodeB)return!0;nodeA=nodeA.parentNode}return!1},_getChildNodeAndOffset=function(parentNode,parentOffset){var childNode,childOffset,childStack,n,_ref;if(0===parentNode.childNodes.length)return[parentNode,parentOffset];for(childNode=null,childOffset=parentOffset,childStack=function(){var _i,_len,_ref,_results;for(_ref=parentNode.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)n=_ref[_i],_results.push(n);return _results}();childStack.length>0;)switch(childNode=childStack.shift(),childNode.nodeType){case Node.TEXT_NODE:if(childNode.textContent.length>=childOffset)return[childNode,childOffset];childOffset-=childNode.textContent.length;break;case Node.ELEMENT_NODE:if(_ref=childNode.nodeName.toLowerCase(),__indexOf.call(SELF_CLOSING_NODE_NAMES,_ref)>=0){if(0===childOffset)return[childNode,0];childOffset=Math.max(0,childOffset-1)}else childNode.childNodes&&Array.prototype.unshift.apply(childStack,function(){var _i,_len,_ref1,_results;for(_ref1=childNode.childNodes,_results=[],_i=0,_len=_ref1.length;_len>_i;_i++)n=_ref1[_i],_results.push(n);return _results}())}return[childNode,childOffset]},_getOffsetOfChildNode=function(parentNode,childNode){var childStack,n,offset,otherChildNode,_ref,_ref1;if(0===parentNode.childNodes.length)return 0;for(offset=0,childStack=function(){var _i,_len,_ref,_results;for(_ref=parentNode.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)n=_ref[_i],_results.push(n);return _results}();childStack.length>0;){if(otherChildNode=childStack.shift(),otherChildNode===childNode)return _ref=otherChildNode.nodeName.toLowerCase(),__indexOf.call(SELF_CLOSING_NODE_NAMES,_ref)>=0?offset+1:offset;switch(otherChildNode.nodeType){case Node.TEXT_NODE:offset+=otherChildNode.textContent.length;break;case Node.ELEMENT_NODE:_ref1=otherChildNode.nodeName.toLowerCase(),__indexOf.call(SELF_CLOSING_NODE_NAMES,_ref1)>=0?offset+=1:otherChildNode.childNodes&&Array.prototype.unshift.apply(childStack,function(){var _i,_len,_ref2,_results;
  for(_ref2=otherChildNode.childNodes,_results=[],_i=0,_len=_ref2.length;_len>_i;_i++)n=_ref2[_i],_results.push(n);return _results}())}}return offset},_getNodeRange=function(element,docRange){var childNode,childNodes,endNode,endOffset,endRange,i,startNode,startOffset,startRange,_i,_j,_len,_len1,_ref;if(childNodes=element.childNodes,startRange=docRange.cloneRange(),startRange.collapse(!0),endRange=docRange.cloneRange(),endRange.collapse(!1),startNode=startRange.startContainer,startOffset=startRange.startOffset,endNode=endRange.endContainer,endOffset=endRange.endOffset,!startRange.comparePoint)return[startNode,startOffset,endNode,endOffset];if(startNode===element)for(startNode=childNodes[childNodes.length-1],startOffset=startNode.textContent.length,i=_i=0,_len=childNodes.length;_len>_i;i=++_i)if(childNode=childNodes[i],1===startRange.comparePoint(childNode,0)){0===i?(startNode=childNode,startOffset=0):(startNode=childNodes[i-1],startOffset=childNode.textContent.length),_ref=startNode.nodeName.toLowerCase,__indexOf.call(SELF_CLOSING_NODE_NAMES,_ref)>=0&&(startOffset=1);break}if(docRange.collapsed)return[startNode,startOffset,startNode,startOffset];if(endNode===element)for(endNode=childNodes[childNodes.length-1],endOffset=endNode.textContent.length,i=_j=0,_len1=childNodes.length;_len1>_j;i=++_j)childNode=childNodes[i],1===endRange.comparePoint(childNode,0)&&(endNode=0===i?childNode:childNodes[i-1],endOffset=childNode.textContent.length+1);return[startNode,startOffset,endNode,endOffset]}}.call(this),function(){var C,_Root,_TagNames,_mergers,__slice=[].slice,__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;l>i;i++)if(i in this&&this[i]===item)return i;return-1},__hasProp={}.hasOwnProperty,__extends=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},__bind=function(fn,me){return function(){return fn.apply(me,arguments)}};window.ContentEdit={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",RESIZE_CORNER_SIZE:15,_translations:{},_:function(s){var lang;return lang=ContentEdit.LANGUAGE,ContentEdit._translations[lang]&&ContentEdit._translations[lang][s]?ContentEdit._translations[lang][s]:s},addTranslations:function(language,translations){return ContentEdit._translations[language]=translations},addCSSClass:function(domElement,className){var c,classAttr,classNames;return domElement.classList?void domElement.classList.add(className):(classAttr=domElement.getAttribute("class"),classAttr?(classNames=function(){var _i,_len,_ref,_results;for(_ref=classAttr.split(" "),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),-1===classNames.indexOf(className)?domElement.setAttribute("class",""+classAttr+" "+className):void 0):domElement.setAttribute("class",className))},attributesToString:function(attributes){var attributeStrings,name,names,value,_i,_len;if(!attributes)return"";for(names=function(){var _results;_results=[];for(name in attributes)_results.push(name);return _results}(),names.sort(),attributeStrings=[],_i=0,_len=names.length;_len>_i;_i++)name=names[_i],value=attributes[name],attributeStrings.push(""===value?name:""+name+'="'+value+'"');return attributeStrings.join(" ")},removeCSSClass:function(domElement,className){var c,classAttr,classNameIndex,classNames;return domElement.classList?(domElement.classList.remove(className),void(0===domElement.classList.length&&domElement.removeAttribute("class"))):(classAttr=domElement.getAttribute("class"),classAttr?(classNames=function(){var _i,_len,_ref,_results;for(_ref=classAttr.split(" "),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),classNameIndex=classNames.indexOf(className),classNameIndex>-1?(classNames.splice(classNameIndex,1),classNames.length?domElement.setAttribute("class",classNames.join(" ")):domElement.removeAttribute("class")):void 0):domElement.setAttribute("class",className))}},(C=function(){function C(){}return C}()).name||Object.defineProperty(Function.prototype,"name",{get:function(){var name;return name=this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1],Object.defineProperty(this,"name",{value:name}),name}}),_TagNames=function(){function _TagNames(){this._tagNames={}}return _TagNames.prototype.register=function(){var cls,tagName,tagNames,_i,_len,_results;for(cls=arguments[0],tagNames=2<=arguments.length?__slice.call(arguments,1):[],_results=[],_i=0,_len=tagNames.length;_len>_i;_i++)tagName=tagNames[_i],_results.push(this._tagNames[tagName.toLowerCase()]=cls);return _results},_TagNames.prototype.match=function(tagName){return this._tagNames[tagName.toLowerCase()]?this._tagNames[tagName.toLowerCase()]:ContentEdit.Static},_TagNames}(),ContentEdit.TagNames=function(){function TagNames(){}var instance;return instance=null,TagNames.get=function(){return null!=instance?instance:instance=new _TagNames},TagNames}(),ContentEdit.Node=function(){function Node(){this._bindings={},this._parent=null,this._modified=null}return Node.prototype.lastModified=function(){return this._modified},Node.prototype.parent=function(){return this._parent},Node.prototype.parents=function(){var parent,parents;for(parents=[],parent=this._parent;parent;)parents.push(parent),parent=parent._parent;return parents},Node.prototype.html=function(indent){throw null==indent&&(indent=""),new Error("`html` not implemented")},Node.prototype.bind=function(eventName,callback){return void 0===this._bindings[eventName]&&(this._bindings[eventName]=[]),this._bindings[eventName].push(callback),callback},Node.prototype.trigger=function(){var args,callback,eventName,_i,_len,_ref,_results;if(eventName=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[],this._bindings[eventName]){for(_ref=this._bindings[eventName],_results=[],_i=0,_len=_ref.length;_len>_i;_i++)callback=_ref[_i],callback&&_results.push(callback.call.apply(callback,[this].concat(__slice.call(args))));return _results}},Node.prototype.unbind=function(eventName,callback){var i,suspect,_i,_len,_ref,_results;if(!eventName)return void(this._bindings={});if(!callback)return void(this._bindings[eventName]=void 0);if(this._bindings[eventName]){for(_ref=this._bindings[eventName],_results=[],i=_i=0,_len=_ref.length;_len>_i;i=++_i)suspect=_ref[i],_results.push(suspect===callback?this._bindings[eventName].splice(i,1):void 0);return _results}},Node.prototype.commit=function(){return this._modified=null,ContentEdit.Root.get().trigger("commit",this)},Node.prototype.taint=function(){var now,parent,root,_i,_len,_ref;for(now=Date.now(),this._modified=now,_ref=this.parents(),_i=0,_len=_ref.length;_len>_i;_i++)parent=_ref[_i],parent._modified=now;return root=ContentEdit.Root.get(),root._modified=now,root.trigger("taint",this)},Node.prototype.closest=function(testFunc){var parent;for(parent=this.parent();parent&&!testFunc(parent);)parent=parent.parent?parent.parent():null;return parent},Node.prototype.next=function(){var children,index,node,_i,_len,_ref;if(this.children&&this.children.length>0)return this.children[0];for(_ref=[this].concat(this.parents()),_i=0,_len=_ref.length;_len>_i;_i++){if(node=_ref[_i],!node.parent())return null;if(children=node.parent().children,index=children.indexOf(node),index<children.length-1)return children[index+1]}},Node.prototype.nextContent=function(){return this.nextWithTest(function(node){return void 0!==node.content})},Node.prototype.nextSibling=function(){var index;return index=this.parent().children.indexOf(this),index===this.parent().children.length-1?null:this.parent().children[index+1]},Node.prototype.nextWithTest=function(testFunc){var node;for(node=this;node;)if(node=node.next(),node&&testFunc(node))return node},Node.prototype.previous=function(){var children,node;if(!this.parent())return null;if(children=this.parent().children,children[0]===this)return this.parent();for(node=children[children.indexOf(this)-1];node.children&&node.children.length;)node=node.children[node.children.length-1];return node},Node.prototype.previousContent=function(){var node;return node=this.previousWithTest(function(node){return void 0!==node.content})},Node.prototype.previousSibling=function(){var index;return index=this.parent().children.indexOf(this),0===index?null:this.parent().children[index-1]},Node.prototype.previousWithTest=function(testFunc){var node;for(node=this;node;)if(node=node.previous(),node&&testFunc(node))return node},Node.extend=function(cls){var key,value,_ref;_ref=cls.prototype;for(key in _ref)value=_ref[key],"constructor"!==key&&(this.prototype[key]=value);for(key in cls)value=cls[key],__indexOf.call("__super__",key)>=0||(this.prototype[key]=value);return this},Node.fromDOMElement=function(){throw new Error("`fromDOMElement` not implemented")},Node}(),ContentEdit.NodeCollection=function(_super){function NodeCollection(){NodeCollection.__super__.constructor.call(this),this.children=[]}return __extends(NodeCollection,_super),NodeCollection.prototype.descendants=function(){var descendants,node,nodeStack;for(descendants=[],nodeStack=this.children.slice();nodeStack.length>0;)node=nodeStack.shift(),descendants.push(node),node.children&&node.children.length>0&&(nodeStack=node.children.slice().concat(nodeStack));return descendants},NodeCollection.prototype.isMounted=function(){return!1},NodeCollection.prototype.attach=function(node,index){return node.parent()&&node.parent().detach(node),node._parent=this,void 0!==index?this.children.splice(index,0,node):this.children.push(node),node.mount&&this.isMounted()&&node.mount(),this.taint(),ContentEdit.Root.get().trigger("attach",this,node)},NodeCollection.prototype.commit=function(){var descendant,_i,_len,_ref;for(_ref=this.descendants(),_i=0,_len=_ref.length;_len>_i;_i++)descendant=_ref[_i],descendant._modified=null;return this._modified=null,ContentEdit.Root.get().trigger("commit",this)},NodeCollection.prototype.detach=function(node){var nodeIndex;return nodeIndex=this.children.indexOf(node),-1!==nodeIndex?(node.unmount&&this.isMounted()&&node.isMounted()&&node.unmount(),this.children.splice(nodeIndex,1),node._parent=null,this.taint(),ContentEdit.Root.get().trigger("detach",this,node)):void 0},NodeCollection}(ContentEdit.Node),ContentEdit.Element=function(_super){function Element(tagName,attributes){Element.__super__.constructor.call(this),this._tagName=tagName.toLowerCase(),this._attributes=attributes?attributes:{},this._domElement=null}return __extends(Element,_super),Element.prototype.attributes=function(){var attributes,name,value,_ref;attributes={},_ref=this._attributes;for(name in _ref)value=_ref[name],attributes[name]=value;return attributes},Element.prototype.cssTypeName=function(){return"element"},Element.prototype.domElement=function(){return this._domElement},Element.prototype.isFocused=function(){return ContentEdit.Root.get().focused()===this},Element.prototype.isMounted=function(){return null!==this._domElement},Element.prototype.typeName=function(){return"Element"},Element.prototype.addCSSClass=function(className){var modified;return modified=!1,this.hasCSSClass(className)||(modified=!0,this.attr("class")?this.attr("class",""+this.attr("class")+" "+className):this.attr("class",className)),this._addCSSClass(className),modified?this.taint():void 0},Element.prototype.attr=function(name,value){return name=name.toLowerCase(),void 0===value?this._attributes[name]:(this._attributes[name]=value,this.isMounted()&&"class"!==name.toLowerCase()&&this._domElement.setAttribute(name,value),this.taint())},Element.prototype.blur=function(){var root;return root=ContentEdit.Root.get(),this.isFocused()?(this._removeCSSClass("ce-element--focused"),root._focused=null,root.trigger("blur",this)):void 0},Element.prototype.createDraggingDOMElement=function(){var helper;if(this.isMounted())return helper=document.createElement("div"),helper.setAttribute("class","ce-drag-helper ce-drag-helper--type-"+this.cssTypeName()),helper.setAttribute("data-ce-type",ContentEdit._(this.typeName())),helper},Element.prototype.drag=function(x,y){var root;if(this.isMounted())return root=ContentEdit.Root.get(),root.startDragging(this,x,y),root.trigger("drag",this)},Element.prototype.drop=function(element,placement){var root;if(root=ContentEdit.Root.get(),element){if(element._removeCSSClass("ce-element--drop"),element._removeCSSClass("ce-element--drop-"+placement[0]),element._removeCSSClass("ce-element--drop-"+placement[1]),this.constructor.droppers[element.constructor.name])return this.constructor.droppers[element.constructor.name](this,element,placement),void root.trigger("drop",this,element,placement);if(element.constructor.droppers[this.constructor.name])return element.constructor.droppers[this.constructor.name](this,element,placement),void root.trigger("drop",this,element,placement)}return root.trigger("drop",this,null,null)},Element.prototype.focus=function(supressDOMFocus){var root;return root=ContentEdit.Root.get(),this.isFocused()?void 0:(root.focused()&&root.focused().blur(),this._addCSSClass("ce-element--focused"),root._focused=this,this.isMounted()&&!supressDOMFocus&&this.domElement().focus(),root.trigger("focus",this))},Element.prototype.hasCSSClass=function(className){var c,classNames;return this.attr("class")&&(classNames=function(){var _i,_len,_ref,_results;for(_ref=this.attr("class").split(" "),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}.call(this),classNames.indexOf(className)>-1)?!0:!1},Element.prototype.merge=function(element){return this.constructor.mergers[element.constructor.name]?this.constructor.mergers[element.constructor.name](element,this):element.constructor.mergers[this.constructor.name]?element.constructor.mergers[this.constructor.name](element,this):void 0},Element.prototype.mount=function(){var sibling;return this._domElement||(this._domElement=document.createElement(this.tagName())),sibling=this.nextSibling(),sibling?this.parent().domElement().insertBefore(this._domElement,sibling.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"),ContentEdit.Root.get().trigger("mount",this)},Element.prototype.removeAttr=function(name){return name=name.toLowerCase(),this._attributes[name]?(delete this._attributes[name],this.isMounted()&&"class"!==name.toLowerCase()&&this._domElement.removeAttribute(name),this.taint()):void 0},Element.prototype.removeCSSClass=function(className){var c,classNameIndex,classNames;if(this.hasCSSClass(className))return classNames=function(){var _i,_len,_ref,_results;for(_ref=this.attr("class").split(" "),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}.call(this),classNameIndex=classNames.indexOf(className),classNameIndex>-1&&classNames.splice(classNameIndex,1),classNames.length?this.attr("class",classNames.join(" ")):this.removeAttr("class"),this._removeCSSClass(className),this.taint()},Element.prototype.tagName=function(name){return void 0===name?this._tagName:(this._tagName=name.toLowerCase(),this.isMounted()&&(this.unmount(),this.mount()),this.taint())},Element.prototype.unmount=function(){return this._removeDOMEventListeners(),this._domElement.parentNode&&this._domElement.parentNode.removeChild(this._domElement),this._domElement=null,ContentEdit.Root.get().trigger("unmount",this)},Element.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("focus",function(){return function(ev){return ev.preventDefault()}}(this)),this._domElement.addEventListener("dragstart",function(){return function(ev){return ev.preventDefault()}}(this)),this._domElement.addEventListener("keydown",function(_this){return function(ev){return _this._onKeyDown(ev)}}(this)),this._domElement.addEventListener("keyup",function(_this){return function(ev){return _this._onKeyUp(ev)}}(this)),this._domElement.addEventListener("mousedown",function(_this){return function(ev){return 0===ev.button?_this._onMouseDown(ev):void 0}}(this)),this._domElement.addEventListener("mousemove",function(_this){return function(ev){return _this._onMouseMove(ev)}}(this)),this._domElement.addEventListener("mouseover",function(_this){return function(ev){return _this._onMouseOver(ev)}}(this)),this._domElement.addEventListener("mouseout",function(_this){return function(ev){return _this._onMouseOut(ev)}}(this)),this._domElement.addEventListener("mouseup",function(_this){return function(ev){return 0===ev.button?_this._onMouseUp(ev):void 0}}(this)),this._domElement.addEventListener("paste",function(_this){return function(ev){return _this._onPaste(ev)}}(this))},Element.prototype._onKeyDown=function(){},Element.prototype._onKeyUp=function(){},Element.prototype._onMouseDown=function(){return this.focus?this.focus(!0):void 0},Element.prototype._onMouseMove=function(){},Element.prototype._onMouseOver=function(){var dragging,root;return this._addCSSClass("ce-element--over"),root=ContentEdit.Root.get(),dragging=root.dragging(),dragging&&dragging!==this&&!root._dropTarget&&(this.constructor.droppers[dragging.constructor.name]||dragging.constructor.droppers[this.constructor.name])?(this._addCSSClass("ce-element--drop"),root._dropTarget=this):void 0},Element.prototype._onMouseOut=function(){var dragging,root;return this._removeCSSClass("ce-element--over"),root=ContentEdit.Root.get(),dragging=root.dragging(),dragging?(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"),root._dropTarget=null):void 0},Element.prototype._onMouseUp=function(){},Element.prototype._onPaste=function(ev){return ev.preventDefault(),ev.stopPropagation(),ContentEdit.Root.get().trigger("paste",this,ev)},Element.prototype._removeDOMEventListeners=function(){},Element.prototype._addCSSClass=function(className){return this.isMounted()?ContentEdit.addCSSClass(this._domElement,className):void 0},Element.prototype._attributesToString=function(){return Object.getOwnPropertyNames(this._attributes).length>0?" "+ContentEdit.attributesToString(this._attributes):""},Element.prototype._removeCSSClass=function(className){return this.isMounted()?ContentEdit.removeCSSClass(this._domElement,className):void 0},Element.droppers={},Element.mergers={},Element.placements=["above","below"],Element.getDOMElementAttributes=function(domElement){var attribute,attributes,_i,_len,_ref;if(!domElement.hasAttributes())return{};for(attributes={},_ref=domElement.attributes,_i=0,_len=_ref.length;_len>_i;_i++)attribute=_ref[_i],attributes[attribute.name.toLowerCase()]=attribute.value;return attributes},Element._dropVert=function(element,target,placement){var insertIndex;return element.parent().detach(element),insertIndex=target.parent().children.indexOf(target),"below"===placement[0]&&(insertIndex+=1),target.parent().attach(element,insertIndex)},Element._dropBoth=function(element,target,placement){var aClassNames,className,insertIndex,_i,_len,_ref;if(element.parent().detach(element),insertIndex=target.parent().children.indexOf(target),"below"===placement[0]&&"center"===placement[1]&&(insertIndex+=1),element.a){if(element._removeCSSClass("align-left"),element._removeCSSClass("align-right"),element.a["class"]){for(aClassNames=[],_ref=element.a["class"].split(" "),_i=0,_len=_ref.length;_len>_i;_i++)className=_ref[_i],"align-left"!==className&&"align-right"!==className&&aClassNames.push(className);aClassNames.length?element.a["class"]=aClassNames.join(" "):delete element.a["class"]}}else element.removeCSSClass("align-left"),element.removeCSSClass("align-right");return"left"===placement[1]&&(element.a?(element.a["class"]?element.a["class"]+=" align-left":element.a["class"]="align-left",element._addCSSClass("align-left")):element.addCSSClass("align-left")),"right"===placement[1]&&(element.a?(element.a["class"]?element.a["class"]+=" align-right":element.a["class"]="align-right",element._addCSSClass("align-right")):element.addCSSClass("align-right")),target.parent().attach(element,insertIndex)},Element}(ContentEdit.Node),ContentEdit.ElementCollection=function(_super){function ElementCollection(tagName,attributes){ElementCollection.__super__.constructor.call(this,tagName,attributes),ContentEdit.NodeCollection.prototype.constructor.call(this)}return __extends(ElementCollection,_super),ElementCollection.extend(ContentEdit.NodeCollection),ElementCollection.prototype.cssTypeName=function(){return"element-collection"},ElementCollection.prototype.isMounted=function(){return null!==this._domElement},ElementCollection.prototype.createDraggingDOMElement=function(){var helper,text;if(this.isMounted())return helper=ElementCollection.__super__.createDraggingDOMElement.call(this),text=this._domElement.textContent,text.length>ContentEdit.HELPER_CHAR_LIMIT&&(text=text.substr(0,ContentEdit.HELPER_CHAR_LIMIT)),helper.innerHTML=text,helper},ElementCollection.prototype.detach=function(element){return ContentEdit.NodeCollection.prototype.detach.call(this,element),0===this.children.length&&this.parent()?this.parent().detach(this):void 0},ElementCollection.prototype.html=function(indent){var c,children;return null==indent&&(indent=""),children=function(){var _i,_len,_ref,_results;for(_ref=this.children,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c.html(indent+ContentEdit.INDENT));return _results}.call(this),""+indent+"<"+this.tagName()+this._attributesToString()+">\n"+(""+children.join("\n")+"\n")+(""+indent+"</"+this.tagName()+">")},ElementCollection.prototype.mount=function(){var child,name,value,_i,_len,_ref,_ref1,_results;this._domElement=document.createElement(this._tagName),_ref=this._attributes;for(name in _ref)value=_ref[name],this._domElement.setAttribute(name,value);for(ElementCollection.__super__.mount.call(this),_ref1=this.children,_results=[],_i=0,_len=_ref1.length;_len>_i;_i++)child=_ref1[_i],_results.push(child.mount());return _results},ElementCollection.prototype.unmount=function(){var child,_i,_len,_ref;for(_ref=this.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],child.unmount();return ElementCollection.__super__.unmount.call(this)},ElementCollection.prototype.blur=void 0,ElementCollection.prototype.focus=void 0,ElementCollection}(ContentEdit.Element),ContentEdit.ResizableElement=function(_super){function ResizableElement(tagName,attributes){ResizableElement.__super__.constructor.call(this,tagName,attributes),this._domSizeInfoElement=null,this._aspectRatio=1}return __extends(ResizableElement,_super),ResizableElement.prototype.aspectRatio=function(){return this._aspectRatio},ResizableElement.prototype.maxSize=function(){var maxWidth;return maxWidth=parseInt(this.attr("data-ce-max-width")||0),maxWidth||(maxWidth=ContentEdit.DEFAULT_MAX_ELEMENT_WIDTH),maxWidth=Math.max(maxWidth,this.size()[0]),[maxWidth,maxWidth*this.aspectRatio()]},ResizableElement.prototype.minSize=function(){var minWidth;return minWidth=parseInt(this.attr("data-ce-min-width")||0),minWidth||(minWidth=ContentEdit.DEFAULT_MIN_ELEMENT_WIDTH),minWidth=Math.min(minWidth,this.size()[0]),[minWidth,minWidth*this.aspectRatio()]},ResizableElement.prototype.mount=function(){return ResizableElement.__super__.mount.call(this),this._domElement.setAttribute("data-ce-size",this._getSizeInfo())},ResizableElement.prototype.resize=function(corner,x,y){return this.isMounted()?ContentEdit.Root.get().startResizing(this,corner,x,y,!0):void 0},ResizableElement.prototype.size=function(newSize){var height,maxSize,minSize,width;return newSize?(newSize[0]=parseInt(newSize[0]),newSize[1]=parseInt(newSize[1]),minSize=this.minSize(),newSize[0]=Math.max(newSize[0],minSize[0]),newSize[1]=Math.max(newSize[1],minSize[1]),maxSize=this.maxSize(),newSize[0]=Math.min(newSize[0],maxSize[0]),newSize[1]=Math.min(newSize[1],maxSize[1]),this.attr("width",parseInt(newSize[0])),this.attr("height",parseInt(newSize[1])),this.isMounted()?(this._domElement.style.width=""+newSize[0]+"px",this._domElement.style.height=""+newSize[1]+"px",this._domElement.setAttribute("data-ce-size",this._getSizeInfo())):void 0):(width=parseInt(this.attr("width")||1),height=parseInt(this.attr("height")||1),[width,height])},ResizableElement.prototype._onMouseDown=function(ev){var corner;return ResizableElement.__super__._onMouseDown.call(this),corner=this._getResizeCorner(ev.clientX,ev.clientY),corner?this.resize(corner,ev.clientX,ev.clientY):(clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(function(_this){return function(){return _this.drag(ev.pageX,ev.pageY)}}(this),150))},ResizableElement.prototype._onMouseMove=function(ev){var corner;return ResizableElement.__super__._onMouseMove.call(this),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"),corner=this._getResizeCorner(ev.clientX,ev.clientY),corner?this._addCSSClass("ce-element--resize-"+corner[0]+"-"+corner[1]):void 0},ResizableElement.prototype._onMouseOut=function(){return ResizableElement.__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"),this._removeCSSClass("ce-element--resize-bottom-right")},ResizableElement.prototype._onMouseUp=function(){return ResizableElement.__super__._onMouseUp.call(this),this._dragTimeout?clearTimeout(this._dragTimeout):void 0},ResizableElement.prototype._getResizeCorner=function(x,y){var corner,cornerSize,rect,size,_ref;return rect=this._domElement.getBoundingClientRect(),_ref=[x-rect.left,y-rect.top],x=_ref[0],y=_ref[1],size=this.size(),cornerSize=ContentEdit.RESIZE_CORNER_SIZE,cornerSize=Math.min(cornerSize,Math.max(parseInt(size[0]/4),1)),cornerSize=Math.min(cornerSize,Math.max(parseInt(size[1]/4),1)),corner=null,cornerSize>x?cornerSize>y?corner=["top","left"]:y>rect.height-cornerSize&&(corner=["bottom","left"]):x>rect.width-cornerSize&&(cornerSize>y?corner=["top","right"]:y>rect.height-cornerSize&&(corner=["bottom","right"])),corner},ResizableElement.prototype._getSizeInfo=function(){var size;return size=this.size(),"w "+size[0]+" × h "+size[1]},ResizableElement}(ContentEdit.Element),ContentEdit.Region=function(_super){function Region(domElement){var c,childNode,childNodes,cls,element,tagNames,_i,_len;for(Region.__super__.constructor.call(this),this._domElement=domElement,tagNames=ContentEdit.TagNames.get(),childNodes=function(){var _i,_len,_ref,_results;for(_ref=this._domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}.call(this),_i=0,_len=childNodes.length;_len>_i;_i++)childNode=childNodes[_i],1===childNode.nodeType&&(cls=tagNames.match(childNode.getAttribute("data-ce-tag")?childNode.getAttribute("data-ce-tag"):childNode.tagName),element=cls.fromDOMElement(childNode),this._domElement.removeChild(childNode),element&&this.attach(element))}return __extends(Region,_super),Region.prototype.domElement=function(){return this._domElement},Region.prototype.isMounted=function(){return!0},Region.prototype.html=function(indent){var c;return null==indent&&(indent=""),function(){var _i,_len,_ref,_results;for(_ref=this.children,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c.html(indent));return _results}.call(this).join("\n").trim()},Region}(ContentEdit.NodeCollection),_Root=function(_super){function _Root(){this._onStopResizing=__bind(this._onStopResizing,this),this._onResize=__bind(this._onResize,this),this._onStopDragging=__bind(this._onStopDragging,this),this._onDrag=__bind(this._onDrag,this),_Root.__super__.constructor.call(this),this._focused=null,this._dragging=null,this._dropTarget=null,this._draggingDOMElement=null,this._resizing=null,this._resizingInit=null}return __extends(_Root,_super),_Root.prototype.dragging=function(){return this._dragging},_Root.prototype.dropTarget=function(){return this._dropTarget},_Root.prototype.focused=function(){return this._focused},_Root.prototype.resizing=function(){return this._resizing},_Root.prototype.cancelDragging=function(){return this._dragging?(document.body.removeChild(this._draggingDOMElement),document.removeEventListener("mousemove",this._onDrag),document.removeEventListener("mouseup",this._onStopDragging),this._dragging._removeCSSClass("ce-element--dragging"),this._dragging=null,this._dropTarget=null,ContentEdit.removeCSSClass(document.body,"ce--dragging")):void 0},_Root.prototype.startDragging=function(element,x,y){return this._dragging?void 0:(this._dragging=element,this._dragging._addCSSClass("ce-element--dragging"),this._draggingDOMElement=this._dragging.createDraggingDOMElement(),document.body.appendChild(this._draggingDOMElement),this._draggingDOMElement.style.left=""+x+"px",this._draggingDOMElement.style.top=""+y+"px",document.addEventListener("mousemove",this._onDrag),document.addEventListener("mouseup",this._onStopDragging),ContentEdit.addCSSClass(document.body,"ce--dragging"))},_Root.prototype._getDropPlacement=function(x,y){var horz,rect,vert,_ref;return this._dropTarget?(rect=this._dropTarget.domElement().getBoundingClientRect(),_ref=[x-rect.left,y-rect.top],x=_ref[0],y=_ref[1],horz="center",x<ContentEdit.DROP_EDGE_SIZE?horz="left":x>rect.width-ContentEdit.DROP_EDGE_SIZE&&(horz="right"),vert="above",y>rect.height/2&&(vert="below"),[vert,horz]):null},_Root.prototype._onDrag=function(ev){var placement,_ref,_ref1;return ContentSelect.Range.unselectAll(),this._draggingDOMElement.style.left=""+ev.pageX+"px",this._draggingDOMElement.style.top=""+ev.pageY+"px",this._dropTarget&&(placement=this._getDropPlacement(ev.clientX,ev.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"),_ref=placement[0],__indexOf.call(this._dragging.constructor.placements,_ref)>=0&&this._dropTarget._addCSSClass("ce-element--drop-"+placement[0]),_ref1=placement[1],__indexOf.call(this._dragging.constructor.placements,_ref1)>=0)?this._dropTarget._addCSSClass("ce-element--drop-"+placement[1]):void 0},_Root.prototype._onStopDragging=function(ev){var placement;return placement=this._getDropPlacement(ev.clientX,ev.clientY),this._dragging.drop(this._dropTarget,placement),this.cancelDragging()},_Root.prototype.startResizing=function(element,corner,x,y,fixed){var measureDom,parentDom;if(!this._resizing)return this._resizing=element,this._resizingInit={corner:corner,fixed:fixed,origin:[x,y],size:element.size()},this._resizing._addCSSClass("ce-element--resizing"),parentDom=this._resizing.parent().domElement(),measureDom=document.createElement("div"),measureDom.setAttribute("class","ce-measure"),parentDom.appendChild(measureDom),this._resizingParentWidth=measureDom.getBoundingClientRect().width,parentDom.removeChild(measureDom),document.addEventListener("mousemove",this._onResize),document.addEventListener("mouseup",this._onStopResizing),ContentEdit.addCSSClass(document.body,"ce--resizing")},_Root.prototype._onResize=function(ev){var height,width,x,y;return ContentSelect.Range.unselectAll(),x=this._resizingInit.origin[0]-ev.clientX,"right"===this._resizingInit.corner[1]&&(x=-x),width=this._resizingInit.size[0]+x,width=Math.min(width,this._resizingParentWidth),this._resizingInit.fixed?height=width*this._resizing.aspectRatio():(y=this._resizingInit.origin[1]-ev.clientY,"bottom"===this._resizingInit.corner[0]&&(y=-y),height=this._resizingInit.size[1]+y),this._resizing.size([width,height])
  },_Root.prototype._onStopResizing=function(){return document.removeEventListener("mousemove",this._onResize),document.removeEventListener("mouseup",this._onStopResizing),this._resizing._removeCSSClass("ce-element--resizing"),this._resizing=null,this._resizingInit=null,this._resizingParentWidth=null,ContentEdit.removeCSSClass(document.body,"ce--resizing")},_Root}(ContentEdit.Node),ContentEdit.Root=function(){function Root(){}var instance;return instance=null,Root.get=function(){return null!=instance?instance:instance=new _Root},Root}(),ContentEdit.Static=function(_super){function Static(tagName,attributes,content){Static.__super__.constructor.call(this,tagName,attributes),this._content=content}return __extends(Static,_super),Static.prototype.cssTypeName=function(){return"static"},Static.prototype.typeName=function(){return"Static"},Static.prototype.createDraggingDOMElement=function(){var helper,text;if(this.isMounted())return helper=Static.__super__.createDraggingDOMElement.call(this),text=this._domElement.textContent,text.length>ContentEdit.HELPER_CHAR_LIMIT&&(text=text.substr(0,ContentEdit.HELPER_CHAR_LIMIT)),helper.innerHTML=text,helper},Static.prototype.html=function(indent){return null==indent&&(indent=""),""+indent+"<"+this._tagName+this._attributesToString()+">"+this._content+(""+indent+"</"+this._tagName+">")},Static.prototype.mount=function(){var name,value,_ref;this._domElement=document.createElement(this._tagName),_ref=this._attributes;for(name in _ref)value=_ref[name],this._domElement.setAttribute(name,value);return this._domElement.innerHTML=this._content,Static.__super__.mount.call(this)},Static.prototype.blur=void 0,Static.prototype.focus=void 0,Static.prototype._onMouseDown=function(ev){return Static.__super__._onMouseDown.call(this),void 0!==this.attr("data-ce-moveable")?(clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(function(_this){return function(){return _this.drag(ev.pageX,ev.pageY)}}(this),150)):void 0},Static.prototype._onMouseOver=function(ev){return Static.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},Static.prototype._onMouseUp=function(){return Static.__super__._onMouseUp.call(this),this._dragTimeout?clearTimeout(this._dragTimeout):void 0},Static.droppers={Static:ContentEdit.Element._dropVert},Static.fromDOMElement=function(domElement){return new this(domElement.tagName,this.getDOMElementAttributes(domElement),domElement.innerHTML)},Static}(ContentEdit.Element),ContentEdit.TagNames.get().register(ContentEdit.Static,"static"),ContentEdit.Text=function(_super){function Text(tagName,attributes,content){Text.__super__.constructor.call(this,tagName,attributes),this.content=content instanceof HTMLString.String?content:new HTMLString.String(content).trim()}return __extends(Text,_super),Text.prototype.cssTypeName=function(){return"text"},Text.prototype.typeName=function(){return"Text"},Text.prototype.blur=function(){var error;if(this.isMounted()&&this._syncContent(),this.content.isWhitespace())this.parent()&&this.parent().detach(this);else if(this.isMounted()){try{this._domElement.blur()}catch(_error){error=_error}this._domElement.removeAttribute("contenteditable")}return Text.__super__.blur.call(this)},Text.prototype.createDraggingDOMElement=function(){var helper,text;if(this.isMounted())return helper=Text.__super__.createDraggingDOMElement.call(this),text=this._domElement.textContent,text.length>ContentEdit.HELPER_CHAR_LIMIT&&(text=text.substr(0,ContentEdit.HELPER_CHAR_LIMIT)),helper.innerHTML=text,helper},Text.prototype.drag=function(x,y){return this.storeState(),this._domElement.removeAttribute("contenteditable"),Text.__super__.drag.call(this,x,y)},Text.prototype.drop=function(element,placement){return Text.__super__.drop.call(this,element,placement),this.restoreState()},Text.prototype.focus=function(supressDOMFocus){return this.isMounted()&&this._domElement.setAttribute("contenteditable",""),Text.__super__.focus.call(this,supressDOMFocus)},Text.prototype.html=function(indent){var content;return null==indent&&(indent=""),(!this._lastCached||this._lastCached<this._modified)&&(content=this.content.copy(),content.optimize(),this._lastCached=Date.now(),this._cached=content.html()),""+indent+"<"+this._tagName+this._attributesToString()+">\n"+(""+indent+ContentEdit.INDENT+this._cached+"\n")+(""+indent+"</"+this._tagName+">")},Text.prototype.mount=function(){var name,value,_ref;this._domElement=document.createElement(this._tagName),_ref=this._attributes;for(name in _ref)value=_ref[name],this._domElement.setAttribute(name,value);return this.updateInnerHTML(),Text.__super__.mount.call(this)},Text.prototype.restoreState=function(){return this._savedSelection?this.isMounted()&&this.isFocused()?(this._domElement.setAttribute("contenteditable",""),this._addCSSClass("ce-element--focused"),this._savedSelection.select(this._domElement),this._savedSelection=void 0):void(this._savedSelection=void 0):void 0},Text.prototype.selection=function(selection){return void 0===selection?this.isMounted()?ContentSelect.Range.query(this._domElement):new ContentSelect.Range(0,0):selection.select(this._domElement)},Text.prototype.storeState=function(){return this.isMounted()&&this.isFocused()?this._savedSelection=ContentSelect.Range.query(this._domElement):void 0},Text.prototype.updateInnerHTML=function(){return this._domElement.innerHTML=this.content.html(),ContentSelect.Range.prepareElement(this._domElement),this._flagIfEmpty()},Text.prototype._onKeyDown=function(ev){switch(ev.keyCode){case 40:return this._keyDown(ev);case 37:return this._keyLeft(ev);case 39:return this._keyRight(ev);case 38:return this._keyUp(ev);case 9:return this._keyTab(ev);case 8:return this._keyBack(ev);case 46:return this._keyDelete(ev);case 13:return this._keyReturn(ev)}},Text.prototype._onKeyUp=function(){return this._syncContent()},Text.prototype._onMouseDown=function(ev){return Text.__super__._onMouseDown.call(this),clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(function(_this){return function(){return _this.drag(ev.pageX,ev.pageY)}}(this),ContentEdit.DRAG_HOLD_DURATION)},Text.prototype._onMouseMove=function(){return this._dragTimeout&&clearTimeout(this._dragTimeout),Text.__super__._onMouseMove.call(this)},Text.prototype._onMouseOut=function(){return this._dragTimeout&&clearTimeout(this._dragTimeout),Text.__super__._onMouseOut.call(this)},Text.prototype._onMouseUp=function(){return this._dragTimeout&&clearTimeout(this._dragTimeout),Text.__super__._onMouseUp.call(this)},Text.prototype._keyBack=function(ev){var previous,selection;return selection=ContentSelect.Range.query(this._domElement),0===selection.get()[0]&&selection.isCollapsed()?(ev.preventDefault(),previous=this.previousContent(),this._syncContent(),previous?previous.merge(this):void 0):void 0},Text.prototype._keyDelete=function(ev){var next,selection;return selection=ContentSelect.Range.query(this._domElement),this._atEnd(selection)&&selection.isCollapsed()?(ev.preventDefault(),next=this.nextContent(),next?this.merge(next):void 0):void 0},Text.prototype._keyDown=function(ev){return this._keyRight(ev)},Text.prototype._keyLeft=function(ev){var previous,selection;return selection=ContentSelect.Range.query(this._domElement),0===selection.get()[0]&&selection.isCollapsed()?(ev.preventDefault(),previous=this.previousContent(),previous?(previous.focus(),selection=new ContentSelect.Range(previous.content.length(),previous.content.length()),selection.select(previous.domElement())):ContentEdit.Root.get().trigger("previous-region",this.closest(function(node){return"Region"===node.constructor.name}))):void 0},Text.prototype._keyReturn=function(ev){var element,selection,tail,tip;return ev.preventDefault(),this.content.isWhitespace()?void 0:(ContentSelect.Range.query(this._domElement),selection=ContentSelect.Range.query(this._domElement),tip=this.content.substring(0,selection.get()[0]),tail=this.content.substring(selection.get()[1]),this.content=tip.trim(),this.updateInnerHTML(),element=new this.constructor("p",{},tail.trim()),this.parent().attach(element,this.parent().children.indexOf(this)+1),tip.length()?(element.focus(),selection=new ContentSelect.Range(0,0),selection.select(element.domElement())):(selection=new ContentSelect.Range(0,tip.length()),selection.select(this._domElement)),this.taint())},Text.prototype._keyRight=function(ev){var next,selection;return selection=ContentSelect.Range.query(this._domElement),this._atEnd(selection)&&selection.isCollapsed()?(ev.preventDefault(),next=this.nextContent(),next?(next.focus(),selection=new ContentSelect.Range(0,0),selection.select(next.domElement())):ContentEdit.Root.get().trigger("next-region",this.closest(function(node){return"Region"===node.constructor.name}))):void 0},Text.prototype._keyTab=function(ev){return ev.preventDefault()},Text.prototype._keyUp=function(ev){return this._keyLeft(ev)},Text.prototype._atEnd=function(selection){var atEnd;return atEnd=selection.get()[0]===this.content.length(),selection.get()[0]===this.content.length()-1&&this.content.characters[this.content.characters.length-1].isTag("br")&&(atEnd=!0),atEnd},Text.prototype._flagIfEmpty=function(){return 0===this.content.length()?this._addCSSClass("ce-element--empty"):this._removeCSSClass("ce-element--empty")},Text.prototype._syncContent=function(){var newSnaphot,snapshot;return snapshot=this.content.html(),this.content=new HTMLString.String(this._domElement.innerHTML,this.content.preserveWhitespace()),newSnaphot=this.content.html(),snapshot!==newSnaphot&&this.taint(),this._flagIfEmpty()},Text.droppers={Static:ContentEdit.Element._dropVert,Text:ContentEdit.Element._dropVert},Text.mergers={Text:function(element,target){var offset;return offset=target.content.length(),element.content.length()&&(target.content=target.content.concat(element.content)),target.isMounted()&&target.updateInnerHTML(),target.focus(),new ContentSelect.Range(offset,offset).select(target._domElement),element.parent()&&element.parent().detach(element),target.taint()}},Text.fromDOMElement=function(domElement){return new this(domElement.tagName,this.getDOMElementAttributes(domElement),domElement.innerHTML.replace(/^\s+|\s+$/g,""))},Text}(ContentEdit.Element),ContentEdit.TagNames.get().register(ContentEdit.Text,"address","blockquote","h1","h2","h3","h4","h5","h6","p"),ContentEdit.PreText=function(_super){function PreText(tagName,attributes,content){this.content=content instanceof HTMLString.String?content:new HTMLString.String(content,!0),ContentEdit.Element.call(this,tagName,attributes)}return __extends(PreText,_super),PreText.prototype.cssTypeName=function(){return"pre-text"},PreText.prototype.typeName=function(){return"Preformatted"},PreText.prototype.html=function(indent){var content;return null==indent&&(indent=""),(!this._lastCached||this._lastCached<this._modified)&&(content=this.content.copy(),content.optimize(),this._lastCached=Date.now(),this._cached=content.html()),""+indent+"<"+this._tagName+this._attributesToString()+">"+(""+this._cached+"</"+this._tagName+">")},PreText.prototype.updateInnerHTML=function(){var html;return html=this.content.html(),html+="\n",this._domElement.innerHTML=html,ContentSelect.Range.prepareElement(this._domElement),this._flagIfEmpty()},PreText.prototype._onKeyUp=function(){var html,newSnaphot,snapshot;return snapshot=this.content.html(),html=this._domElement.innerHTML.replace(/[\n]$/,""),this.content=new HTMLString.String(html,this.content.preserveWhitespace()),newSnaphot=this.content.html(),snapshot!==newSnaphot&&this.taint(),this._flagIfEmpty()},PreText.prototype._keyReturn=function(ev){var cursor,selection,tail,tip;return ev.preventDefault(),selection=ContentSelect.Range.query(this._domElement),cursor=selection.get()[0]+1,0===selection.get()[0]&&selection.isCollapsed()?this.content=new HTMLString.String("\n",!0).concat(this.content):this._atEnd(selection)&&selection.isCollapsed()?this.content=this.content.concat(new HTMLString.String("\n",!0)):0===selection.get()[0]&&selection.get()[1]===this.content.length()?(this.content=new HTMLString.String("\n",!0),cursor=0):(tip=this.content.substring(0,selection.get()[0]),tail=this.content.substring(selection.get()[1]),this.content=tip.concat(new HTMLString.String("\n",!0),tail)),this.updateInnerHTML(),selection.set(cursor,cursor),selection.select(this._domElement),this.taint()},PreText.droppers={PreText:ContentEdit.Element._dropVert,Static:ContentEdit.Element._dropVert,Text:ContentEdit.Element._dropVert},PreText.mergers={},PreText.fromDOMElement=function(domElement){return new this(domElement.tagName,this.getDOMElementAttributes(domElement),domElement.innerHTML)},PreText}(ContentEdit.Text),ContentEdit.TagNames.get().register(ContentEdit.PreText,"pre"),ContentEdit.Image=function(_super){function Image(attributes,a){var size;Image.__super__.constructor.call(this,"img",attributes),this.a=a?a:null,size=this.size(),this._aspectRatio=size[1]/size[0]}return __extends(Image,_super),Image.prototype.cssTypeName=function(){return"image"},Image.prototype.typeName=function(){return"Image"},Image.prototype.createDraggingDOMElement=function(){var helper;if(this.isMounted())return helper=Image.__super__.createDraggingDOMElement.call(this),helper.style.backgroundImage="url("+this._attributes.src+")",helper},Image.prototype.html=function(indent){var attributes,img;return null==indent&&(indent=""),img=""+indent+"<img"+this._attributesToString()+">",this.a?(attributes=ContentEdit.attributesToString(this.a),attributes=""+attributes+' data-ce-tag="img"',""+indent+"<a "+attributes+">\n"+(""+ContentEdit.INDENT+img+"\n")+(""+indent+"</a>")):img},Image.prototype.mount=function(){var style;return 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"]),style=this._attributes.style?this._attributes.style:"",style+="background-image:url("+this._attributes.src+");",this._attributes.width&&(style+="width:"+this._attributes.width+"px;"),this._attributes.height&&(style+="height:"+this._attributes.height+"px;"),this._domElement.setAttribute("style",style),Image.__super__.mount.call(this)},Image.droppers={Image:ContentEdit.Element._dropBoth,PreText:ContentEdit.Element._dropBoth,Static:ContentEdit.Element._dropBoth,Text:ContentEdit.Element._dropBoth},Image.placements=["above","below","left","right","center"],Image.fromDOMElement=function(domElement){var a,attributes,c,childNode,childNodes,_i,_len;if(a=null,"a"===domElement.tagName.toLowerCase()){for(a=this.getDOMElementAttributes(domElement),childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),_i=0,_len=childNodes.length;_len>_i;_i++)if(childNode=childNodes[_i],1===childNode.nodeType&&"img"===childNode.tagName.toLowerCase()){domElement=childNode;break}"a"===domElement.tagName.toLowerCase()&&(domElement=document.createElement("img"))}return attributes=this.getDOMElementAttributes(domElement),void 0===attributes.width&&(attributes.width=void 0===attributes.height?domElement.naturalWidth:domElement.clientWidth),void 0===attributes.height&&(attributes.height=void 0===attributes.width?domElement.naturalHeight:domElement.clientHeight),new this(attributes,a)},Image}(ContentEdit.ResizableElement),ContentEdit.TagNames.get().register(ContentEdit.Image,"img"),ContentEdit.Video=function(_super){function Video(tagName,attributes,sources){var size;null==sources&&(sources=[]),Video.__super__.constructor.call(this,tagName,attributes),this.sources=sources,size=this.size(),this._aspectRatio=size[1]/size[0]}return __extends(Video,_super),Video.prototype.cssTypeName=function(){return"video"},Video.prototype.typeName=function(){return"Video"},Video.prototype._title=function(){var src;return src="",this.attr("src")?src=this.attr("src"):this.sources.length&&(src=this.sources[0].src),src||(src="No video source set"),src.length>ContentEdit.HELPER_CHAR_LIMIT&&(src=text.substr(0,ContentEdit.HELPER_CHAR_LIMIT)),src},Video.prototype.createDraggingDOMElement=function(){var helper;if(this.isMounted())return helper=Video.__super__.createDraggingDOMElement.call(this),helper.innerHTML=this._title(),helper},Video.prototype.html=function(indent){var attributes,source,sourceStrings,_i,_len,_ref;if(null==indent&&(indent=""),"video"===this.tagName()){for(sourceStrings=[],_ref=this.sources,_i=0,_len=_ref.length;_len>_i;_i++)source=_ref[_i],attributes=ContentEdit.attributesToString(source),sourceStrings.push(""+indent+ContentEdit.INDENT+"<source "+attributes+">");return""+indent+"<video"+this._attributesToString()+">\n"+sourceStrings.join("\n")+("\n"+indent+"</video>")}return""+indent+"<"+this._tagName+this._attributesToString()+">"+("</"+this._tagName+">")},Video.prototype.mount=function(){var style;return 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"]),style=this._attributes.style?this._attributes.style:"",this._attributes.width&&(style+="width:"+this._attributes.width+"px;"),this._attributes.height&&(style+="height:"+this._attributes.height+"px;"),this._domElement.setAttribute("style",style),this._domElement.setAttribute("data-ce-title",this._title()),Video.__super__.mount.call(this)},Video.droppers={Image:ContentEdit.Element._dropBoth,PreText:ContentEdit.Element._dropBoth,Static:ContentEdit.Element._dropBoth,Text:ContentEdit.Element._dropBoth,Video:ContentEdit.Element._dropBoth},Video.placements=["above","below","left","right","center"],Video.fromDOMElement=function(domElement){var c,childNode,childNodes,sources,_i,_len;for(childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),sources=[],_i=0,_len=childNodes.length;_len>_i;_i++)childNode=childNodes[_i],1===childNode.nodeType&&"source"===childNode.tagName.toLowerCase()&&sources.push(this.getDOMElementAttributes(childNode));return new this(domElement.tagName,this.getDOMElementAttributes(domElement),sources)},Video}(ContentEdit.ResizableElement),ContentEdit.TagNames.get().register(ContentEdit.Video,"iframe","video"),ContentEdit.List=function(_super){function List(tagName,attributes){List.__super__.constructor.call(this,tagName,attributes)}return __extends(List,_super),List.prototype.cssTypeName=function(){return"list"},List.prototype.typeName=function(){return"List"},List.prototype._onMouseOver=function(ev){return"ListItem"!==this.parent().constructor.name?(List.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")):void 0},List.droppers={Image:ContentEdit.Element._dropBoth,List:ContentEdit.Element._dropVert,PreText:ContentEdit.Element._dropVert,Static:ContentEdit.Element._dropVert,Text:ContentEdit.Element._dropVert,Video:ContentEdit.Element._dropBoth},List.fromDOMElement=function(domElement){var c,childNode,childNodes,list,_i,_len;for(list=new this(domElement.tagName,this.getDOMElementAttributes(domElement)),childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),_i=0,_len=childNodes.length;_len>_i;_i++)childNode=childNodes[_i],1===childNode.nodeType&&"li"===childNode.tagName.toLowerCase()&&list.attach(ContentEdit.ListItem.fromDOMElement(childNode));return 0===list.children.length?null:list},List}(ContentEdit.ElementCollection),ContentEdit.TagNames.get().register(ContentEdit.List,"ol","ul"),ContentEdit.ListItem=function(_super){function ListItem(attributes){ListItem.__super__.constructor.call(this,"li",attributes)}return __extends(ListItem,_super),ListItem.prototype.cssTypeName=function(){return"list-item"},ListItem.prototype.list=function(){return 2===this.children.length?this.children[1]:null},ListItem.prototype.listItemText=function(){return this.children.length>0?this.children[0]:null},ListItem.prototype.html=function(indent){var lines;return null==indent&&(indent=""),lines=[""+indent+"<li"+this._attributesToString()+">"],this.listItemText()&&lines.push(this.listItemText().html(indent+ContentEdit.INDENT)),this.list()&&lines.push(this.list().html(indent+ContentEdit.INDENT)),lines.push(""+indent+"</li>"),lines.join("\n")},ListItem.prototype.indent=function(){var sibling;if(0!==this.parent().children.indexOf(this))return sibling=this.previousSibling(),sibling.list()||sibling.attach(new ContentEdit.List(sibling.parent().tagName())),this.listItemText().storeState(),this.parent().detach(this),sibling.list().attach(this),this.listItemText().restoreState()},ListItem.prototype.remove=function(){var child,i,index,_i,_len,_ref;if(this.parent()){if(index=this.parent().children.indexOf(this),this.list())for(_ref=this.list().children.slice(),i=_i=0,_len=_ref.length;_len>_i;i=++_i)child=_ref[i],child.parent().detach(child),this.parent().attach(child,i+index);return this.parent().detach(this)}},ListItem.prototype.unindent=function(){var child,grandParent,i,itemIndex,list,parent,parentIndex,selection,sibling,siblings,text,_i,_j,_k,_l,_len,_len1,_len2,_len3,_ref,_ref1;if(parent=this.parent(),grandParent=parent.parent(),siblings=parent.children.slice(parent.children.indexOf(this)+1,parent.children.length),"ListItem"===grandParent.constructor.name){for(this.listItemText().storeState(),parent.detach(this),grandParent.parent().attach(this,grandParent.parent().children.indexOf(grandParent)+1),siblings.length&&!this.list()&&this.attach(new ContentEdit.List(parent.tagName())),_i=0,_len=siblings.length;_len>_i;_i++)sibling=siblings[_i],sibling.parent().detach(sibling),this.list().attach(sibling);return this.listItemText().restoreState()}if(text=new ContentEdit.Text("p",this.attr("class")?{"class":this.attr("class")}:{},this.listItemText().content),selection=null,this.listItemText().isFocused()&&(selection=ContentSelect.Range.query(this.listItemText().domElement())),parentIndex=grandParent.children.indexOf(parent),itemIndex=parent.children.indexOf(this),0===itemIndex){if(list=null,1===parent.children.length?(this.list()&&(list=new ContentEdit.List(parent.tagName())),grandParent.detach(parent)):parent.detach(this),grandParent.attach(text,parentIndex),list&&grandParent.attach(list,parentIndex+1),this.list())for(_ref=this.list().children.slice(),i=_j=0,_len1=_ref.length;_len1>_j;i=++_j)child=_ref[i],child.parent().detach(child),list?list.attach(child):parent.attach(child,i)}else if(itemIndex===parent.children.length-1)parent.detach(this),grandParent.attach(text,parentIndex+1),this.list()&&grandParent.attach(this.list(),parentIndex+2);else{if(parent.detach(this),grandParent.attach(text,parentIndex+1),list=new ContentEdit.List(parent.tagName()),grandParent.attach(list,parentIndex+2),this.list())for(_ref1=this.list().children.slice(),_k=0,_len2=_ref1.length;_len2>_k;_k++)child=_ref1[_k],child.parent().detach(child),list.attach(child);for(_l=0,_len3=siblings.length;_len3>_l;_l++)sibling=siblings[_l],sibling.parent().detach(sibling),list.attach(sibling)}return selection?(text.focus(),selection.select(text.domElement())):void 0},ListItem.prototype._onMouseOver=function(ev){return ListItem.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},ListItem.prototype._addDOMEventListeners=function(){},ListItem.prototype._removeDOMEventListners=function(){},ListItem.fromDOMElement=function(domElement){var childNode,content,listDOMElement,listElement,listItem,listItemText,_i,_len,_ref,_ref1;for(listItem=new this(this.getDOMElementAttributes(domElement)),content="",listDOMElement=null,_ref=domElement.childNodes,_i=0,_len=_ref.length;_len>_i;_i++)childNode=_ref[_i],1===childNode.nodeType?"ul"===(_ref1=childNode.tagName.toLowerCase())||"li"===_ref1?listDOMElement||(listDOMElement=childNode):content+=childNode.outerHTML:content+=HTMLString.String.encode(childNode.textContent);return content=content.replace(/^\s+|\s+$/g,""),listItemText=new ContentEdit.ListItemText(content),listItem.attach(listItemText),listDOMElement&&(listElement=ContentEdit.List.fromDOMElement(listDOMElement),listItem.attach(listElement)),listItem},ListItem}(ContentEdit.ElementCollection),ContentEdit.ListItemText=function(_super){function ListItemText(content){ListItemText.__super__.constructor.call(this,"div",{},content)}return __extends(ListItemText,_super),ListItemText.prototype.cssTypeName=function(){return"list-item-text"},ListItemText.prototype.typeName=function(){return"List item"},ListItemText.prototype.blur=function(){return this.content.isWhitespace()?this.parent().remove():this.isMounted()&&(this._domElement.blur(),this._domElement.removeAttribute("contenteditable")),ContentEdit.Element.prototype.blur.call(this)},ListItemText.prototype.html=function(indent){var content;return null==indent&&(indent=""),(!this._lastCached||this._lastCached<this._modified)&&(content=this.content.copy(),content.optimize(),this._lastCached=Date.now(),this._cached=content.html()),""+indent+this._cached},ListItemText.prototype._onMouseDown=function(ev){var initDrag;return ContentEdit.Element.prototype._onMouseDown.call(this,ev),initDrag=function(_this){return function(){var listRoot;return ContentEdit.Root.get().dragging()===_this?(ContentEdit.Root.get().cancelDragging(),listRoot=_this.closest(function(node){return"Region"===node.parent().constructor.name}),listRoot.drag(ev.pageX,ev.pageY)):(_this.drag(ev.pageX,ev.pageY),_this._dragTimeout=setTimeout(initDrag,2*ContentEdit.DRAG_HOLD_DURATION))}}(this),clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(initDrag,ContentEdit.DRAG_HOLD_DURATION)},ListItemText.prototype._onMouseMove=function(ev){return this._dragTimeout&&clearTimeout(this._dragTimeout),ContentEdit.Element.prototype._onMouseMove.call(this,ev)},ListItemText.prototype._onMouseUp=function(ev){return this._dragTimeout&&clearTimeout(this._dragTimeout),ContentEdit.Element.prototype._onMouseUp.call(this,ev)},ListItemText.prototype._keyTab=function(ev){return ev.preventDefault(),ev.shiftKey?this.parent().unindent():this.parent().indent()},ListItemText.prototype._keyReturn=function(ev){var grandParent,list,listItem,selection,tail,tip;return ev.preventDefault(),this.content.isWhitespace()?void this.parent().unindent():(ContentSelect.Range.query(this._domElement),selection=ContentSelect.Range.query(this._domElement),tip=this.content.substring(0,selection.get()[0]),tail=this.content.substring(selection.get()[1]),tip.length()+tail.length()===0?void this.parent().unindent():(this.content=tip.trim(),this.updateInnerHTML(),grandParent=this.parent().parent(),listItem=new ContentEdit.ListItem(this.attr("class")?{"class":this.attr("class")}:{}),grandParent.attach(listItem,grandParent.children.indexOf(this.parent())+1),listItem.attach(new ContentEdit.ListItemText(tail.trim())),list=this.parent().list(),list&&(this.parent().detach(list),listItem.attach(list)),tip.length()?(listItem.listItemText().focus(),selection=new ContentSelect.Range(0,0),selection.select(listItem.listItemText().domElement())):(selection=new ContentSelect.Range(0,tip.length()),selection.select(this._domElement))))},ListItemText.droppers={ListItemText:function(element,target,placement){var elementParent,insertIndex,listItem,targetParent;return elementParent=element.parent(),targetParent=target.parent(),elementParent.remove(),elementParent.detach(element),listItem=new ContentEdit.ListItem(elementParent._attributes),listItem.attach(element),targetParent.list()&&"below"===placement[0]?void targetParent.list().attach(listItem,0):(insertIndex=targetParent.parent().children.indexOf(targetParent),"below"===placement[0]&&(insertIndex+=1),targetParent.parent().attach(listItem,insertIndex))},Text:function(element,target,placement){var cssClass,insertIndex,listItem,targetParent,text;if("Text"===element.constructor.name){if(targetParent=target.parent(),element.parent().detach(element),cssClass=element.attr("class"),listItem=new ContentEdit.ListItem(cssClass?{"class":cssClass}:{}),listItem.attach(new ContentEdit.ListItemText(element.content)),targetParent.list()&&"below"===placement[0])return void targetParent.list().attach(listItem,0);if(insertIndex=targetParent.parent().children.indexOf(targetParent),"below"===placement[0]&&(insertIndex+=1),targetParent.parent().attach(listItem,insertIndex),listItem.listItemText().focus(),element._savedSelection)return element._savedSelection.select(listItem.listItemText().domElement())}else if(cssClass=element.attr("class"),text=new ContentEdit.Text("p",cssClass?{"class":cssClass}:{},element.content),element.parent().remove(),insertIndex=target.parent().children.indexOf(target),"below"===placement[0]&&(insertIndex+=1),target.parent().attach(text,insertIndex),text.focus(),element._savedSelection)return element._savedSelection.select(text.domElement())}},ListItemText.mergers={ListItemText:function(element,target){var offset;return offset=target.content.length(),element.content.length()&&(target.content=target.content.concat(element.content)),target.isMounted()&&(target._domElement.innerHTML=target.content.html()),target.focus(),new ContentSelect.Range(offset,offset).select(target._domElement),"Text"===element.constructor.name?element.parent()&&element.parent().detach(element):element.parent().remove(),target.taint()}},ListItemText}(ContentEdit.Text),_mergers=ContentEdit.ListItemText.mergers,_mergers.Text=_mergers.ListItemText,ContentEdit.Table=function(_super){function Table(attributes){Table.__super__.constructor.call(this,"table",attributes)}return __extends(Table,_super),Table.prototype.cssTypeName=function(){return"table"},Table.prototype.typeName=function(){return"Table"},Table.prototype.firstSection=function(){var section;return(section=this.thead())?section:(section=this.tbody())?section:(section=this.tfoot())?section:null},Table.prototype.lastSection=function(){var section;return(section=this.tfoot())?section:(section=this.tbody())?section:(section=this.thead())?section:null},Table.prototype.tbody=function(){return this._getChild("tbody")},Table.prototype.tfoot=function(){return this._getChild("tfoot")},Table.prototype.thead=function(){return this._getChild("thead")},Table.prototype._onMouseOver=function(ev){return Table.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},Table.prototype._getChild=function(tagName){var child,_i,_len,_ref;for(_ref=this.children,_i=0,_len=_ref.length;_len>_i;_i++)if(child=_ref[_i],child.tagName()===tagName)return child;return null},Table.droppers={Image:ContentEdit.Element._dropBoth,List:ContentEdit.Element._dropVert,PreText:ContentEdit.Element._dropVert,Static:ContentEdit.Element._dropVert,Table:ContentEdit.Element._dropVert,Text:ContentEdit.Element._dropVert,Video:ContentEdit.Element._dropBoth},Table.fromDOMElement=function(domElement){var c,childNode,childNodes,orphanRows,row,section,table,tagName,_i,_j,_len,_len1;for(table=new this(this.getDOMElementAttributes(domElement)),childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),orphanRows=[],_i=0,_len=childNodes.length;_len>_i;_i++)if(childNode=childNodes[_i],1===childNode.nodeType&&(tagName=childNode.tagName.toLowerCase(),!table._getChild(tagName)))switch(tagName){case"tbody":case"tfoot":case"thead":section=ContentEdit.TableSection.fromDOMElement(childNode),table.attach(section);break;case"tr":orphanRows.push(ContentEdit.TableRow.fromDOMElement(childNode))}if(orphanRows.length>0)for(table._getChild("tbody")||table.attach(new ContentEdit.TableSection("tbody")),_j=0,_len1=orphanRows.length;_len1>_j;_j++)row=orphanRows[_j],table.tbody().attach(row);return 0===table.children.length?null:table},Table}(ContentEdit.ElementCollection),ContentEdit.TagNames.get().register(ContentEdit.Table,"table"),ContentEdit.TableSection=function(_super){function TableSection(tagName,attributes){TableSection.__super__.constructor.call(this,tagName,attributes)
  }return __extends(TableSection,_super),TableSection.prototype.cssTypeName=function(){return"table-section"},TableSection.prototype._onMouseOver=function(ev){return TableSection.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},TableSection.fromDOMElement=function(domElement){var c,childNode,childNodes,section,_i,_len;for(section=new this(domElement.tagName,this.getDOMElementAttributes(domElement)),childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),_i=0,_len=childNodes.length;_len>_i;_i++)childNode=childNodes[_i],1===childNode.nodeType&&"tr"===childNode.tagName.toLowerCase()&&section.attach(ContentEdit.TableRow.fromDOMElement(childNode));return section},TableSection}(ContentEdit.ElementCollection),ContentEdit.TableRow=function(_super){function TableRow(attributes){TableRow.__super__.constructor.call(this,"tr",attributes)}return __extends(TableRow,_super),TableRow.prototype.cssTypeName=function(){return"table-row"},TableRow.prototype.typeName=function(){return"Table row"},TableRow.prototype._onMouseOver=function(ev){return TableRow.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},TableRow.droppers={TableRow:ContentEdit.Element._dropVert},TableRow.fromDOMElement=function(domElement){var c,childNode,childNodes,row,tagName,_i,_len;for(row=new this(this.getDOMElementAttributes(domElement)),childNodes=function(){var _i,_len,_ref,_results;for(_ref=domElement.childNodes,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)c=_ref[_i],_results.push(c);return _results}(),_i=0,_len=childNodes.length;_len>_i;_i++)childNode=childNodes[_i],1===childNode.nodeType&&(tagName=childNode.tagName.toLowerCase(),("td"===tagName||"th"===tagName)&&row.attach(ContentEdit.TableCell.fromDOMElement(childNode)));return row},TableRow}(ContentEdit.ElementCollection),ContentEdit.TableCell=function(_super){function TableCell(tagName,attributes){TableCell.__super__.constructor.call(this,tagName,attributes)}return __extends(TableCell,_super),TableCell.prototype.cssTypeName=function(){return"table-cell"},TableCell.prototype.tableCellText=function(){return this.children.length>0?this.children[0]:null},TableCell.prototype.html=function(indent){var lines;return null==indent&&(indent=""),lines=[""+indent+"<"+this.tagName()+this._attributesToString()+">"],this.tableCellText()&&lines.push(this.tableCellText().html(indent+ContentEdit.INDENT)),lines.push(""+indent+"</"+this.tagName()+">"),lines.join("\n")},TableCell.prototype._onMouseOver=function(ev){return TableCell.__super__._onMouseOver.call(this,ev),this._removeCSSClass("ce-element--over")},TableCell.prototype._addDOMEventListeners=function(){},TableCell.prototype._removeDOMEventListners=function(){},TableCell.fromDOMElement=function(domElement){var tableCell,tableCellText;return tableCell=new this(domElement.tagName,this.getDOMElementAttributes(domElement)),tableCellText=new ContentEdit.TableCellText(domElement.innerHTML.replace(/^\s+|\s+$/g,"")),tableCell.attach(tableCellText),tableCell},TableCell}(ContentEdit.ElementCollection),ContentEdit.TableCellText=function(_super){function TableCellText(content){TableCellText.__super__.constructor.call(this,"div",{},content)}return __extends(TableCellText,_super),TableCellText.prototype.cssTypeName=function(){return"table-cell-text"},TableCellText.prototype._isInFirstRow=function(){var cell,row,section,table;return cell=this.parent(),row=cell.parent(),section=row.parent(),table=section.parent(),section!==table.firstSection()?!1:row===section.children[0]},TableCellText.prototype._isInLastRow=function(){var cell,row,section,table;return cell=this.parent(),row=cell.parent(),section=row.parent(),table=section.parent(),section!==table.lastSection()?!1:row===section.children[section.children.length-1]},TableCellText.prototype._isLastInSection=function(){var cell,row,section;return cell=this.parent(),row=cell.parent(),section=row.parent(),row!==section.children[section.children.length-1]?!1:cell===row.children[row.children.length-1]},TableCellText.prototype.blur=function(){return this.isMounted()&&(this._domElement.blur(),this._domElement.removeAttribute("contenteditable")),ContentEdit.Element.prototype.blur.call(this)},TableCellText.prototype.html=function(indent){var content;return null==indent&&(indent=""),(!this._lastCached||this._lastCached<this._modified)&&(content=this.content.copy(),content.optimize(),this._lastCached=Date.now(),this._cached=content.html()),""+indent+this._cached},TableCellText.prototype._onMouseDown=function(ev){var initDrag;return ContentEdit.Element.prototype._onMouseDown.call(this,ev),initDrag=function(_this){return function(){var cell,table;return cell=_this.parent(),ContentEdit.Root.get().dragging()===cell.parent()?(ContentEdit.Root.get().cancelDragging(),table=cell.parent().parent().parent(),table.drag(ev.pageX,ev.pageY)):(cell.parent().drag(ev.pageX,ev.pageY),_this._dragTimeout=setTimeout(initDrag,2*ContentEdit.DRAG_HOLD_DURATION))}}(this),clearTimeout(this._dragTimeout),this._dragTimeout=setTimeout(initDrag,ContentEdit.DRAG_HOLD_DURATION)},TableCellText.prototype._keyReturn=function(ev){return ev.preventDefault(),this._keyTab({shiftKey:!1,preventDefault:function(){}})},TableCellText.prototype._keyDown=function(ev){var cell,cellIndex,lastCell,nextRow,row;return ev.preventDefault(),cell=this.parent(),this._isInLastRow()?(row=cell.parent(),lastCell=row.children[row.children.length-1].tableCellText(),lastCell.nextContent().focus()):(nextRow=cell.parent().nextWithTest(function(node){return"TableRow"===node.constructor.name}),cellIndex=cell.parent().children.indexOf(cell),cellIndex=Math.min(cellIndex,nextRow.children.length),nextRow.children[cellIndex].tableCellText().focus())},TableCellText.prototype._keyTab=function(ev){var cell,child,grandParent,newCell,newCellText,row,section,_i,_len,_ref;if(ev.preventDefault(),cell=this.parent(),ev.shiftKey){if(this._isInFirstRow()&&cell.parent().children[0]===cell)return;return this.previousContent().focus()}if(grandParent=cell.parent().parent(),"tbody"===grandParent.tagName()&&this._isLastInSection()){for(row=new ContentEdit.TableRow,_ref=cell.parent().children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],newCell=new ContentEdit.TableCell(child.tagName(),child._attributes),newCellText=new ContentEdit.TableCellText(""),newCell.attach(newCellText),row.attach(newCell);return section=this.closest(function(node){return"TableSection"===node.constructor.name}),section.attach(row),row.children[0].tableCellText().focus()}return this.nextContent().focus()},TableCellText.prototype._keyUp=function(ev){var cell,cellIndex,previousRow,row;return ev.preventDefault(),cell=this.parent(),this._isInFirstRow()?(row=cell.parent(),row.children[0].previousContent().focus()):(previousRow=cell.parent().previousWithTest(function(node){return"TableRow"===node.constructor.name}),cellIndex=cell.parent().children.indexOf(cell),cellIndex=Math.min(cellIndex,previousRow.children.length),previousRow.children[cellIndex].tableCellText().focus())},TableCellText.droppers={},TableCellText.mergers={},TableCellText}(ContentEdit.Text)}.call(this),function(){var AttributeUI,CropMarksUI,StyleUI,_EditorApp,__slice=[].slice,__hasProp={}.hasOwnProperty,__extends=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},__bind=function(fn,me){return function(){return fn.apply(me,arguments)}};window.ContentTools={Tools:{},DEFAULT_TOOLS:[["bold","italic","link","align-left","align-center","align-right"],["heading","subheading","paragraph","unordered-list","ordered-list","table","indent","unindent","line-break"],["image","video","preformatted"],["undo","redo","remove"]],DEFAULT_VIDEO_HEIGHT:300,DEFAULT_VIDEO_WIDTH:400,HIGHLIGHT_HOLD_DURATION:2e3,INSPECTOR_IGNORED_ELEMENTS:["ListItemText","Region","TableCellText"],IMAGE_UPLOADER:null,MIN_CROP:10,RESTRICTED_ATTRIBUTES:{img:["height","src","width","data-ce-max-width","data-ce-min-width"],iframe:["height","width"]},getEmbedVideoURL:function(url){var domains,id,kv,m,netloc,params,paramsStr,parser,path,_i,_len,_ref;for(domains={"www.youtube.com":"youtube","youtu.be":"youtube","vimeo.com":"vimeo","player.vimeo.com":"vimeo"},parser=document.createElement("a"),parser.href=url,netloc=parser.hostname.toLowerCase(),path=parser.pathname,null!==path&&"/"!==path.substr(0,1)&&(path="/"+path),params={},paramsStr=parser.search.slice(1),_ref=paramsStr.split("&"),_i=0,_len=_ref.length;_len>_i;_i++)kv=_ref[_i],kv=kv.split("="),params[kv[0]]=kv[1];switch(domains[netloc]){case"youtube":if("/watch"===path.toLowerCase()){if(!params.v)return null;id=params.v}else{if(m=path.match(/\/([A-Za-z0-9_-]+)$/i),!m)return null;id=m[1]}return"https://www.youtube.com/embed/"+id;case"vimeo":return m=path.match(/\/(\w+\/\w+\/){0,1}(\d+)/i),m?"https://player.vimeo.com/video/"+m[2]:null}return null}},ContentTools.ComponentUI=function(){function ComponentUI(){this._bindings={},this._parent=null,this._children=[],this._domElement=null}return ComponentUI.prototype.children=function(){return this._children.slice()},ComponentUI.prototype.domElement=function(){return this._domElement},ComponentUI.prototype.isMounted=function(){return null!==this._domElement},ComponentUI.prototype.parent=function(){return this._parent},ComponentUI.prototype.attach=function(component,index){return component.parent()&&component.parent().detach(component),component._parent=this,void 0!==index?this._children.splice(index,0,component):this._children.push(component)},ComponentUI.prototype.addCSSClass=function(className){return this.isMounted()?ContentEdit.addCSSClass(this._domElement,className):void 0},ComponentUI.prototype.detatch=function(component){var componentIndex;return componentIndex=this._children.indexOf(component),-1!==componentIndex?this._children.splice(componentIndex,1):void 0},ComponentUI.prototype.mount=function(){},ComponentUI.prototype.removeCSSClass=function(className){return this.isMounted()?ContentEdit.removeCSSClass(this._domElement,className):void 0},ComponentUI.prototype.unmount=function(){return this.isMounted()?(this._removeDOMEventListeners(),this._domElement.parentNode.removeChild(this._domElement),this._domElement=null):void 0},ComponentUI.prototype.bind=function(eventName,callback){return void 0===this._bindings[eventName]&&(this._bindings[eventName]=[]),this._bindings[eventName].push(callback),callback},ComponentUI.prototype.trigger=function(){var args,callback,eventName,_i,_len,_ref,_results;if(eventName=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[],this._bindings[eventName]){for(_ref=this._bindings[eventName],_results=[],_i=0,_len=_ref.length;_len>_i;_i++)callback=_ref[_i],callback&&_results.push(callback.call.apply(callback,[this].concat(__slice.call(args))));return _results}},ComponentUI.prototype.unbind=function(eventName,callback){var i,suspect,_i,_len,_ref,_results;if(!eventName)return void(this._bindings={});if(!callback)return void(this._bindings[eventName]=void 0);if(this._bindings[eventName]){for(_ref=this._bindings[eventName],_results=[],i=_i=0,_len=_ref.length;_len>_i;i=++_i)suspect=_ref[i],_results.push(suspect===callback?this._bindings[eventName].splice(i,1):void 0);return _results}},ComponentUI.prototype._addDOMEventListeners=function(){},ComponentUI.prototype._removeDOMEventListeners=function(){},ComponentUI.createDiv=function(classNames,attributes,content){var domElement,name,value;if(domElement=document.createElement("div"),classNames&&classNames.length>0&&domElement.setAttribute("class",classNames.join(" ")),attributes)for(name in attributes)value=attributes[name],domElement.setAttribute(name,value);return content&&(domElement.innerHTML=content),domElement},ComponentUI}(),ContentTools.WidgetUI=function(_super){function WidgetUI(){return WidgetUI.__super__.constructor.apply(this,arguments)}return __extends(WidgetUI,_super),WidgetUI.prototype.attach=function(component,index){return WidgetUI.__super__.attach.call(this,component,index),this.isMounted()?void 0:component.mount()},WidgetUI.prototype.detatch=function(component){return WidgetUI.__super__.detatch.call(this,component),this.isMounted()?component.unmount():void 0},WidgetUI.prototype.show=function(){var fadeIn;return this.isMounted()||this.mount(),fadeIn=function(_this){return function(){return _this.addCSSClass("ct-widget--active")}}(this),setTimeout(fadeIn,100)},WidgetUI.prototype.hide=function(){var monitorForHidden;return this.removeCSSClass("ct-widget--active"),monitorForHidden=function(_this){return function(){return window.getComputedStyle?parseFloat(window.getComputedStyle(_this._domElement).opacity)<.01?_this.unmount():setTimeout(monitorForHidden,250):void _this.unmount()}}(this),this.isMounted()?setTimeout(monitorForHidden,250):void 0},WidgetUI}(ContentTools.ComponentUI),ContentTools.AnchoredComponentUI=function(_super){function AnchoredComponentUI(){return AnchoredComponentUI.__super__.constructor.apply(this,arguments)}return __extends(AnchoredComponentUI,_super),AnchoredComponentUI.prototype.mount=function(domParent,before){return null==before&&(before=null),domParent.insertBefore(this._domElement,before),this._addDOMEventListeners()},AnchoredComponentUI}(ContentTools.ComponentUI),ContentTools.FlashUI=function(_super){function FlashUI(modifier){FlashUI.__super__.constructor.call(this),this.mount(modifier)}return __extends(FlashUI,_super),FlashUI.prototype.mount=function(modifier){var monitorForHidden;return this._domElement=this.constructor.createDiv(["ct-flash","ct-flash--active","ct-flash--"+modifier,"ct-widget","ct-widget--active"]),FlashUI.__super__.mount.call(this,ContentTools.EditorApp.get().domElement()),monitorForHidden=function(_this){return function(){return window.getComputedStyle?parseFloat(window.getComputedStyle(_this._domElement).opacity)<.01?_this.unmount():setTimeout(monitorForHidden,250):void _this.unmount()}}(this),setTimeout(monitorForHidden,250)},FlashUI}(ContentTools.AnchoredComponentUI),ContentTools.IgnitionUI=function(_super){function IgnitionUI(){IgnitionUI.__super__.constructor.call(this),this._busy=!1}return __extends(IgnitionUI,_super),IgnitionUI.prototype.busy=function(busy){if(void 0===busy)return this._busy;if(this._busy!==busy)return this._busy=busy,busy?this.addCSSClass("ct-ignition--busy"):this.removeCSSClass("ct-ignition--busy")},IgnitionUI.prototype.changeState=function(state){return"editing"===state?(this.addCSSClass("ct-ignition--editing"),this.removeCSSClass("ct-ignition--ready")):"ready"===state?(this.removeCSSClass("ct-ignition--editing"),this.addCSSClass("ct-ignition--ready")):void 0},IgnitionUI.prototype.mount=function(){return IgnitionUI.__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),this._addDOMEventListeners()},IgnitionUI.prototype.unmount=function(){return IgnitionUI.__super__.unmount.call(this),this._domEdit=null,this._domConfirm=null,this._domCancel=null},IgnitionUI.prototype._addDOMEventListeners=function(){return this._domEdit.addEventListener("click",function(_this){return function(ev){return ev.preventDefault(),_this.addCSSClass("ct-ignition--editing"),_this.removeCSSClass("ct-ignition--ready"),_this.trigger("start")}}(this)),this._domConfirm.addEventListener("click",function(_this){return function(ev){return ev.preventDefault(),_this.removeCSSClass("ct-ignition--editing"),_this.addCSSClass("ct-ignition--ready"),_this.trigger("stop",!0)}}(this)),this._domCancel.addEventListener("click",function(_this){return function(ev){return ev.preventDefault(),_this.removeCSSClass("ct-ignition--editing"),_this.addCSSClass("ct-ignition--ready"),_this.trigger("stop",!1)}}(this))},IgnitionUI}(ContentTools.WidgetUI),ContentTools.InspectorUI=function(_super){function InspectorUI(){InspectorUI.__super__.constructor.call(this),this._tagUIs=[]}return __extends(InspectorUI,_super),InspectorUI.prototype.mount=function(){return this._domElement=this.constructor.createDiv(["ct-widget","ct-inspector"]),this.parent().domElement().appendChild(this._domElement),this._domTags=this.constructor.createDiv(["ct-inspector__tags","ct-tags"]),this._domElement.appendChild(this._domTags),this._addDOMEventListeners(),this._handleFocusChange=function(_this){return function(){return _this.updateTags()}}(this),ContentEdit.Root.get().bind("blur",this._handleFocusChange),ContentEdit.Root.get().bind("focus",this._handleFocusChange),ContentEdit.Root.get().bind("mount",this._handleFocusChange)},InspectorUI.prototype.unmount=function(){return InspectorUI.__super__.unmount.call(this),this._domTags=null,ContentEdit.Root.get().unbind("blur",this._handleFocusChange),ContentEdit.Root.get().unbind("focus",this._handleFocusChange),ContentEdit.Root.get().unbind("mount",this._handleFocusChange)},InspectorUI.prototype.updateTags=function(){var element,elements,tag,_i,_j,_len,_len1,_ref,_results;for(element=ContentEdit.Root.get().focused(),_ref=this._tagUIs,_i=0,_len=_ref.length;_len>_i;_i++)tag=_ref[_i],tag.unmount();if(this._tagUIs=[],element){for(elements=element.parents(),elements.reverse(),elements.push(element),_results=[],_j=0,_len1=elements.length;_len1>_j;_j++)element=elements[_j],-1===ContentTools.INSPECTOR_IGNORED_ELEMENTS.indexOf(element.constructor.name)&&(tag=new ContentTools.TagUI(element),this._tagUIs.push(tag),_results.push(tag.mount(this._domTags)));return _results}},InspectorUI}(ContentTools.WidgetUI),ContentTools.TagUI=function(_super){function TagUI(element){this.element=element,this._onMouseDown=__bind(this._onMouseDown,this),TagUI.__super__.constructor.call(this)}return __extends(TagUI,_super),TagUI.prototype.mount=function(domParent,before){return null==before&&(before=null),this._domElement=this.constructor.createDiv(["ct-tag"]),this._domElement.textContent=this.element.tagName(),TagUI.__super__.mount.call(this,domParent,before)},TagUI.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("mousedown",this._onMouseDown)},TagUI.prototype._onMouseDown=function(ev){var app,dialog,modal;return ev.preventDefault(),this.element.storeState&&this.element.storeState(),app=ContentTools.EditorApp.get(),modal=new ContentTools.ModalUI,dialog=new ContentTools.PropertiesDialog(this.element),dialog.bind("cancel",function(_this){return function(){return dialog.unbind("cancel"),modal.hide(),dialog.hide(),_this.element.restoreState?_this.element.restoreState():void 0}}(this)),dialog.bind("save",function(_this){return function(attributes,styles,innerHTML){var applied,className,classNames,cssClass,element,name,value,_i,_j,_len,_len1,_ref,_ref1;dialog.unbind("save");for(name in attributes)if(value=attributes[name],"class"===name){for(null===value&&(value=""),classNames={},_ref=value.split(" "),_i=0,_len=_ref.length;_len>_i;_i++)className=_ref[_i],className=className.trim(),className&&(classNames[className]=!0,_this.element.hasCSSClass(className)||_this.element.addCSSClass(className));for(_ref1=_this.element.attr("class").split(" "),_j=0,_len1=_ref1.length;_len1>_j;_j++)className=_ref1[_j],className=className.trim(),void 0===classNames[className]&&_this.element.removeCSSClass(className)}else null===value?_this.element.removeAttr(name):_this.element.attr(name,value);for(cssClass in styles)applied=styles[cssClass],applied?_this.element.addCSSClass(cssClass):_this.element.removeCSSClass(cssClass);return null!==innerHTML&&innerHTML!==dialog.getElementInnerHTML()&&(element=_this.element,element.content||(element=element.children[0]),element.content=new HTMLString.String(innerHTML,element.content.preserveWhitespace()),element.updateInnerHTML(),element.taint(),element.selection(new ContentSelect.Range(0,0)),element.storeState()),modal.hide(),dialog.hide(),_this.element.restoreState?_this.element.restoreState():void 0}}(this)),app.attach(modal),app.attach(dialog),modal.show(),dialog.show()},TagUI}(ContentTools.AnchoredComponentUI),ContentTools.ModalUI=function(_super){function ModalUI(transparent,allowScrolling){ModalUI.__super__.constructor.call(this),this._transparent=transparent,this._allowScrolling=allowScrolling}return __extends(ModalUI,_super),ModalUI.prototype.mount=function(){return 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"),this._addDOMEventListeners()},ModalUI.prototype.unmount=function(){return this._allowScrolling||ContentEdit.removeCSSClass(document.body,"ct--no-scroll"),ModalUI.__super__.unmount.call(this)},ModalUI.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("click",function(_this){return function(){return _this.trigger("click")}}(this))},ModalUI}(ContentTools.WidgetUI),ContentTools.ToolboxUI=function(_super){function ToolboxUI(tools){this._onStopDragging=__bind(this._onStopDragging,this),this._onStartDragging=__bind(this._onStartDragging,this),this._onDrag=__bind(this._onDrag,this),ToolboxUI.__super__.constructor.call(this),this._tools=tools,this._dragging=!1,this._draggingOffset=null,this._domGrip=null,this._toolUIs={}}return __extends(ToolboxUI,_super),ToolboxUI.prototype.isDragging=function(){return this._dragging},ToolboxUI.prototype.hide=function(){return this._removeDOMEventListeners(),ToolboxUI.__super__.hide.call(this)},ToolboxUI.prototype.tools=function(tools){return void 0===tools?this._tools:(this._tools=tools,this.unmount(),this.mount())},ToolboxUI.prototype.mount=function(){var coord,domToolGroup,i,position,restore,tool,toolGroup,toolName,_i,_j,_len,_len1,_ref;for(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"])),_ref=this._tools,i=_i=0,_len=_ref.length;_len>_i;i=++_i)for(toolGroup=_ref[i],domToolGroup=this.constructor.createDiv(["ct-tool-group"]),this._domElement.appendChild(domToolGroup),_j=0,_len1=toolGroup.length;_len1>_j;_j++)toolName=toolGroup[_j],tool=ContentTools.ToolShelf.fetch(toolName),this._toolUIs[toolName]=new ContentTools.ToolUI(tool),this._toolUIs[toolName].mount(domToolGroup),this._toolUIs[toolName].disabled(!0),this._toolUIs[toolName].bind("apply",function(_this){return function(){return _this.updateTools()}}(this));return restore=window.localStorage.getItem("ct-toolbox-position"),restore&&/^\d+,\d+$/.test(restore)&&(position=function(){var _k,_len2,_ref1,_results;for(_ref1=restore.split(","),_results=[],_k=0,_len2=_ref1.length;_len2>_k;_k++)coord=_ref1[_k],_results.push(parseInt(coord));return _results}(),this._domElement.style.left=""+position[0]+"px",this._domElement.style.top=""+position[1]+"px",this._contain()),this._addDOMEventListeners()},ToolboxUI.prototype.updateTools=function(){var element,name,selection,toolUI,_ref,_results;element=ContentEdit.Root.get().focused(),selection=null,element&&element.selection&&(selection=element.selection()),_ref=this._toolUIs,_results=[];for(name in _ref)toolUI=_ref[name],_results.push(toolUI.update(element,selection));return _results},ToolboxUI.prototype.unmount=function(){return ToolboxUI.__super__.unmount.call(this),this._domGrip=null},ToolboxUI.prototype._addDOMEventListeners=function(){return this._domGrip.addEventListener("mousedown",this._onStartDragging),this._handleResize=function(_this){return function(){var containResize;return _this._resizeTimeout&&clearTimeout(_this._resizeTimeout),containResize=function(){return _this._contain()},_this._resizeTimeout=setTimeout(containResize,250)}}(this),window.addEventListener("resize",this._handleResize),this._updateTools=function(_this){return function(){var app,element,name,selection,toolUI,update,_ref,_results;app=ContentTools.EditorApp.get(),update=!1,element=ContentEdit.Root.get().focused(),selection=null,element===_this._lastUpdateElement?element&&element.selection&&(selection=element.selection(),_this._lastUpdateSelection&&selection.eq(_this._lastUpdateSelection)&&(update=!0)):update=!0,app.history&&(_this._lastUpdateHistoryLength!==app.history.length()&&(update=!0),_this._lastUpdateHistoryLength=app.history.length()),_this._lastUpdateElement=element,_this._lastUpdateSelection=selection,_ref=_this._toolUIs,_results=[];for(name in _ref)toolUI=_ref[name],_results.push(toolUI.update(element,selection));return _results}}(this),this._updateToolsTimeout=setInterval(this._updateTools,100),this._handleKeyDown=function(){return function(ev){var element,os,redo,undo,version;switch(46===ev.keyCode&&(element=ContentEdit.Root.get().focused(),element&&!element.content&&ContentTools.Tools.Remove.apply(element,null,function(){})),version=navigator.appVersion,os="linux",-1!==version.indexOf("Mac")?os="mac":-1!==version.indexOf("Win")&&(os="windows"),redo=!1,undo=!1,os){case"linux":90===ev.keyCode&&ev.ctrlKey&&(redo=ev.shiftKey,undo=!redo);break;case"mac":90===ev.keyCode&&ev.metaKey&&(redo=ev.shiftKey,undo=!redo);break;case"windows":89===ev.keyCode&&ev.ctrlKey&&(redo=!0),90===ev.keyCode&&ev.ctrlKey&&(undo=!0)}return undo&&ContentTools.Tools.Undo.canApply(null,null)&&ContentTools.Tools.Undo.apply(null,null,function(){}),redo&&ContentTools.Tools.Redo.canApply(null,null)?ContentTools.Tools.Redo.apply(null,null,function(){}):void 0}}(this),window.addEventListener("keydown",this._handleKeyDown)},ToolboxUI.prototype._contain=function(){var rect;if(this.isMounted())return rect=this._domElement.getBoundingClientRect(),rect.left+rect.width>window.innerWidth&&(this._domElement.style.left=""+(window.innerWidth-rect.width)+"px"),rect.top+rect.height>window.innerHeight&&(this._domElement.style.top=""+(window.innerHeight-rect.height)+"px"),rect.left<0&&(this._domElement.style.left="0px"),rect.top<0&&(this._domElement.style.top="0px"),rect=this._domElement.getBoundingClientRect(),window.localStorage.setItem("ct-toolbox-position",""+rect.left+","+rect.top)},ToolboxUI.prototype._removeDOMEventListeners=function(){return this.isMounted()&&this._domGrip.removeEventListener("mousedown",this._onStartDragging),window.removeEventListener("keydown",this._handleKeyDown),window.removeEventListener("resize",this._handleResize),window.removeEventListener("resize",this._handleResize),clearInterval(this._updateToolsTimeout)},ToolboxUI.prototype._onDrag=function(ev){return ContentSelect.Range.unselectAll(),this._domElement.style.left=""+(ev.clientX-this._draggingOffset.x)+"px",this._domElement.style.top=""+(ev.clientY-this._draggingOffset.y)+"px"},ToolboxUI.prototype._onStartDragging=function(ev){var rect;return ev.preventDefault(),this.isDragging()?void 0:(this._dragging=!0,this.addCSSClass("ct-toolbox--dragging"),rect=this._domElement.getBoundingClientRect(),this._draggingOffset={x:ev.clientX-rect.left,y:ev.clientY-rect.top},document.addEventListener("mousemove",this._onDrag),document.addEventListener("mouseup",this._onStopDragging),ContentEdit.addCSSClass(document.body,"ce--dragging"))},ToolboxUI.prototype._onStopDragging=function(){return this.isDragging()?(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")):void 0},ToolboxUI}(ContentTools.WidgetUI),ContentTools.ToolUI=function(_super){function ToolUI(tool){this._onMouseUp=__bind(this._onMouseUp,this),this._onMouseLeave=__bind(this._onMouseLeave,this),this._onMouseDown=__bind(this._onMouseDown,this),this._addDOMEventListeners=__bind(this._addDOMEventListeners,this),ToolUI.__super__.constructor.call(this),this.tool=tool,this._mouseDown=!1,this._disabled=!1}return __extends(ToolUI,_super),ToolUI.prototype.apply=function(element,selection){var callback;if(this.tool.canApply(element,selection))return callback=function(_this){return function(applied){return applied?_this.trigger("apply"):void 0}}(this),this.tool.apply(element,selection,callback)},ToolUI.prototype.disabled=function(disabledState){if(void 0===disabledState)return this._disabled;if(this._disabled!==disabledState)return this._disabled=disabledState,disabledState?(this._mouseDown=!1,this.addCSSClass("ct-tool--disabled"),this.removeCSSClass("ct-tool--applied")):this.removeCSSClass("ct-tool--disabled")},ToolUI.prototype.mount=function(domParent,before){return null==before&&(before=null),this._domElement=this.constructor.createDiv(["ct-tool","ct-tool--"+this.tool.icon]),this._domElement.setAttribute("data-tooltip",ContentEdit._(this.tool.label)),ToolUI.__super__.mount.call(this,domParent,before)},ToolUI.prototype.update=function(element,selection){return element&&element.isMounted()&&this.tool.canApply(element,selection)?(this.disabled(!1),this.tool.isApplied(element,selection)?this.addCSSClass("ct-tool--applied"):this.removeCSSClass("ct-tool--applied")):void this.disabled(!0)},ToolUI.prototype._addDOMEventListeners=function(){return this._domElement.addEventListener("mousedown",this._onMouseDown),this._domElement.addEventListener("mouseleave",this._onMouseLeave),this._domElement.addEventListener("mouseup",this._onMouseUp)},ToolUI.prototype._onMouseDown=function(ev){return ev.preventDefault(),this.disabled()?void 0:(this._mouseDown=!0,this.addCSSClass("ct-tool--down"))},ToolUI.prototype._onMouseLeave=function(){return this._mouseDown=!1,this.removeCSSClass("ct-tool--down")},ToolUI.prototype._onMouseUp=function(){var element,selection;if(this._mouseDown){if(element=ContentEdit.Root.get().focused(),!element||!element.isMounted())return;selection=null,element.selection&&(selection=element.selection()),this.apply(element,selection)}return this._mouseDown=!1,this.removeCSSClass("ct-tool--down")},ToolUI}(ContentTools.AnchoredComponentUI),ContentTools.AnchoredDialogUI=function(_super){function AnchoredDialogUI(){AnchoredDialogUI.__super__.constructor.call(this),this._position=[0,0]}return __extends(AnchoredDialogUI,_super),AnchoredDialogUI.prototype.mount=function(){return this._domElement=this.constructor.createDiv(["ct-widget","ct-anchored-dialog"]),this.parent().domElement().appendChild(this._domElement),this._domElement.style.top=""+this._position[1]+"px",this._domElement.style.left=""+this._position[0]+"px"},AnchoredDialogUI.prototype.position=function(newPosition){return void 0===newPosition?this._position.slice():(this._position=newPosition.slice(),this.isMounted()?(this._domElement.style.top=""+this._position[1]+"px",this._domElement.style.left=""+this._position[0]+"px"):void 0)},AnchoredDialogUI}(ContentTools.WidgetUI),ContentTools.DialogUI=function(_super){function DialogUI(caption){null==caption&&(caption=""),DialogUI.__super__.constructor.call(this),this._busy=!1,this._caption=caption}return __extends(DialogUI,_super),DialogUI.prototype.busy=function(busy){if(void 0===busy)return this._busy;
  if(this._busy!==busy&&(this._busy=busy,this.isMounted()))return this._busy?ContentEdit.addCSSClass(this._domElement,"ct-dialog--busy"):ContentEdit.removeCSSClass(this._domElement,"ct-dialog--busy")},DialogUI.prototype.caption=function(caption){return void 0===caption?this._caption:(this._caption=caption,this._domCaption.textContent=ContentEdit._(caption))},DialogUI.prototype.mount=function(){var dialogCSSClasses,domBody,domHeader;return dialogCSSClasses=["ct-widget","ct-dialog"],this._busy&&dialogCSSClasses.push("ct-dialog--busy"),this._domElement=this.constructor.createDiv(dialogCSSClasses),this.parent().domElement().appendChild(this._domElement),domHeader=this.constructor.createDiv(["ct-dialog__header"]),this._domElement.appendChild(domHeader),this._domCaption=this.constructor.createDiv(["ct-dialog__caption"]),domHeader.appendChild(this._domCaption),this.caption(this._caption),this._domClose=this.constructor.createDiv(["ct-dialog__close"]),domHeader.appendChild(this._domClose),domBody=this.constructor.createDiv(["ct-dialog__body"]),this._domElement.appendChild(domBody),this._domView=this.constructor.createDiv(["ct-dialog__view"]),domBody.appendChild(this._domView),this._domControls=this.constructor.createDiv(["ct-dialog__controls"]),domBody.appendChild(this._domControls),this._domBusy=this.constructor.createDiv(["ct-dialog__busy"]),this._domElement.appendChild(this._domBusy)},DialogUI.prototype.unmount=function(){return DialogUI.__super__.unmount.call(this),this._domBusy=null,this._domCaption=null,this._domClose=null,this._domControls=null,this._domView=null},DialogUI.prototype._addDOMEventListeners=function(){return this._handleEscape=function(_this){return function(ev){return _this._busy?void 0:27===ev.keyCode?_this.trigger("cancel"):void 0}}(this),document.addEventListener("keyup",this._handleEscape),this._domClose.addEventListener("click",function(_this){return function(ev){return ev.preventDefault(),_this._busy?void 0:_this.trigger("cancel")}}(this))},DialogUI.prototype._removeDOMEventListeners=function(){return document.removeEventListener("keyup",this._handleEscape)},DialogUI}(ContentTools.WidgetUI),ContentTools.ImageDialog=function(_super){function ImageDialog(){ImageDialog.__super__.constructor.call(this,"Insert image"),this._cropMarks=null,this._imageURL=null,this._imageSize=null,this._progress=0,this._state="empty",ContentTools.IMAGE_UPLOADER&&ContentTools.IMAGE_UPLOADER(this)}return __extends(ImageDialog,_super),ImageDialog.prototype.cropRegion=function(){return this._cropMarks?this._cropMarks.region():[0,0,1,1]},ImageDialog.prototype.addCropMarks=function(){return this._cropMarks?void 0:(this._cropMarks=new CropMarksUI(this._imageSize),this._cropMarks.mount(this._domView),ContentEdit.addCSSClass(this._domCrop,"ct-control--active"))},ImageDialog.prototype.clear=function(){return this._domImage&&(this._domImage.parentNode.removeChild(this._domImage),this._domImage=null),this._imageURL=null,this._imageSize=null,this.state("empty")},ImageDialog.prototype.mount=function(){var domActions,domProgressBar,domTools;return ImageDialog.__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"),domTools=this.constructor.createDiv(["ct-control-group","ct-control-group--left"]),this._domControls.appendChild(domTools),this._domRotateCCW=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--rotate-ccw"]),this._domRotateCCW.setAttribute("data-tooltip",ContentEdit._("Rotate")+" -90°"),domTools.appendChild(this._domRotateCCW),this._domRotateCW=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--rotate-cw"]),this._domRotateCW.setAttribute("data-tooltip",ContentEdit._("Rotate")+" 90°"),domTools.appendChild(this._domRotateCW),this._domCrop=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--crop"]),this._domCrop.setAttribute("data-tooltip",ContentEdit._("Crop marks")),domTools.appendChild(this._domCrop),domProgressBar=this.constructor.createDiv(["ct-progress-bar"]),domTools.appendChild(domProgressBar),this._domProgress=this.constructor.createDiv(["ct-progress-bar__progress"]),domProgressBar.appendChild(this._domProgress),domActions=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]),this._domControls.appendChild(domActions),this._domUpload=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--upload"]),this._domUpload.textContent=ContentEdit._("Upload"),domActions.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"),domActions.appendChild(this._domInsert),this._domCancelUpload=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--cancel"]),this._domCancelUpload.textContent=ContentEdit._("Cancel"),domActions.appendChild(this._domCancelUpload),this._domClear=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--clear"]),this._domClear.textContent=ContentEdit._("Clear"),domActions.appendChild(this._domClear),this._addDOMEventListeners(),this.trigger("imageUploader.mount")},ImageDialog.prototype.populate=function(imageURL,imageSize){return this._imageURL=imageURL,this._imageSize=imageSize,this._domImage||(this._domImage=this.constructor.createDiv(["ct-image-dialog__image"]),this._domView.appendChild(this._domImage)),this._domImage.style["background-image"]="url("+imageURL+")",this.state("populated")},ImageDialog.prototype.progress=function(progress){return void 0===progress?this._progress:(this._progress=progress,this.isMounted()?this._domProgress.style.width=""+this._progress+"%":void 0)},ImageDialog.prototype.removeCropMarks=function(){return this._cropMarks?(this._cropMarks.unmount(),this._cropMarks=null,ContentEdit.removeCSSClass(this._domCrop,"ct-control--active")):void 0},ImageDialog.prototype.save=function(imageURL,imageSize,imageAttrs){return this.trigger("save",imageURL,imageSize,imageAttrs)},ImageDialog.prototype.state=function(state){var prevState;if(void 0===state)return this._state;if(this._state!==state&&(prevState=this._state,this._state=state,this.isMounted()))return ContentEdit.addCSSClass(this._domElement,"ct-image-dialog--"+this._state),ContentEdit.removeCSSClass(this._domElement,"ct-image-dialog--"+prevState)},ImageDialog.prototype.unmount=function(){return ImageDialog.__super__.unmount.call(this),this._domCancelUpload=null,this._domClear=null,this._domCrop=null,this._domInput=null,this._domInsert=null,this._domProgress=null,this._domRotateCCW=null,this._domRotateCW=null,this._domUpload=null,this.trigger("imageUploader.unmount")},ImageDialog.prototype._addDOMEventListeners=function(){return ImageDialog.__super__._addDOMEventListeners.call(this),this._domInput.addEventListener("change",function(_this){return function(ev){var file;return file=ev.target.files[0],ev.target.value="",ev.target.value&&(ev.target.type="text",ev.target.type="file"),_this.trigger("imageUploader.fileReady",file)}}(this)),this._domCancelUpload.addEventListener("click",function(_this){return function(){return _this.trigger("imageUploader.cancelUpload")}}(this)),this._domClear.addEventListener("click",function(_this){return function(){return _this.removeCropMarks(),_this.trigger("imageUploader.clear")}}(this)),this._domRotateCCW.addEventListener("click",function(_this){return function(){return _this.removeCropMarks(),_this.trigger("imageUploader.rotateCCW")}}(this)),this._domRotateCW.addEventListener("click",function(_this){return function(){return _this.removeCropMarks(),_this.trigger("imageUploader.rotateCW")}}(this)),this._domCrop.addEventListener("click",function(_this){return function(){return _this._cropMarks?_this.removeCropMarks():_this.addCropMarks()}}(this)),this._domInsert.addEventListener("click",function(_this){return function(){return _this.trigger("imageUploader.save")}}(this))},ImageDialog}(ContentTools.DialogUI),CropMarksUI=function(_super){function CropMarksUI(imageSize){CropMarksUI.__super__.constructor.call(this),this._bounds=null,this._dragging=null,this._draggingOrigin=null,this._imageSize=imageSize}return __extends(CropMarksUI,_super),CropMarksUI.prototype.mount=function(domParent,before){return null==before&&(before=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]),CropMarksUI.__super__.mount.call(this,domParent,before),this._fit(domParent)},CropMarksUI.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]]},CropMarksUI.prototype.unmount=function(){return CropMarksUI.__super__.unmount.call(this),this._domClipper=null,this._domHandles=null,this._domRulers=null},CropMarksUI.prototype._addDOMEventListeners=function(){return CropMarksUI.__super__._addDOMEventListeners.call(this),this._domHandles[0].addEventListener("mousedown",function(_this){return function(ev){return 0===ev.button?_this._startDrag(0,ev.clientY,ev.clientX):void 0}}(this)),this._domHandles[1].addEventListener("mousedown",function(_this){return function(ev){return 0===ev.button?_this._startDrag(1,ev.clientY,ev.clientX):void 0}}(this))},CropMarksUI.prototype._drag=function(top,left){var height,minCrop,offsetLeft,offsetTop,width;if(null!==this._dragging)return ContentSelect.Range.unselectAll(),offsetTop=top-this._draggingOrigin[1],offsetLeft=left-this._draggingOrigin[0],height=this._bounds[1],left=0,top=0,width=this._bounds[0],minCrop=Math.min(Math.min(ContentTools.MIN_CROP,height),width),0===this._dragging?(height=parseInt(this._domHandles[1].style.top)-minCrop,width=parseInt(this._domHandles[1].style.left)-minCrop):(left=parseInt(this._domHandles[0].style.left)+minCrop,top=parseInt(this._domHandles[0].style.top)+minCrop),offsetTop=Math.min(Math.max(top,offsetTop),height),offsetLeft=Math.min(Math.max(left,offsetLeft),width),this._domHandles[this._dragging].style.top=""+offsetTop+"px",this._domHandles[this._dragging].style.left=""+offsetLeft+"px",this._domRulers[this._dragging].style.top=""+offsetTop+"px",this._domRulers[this._dragging].style.left=""+offsetLeft+"px"},CropMarksUI.prototype._fit=function(domParent){var height,heightScale,left,ratio,rect,top,width,widthScale;return rect=domParent.getBoundingClientRect(),widthScale=rect.width/this._imageSize[0],heightScale=rect.height/this._imageSize[1],ratio=Math.min(widthScale,heightScale),width=ratio*this._imageSize[0],height=ratio*this._imageSize[1],left=(rect.width-width)/2,top=(rect.height-height)/2,this._domElement.style.width=""+width+"px",this._domElement.style.height=""+height+"px",this._domElement.style.top=""+top+"px",this._domElement.style.left=""+left+"px",this._domHandles[0].style.top="0px",this._domHandles[0].style.left="0px",this._domHandles[1].style.top=""+height+"px",this._domHandles[1].style.left=""+width+"px",this._domRulers[0].style.top="0px",this._domRulers[0].style.left="0px",this._domRulers[1].style.top=""+height+"px",this._domRulers[1].style.left=""+width+"px",this._bounds=[width,height]},CropMarksUI.prototype._startDrag=function(handleIndex,top,left){var domHandle;return domHandle=this._domHandles[handleIndex],this._dragging=handleIndex,this._draggingOrigin=[left-parseInt(domHandle.style.left),top-parseInt(domHandle.style.top)],this._onMouseMove=function(_this){return function(ev){return _this._drag(ev.clientY,ev.clientX)}}(this),document.addEventListener("mousemove",this._onMouseMove),this._onMouseUp=function(_this){return function(){return _this._stopDrag()}}(this),document.addEventListener("mouseup",this._onMouseUp)},CropMarksUI.prototype._stopDrag=function(){return document.removeEventListener("mousemove",this._onMouseMove),document.removeEventListener("mouseup",this._onMouseUp),this._dragging=null,this._draggingOrigin=null},CropMarksUI}(ContentTools.AnchoredComponentUI),ContentTools.LinkDialog=function(_super){function LinkDialog(initialValue){null==initialValue&&(initialValue=""),LinkDialog.__super__.constructor.call(this),this._initialValue=initialValue}return __extends(LinkDialog,_super),LinkDialog.prototype.mount=function(){return LinkDialog.__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._initialValue),this._domElement.appendChild(this._domInput),this._domButton=this.constructor.createDiv(["ct-anchored-dialog__button"]),this._domElement.appendChild(this._domButton),this._addDOMEventListeners()},LinkDialog.prototype.save=function(){return this.isMounted?this.trigger("save",this._domInput.value.trim()):this.trigger("save","")},LinkDialog.prototype.show=function(){return LinkDialog.__super__.show.call(this),this._domInput.focus(),this._initialValue?this._domInput.select():void 0},LinkDialog.prototype.unmount=function(){return this.isMounted()&&this._domInput.blur(),LinkDialog.__super__.unmount.call(this),this._domButton=null,this._domInput=null},LinkDialog.prototype._addDOMEventListeners=function(){return this._domInput.addEventListener("keypress",function(_this){return function(ev){return 13===ev.keyCode?_this.save():void 0}}(this)),this._domButton.addEventListener("click",function(_this){return function(ev){return ev.preventDefault(),_this.save()}}(this))},LinkDialog}(ContentTools.AnchoredDialogUI),ContentTools.PropertiesDialog=function(_super){function PropertiesDialog(element){var _ref;this.element=element,PropertiesDialog.__super__.constructor.call(this,"Properties"),this._attributeUIs=[],this._focusedAttributeUI=null,this._styleUIs=[],this._supportsCoding=element.content,("ListItem"===(_ref=element.constructor.name)||"TableCell"===_ref)&&(this._supportsCoding=!0)}return __extends(PropertiesDialog,_super),PropertiesDialog.prototype.caption=function(caption){return void 0===caption?this._caption:(this._caption=caption,this._domCaption.textContent=ContentEdit._(caption)+(": "+this.element.tagName()))},PropertiesDialog.prototype.changedAttributes=function(){var attributeUI,attributes,changedAttributes,name,restricted,value,_i,_len,_ref,_ref1;for(attributes={},changedAttributes={},_ref=this._attributeUIs,_i=0,_len=_ref.length;_len>_i;_i++)attributeUI=_ref[_i],name=attributeUI.name(),value=attributeUI.value(),""!==name&&(attributes[name.toLowerCase()]=!0,this.element.attr(name)!==value&&(changedAttributes[name]=value));restricted=ContentTools.RESTRICTED_ATTRIBUTES[this.element.tagName()],_ref1=this.element.attributes();for(name in _ref1)value=_ref1[name],restricted&&-1!==restricted.indexOf(name.toLowerCase())||void 0===attributes[name]&&(changedAttributes[name]=null);return changedAttributes},PropertiesDialog.prototype.changedStyles=function(){var cssClass,styleUI,styles,_i,_len,_ref;for(styles={},_ref=this._styleUIs,_i=0,_len=_ref.length;_len>_i;_i++)styleUI=_ref[_i],cssClass=styleUI.style.cssClass(),this.element.hasCSSClass(cssClass)!==styleUI.applied()&&(styles[cssClass]=styleUI.applied());return styles},PropertiesDialog.prototype.getElementInnerHTML=function(){return this._supportsCoding?this.element.content?this.element.content.html():this.element.children[0].content.html():null},PropertiesDialog.prototype.mount=function(){var attributeNames,attributes,domActions,domTabs,lastTab,name,restricted,style,styleUI,value,_i,_j,_len,_len1,_ref;for(PropertiesDialog.__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),_ref=ContentTools.StylePalette.styles(this.element.tagName()),_i=0,_len=_ref.length;_len>_i;_i++)style=_ref[_i],styleUI=new StyleUI(style,this.element.hasCSSClass(style.cssClass())),this._styleUIs.push(styleUI),styleUI.mount(this._domStyles);this._domAttributes=this.constructor.createDiv(["ct-properties-dialog__attributes"]),this._domView.appendChild(this._domAttributes),restricted=ContentTools.RESTRICTED_ATTRIBUTES[this.element.tagName()],attributes=this.element.attributes(),attributeNames=[];for(name in attributes)value=attributes[name],restricted&&-1!==restricted.indexOf(name.toLowerCase())||attributeNames.push(name);for(attributeNames.sort(),_j=0,_len1=attributeNames.length;_len1>_j;_j++)name=attributeNames[_j],value=attributes[name],this._addAttributeUI(name,value);return 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),domTabs=this.constructor.createDiv(["ct-control-group","ct-control-group--left"]),this._domControls.appendChild(domTabs),this._domStylesTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--styles"]),this._domStylesTab.setAttribute("data-tooltip",ContentEdit._("Styles")),domTabs.appendChild(this._domStylesTab),this._domAttributesTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--attributes"]),this._domAttributesTab.setAttribute("data-tooltip",ContentEdit._("Attributes")),domTabs.appendChild(this._domAttributesTab),this._domCodeTab=this.constructor.createDiv(["ct-control","ct-control--icon","ct-control--code"]),this._domCodeTab.setAttribute("data-tooltip",ContentEdit._("Code")),domTabs.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-tooltip",ContentEdit._("Remove")),domTabs.appendChild(this._domRemoveAttribute),domActions=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]),this._domControls.appendChild(domActions),this._domApply=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--apply"]),this._domApply.textContent=ContentEdit._("Apply"),domActions.appendChild(this._domApply),lastTab=window.localStorage.getItem("ct-properties-dialog-tab"),"attributes"===lastTab?(ContentEdit.addCSSClass(this._domElement,"ct-properties-dialog--attributes"),ContentEdit.addCSSClass(this._domAttributesTab,"ct-control--active")):"code"===lastTab&&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")),this._addDOMEventListeners()},PropertiesDialog.prototype.save=function(){var innerHTML;return innerHTML=null,this._supportsCoding&&(innerHTML=this._domInnerHTML.value),this.trigger("save",this.changedAttributes(),this.changedStyles(),innerHTML)},PropertiesDialog.prototype._addAttributeUI=function(name,value){var attributeUI,dialog;return dialog=this,attributeUI=new AttributeUI(name,value),this._attributeUIs.push(attributeUI),attributeUI.bind("blur",function(){var index,lastAttributeUI,length;return dialog._focusedAttributeUI=null,ContentEdit.addCSSClass(dialog._domRemoveAttribute,"ct-control--muted"),index=dialog._attributeUIs.indexOf(this),length=dialog._attributeUIs.length,""===this.name()&&length-1>index&&(this.unmount(),dialog._attributeUIs.splice(index,1)),lastAttributeUI=dialog._attributeUIs[length-1],lastAttributeUI&&lastAttributeUI.name()&&lastAttributeUI.value()?dialog._addAttributeUI("",""):void 0}),attributeUI.bind("focus",function(){return dialog._focusedAttributeUI=this,ContentEdit.removeCSSClass(dialog._domRemoveAttribute,"ct-control--muted")}),attributeUI.bind("namechange",function(){var element,otherAttributeUI,restricted,valid,_i,_len,_ref;for(element=dialog.element,name=this.name().toLowerCase(),restricted=ContentTools.RESTRICTED_ATTRIBUTES[element.tagName()],valid=!0,restricted&&-1!==restricted.indexOf(name)&&(valid=!1),_ref=dialog._attributeUIs,_i=0,_len=_ref.length;_len>_i;_i++)otherAttributeUI=_ref[_i],""!==name&&otherAttributeUI!==this&&otherAttributeUI.name().toLowerCase()===name&&(valid=!1);return this.valid(valid),valid?ContentEdit.removeCSSClass(dialog._domApply,"ct-control--muted"):ContentEdit.addCSSClass(dialog._domApply,"ct-control--muted")}),attributeUI.mount(this._domAttributes),attributeUI},PropertiesDialog.prototype._addDOMEventListeners=function(){var selectTab,validateCode;return PropertiesDialog.__super__._addDOMEventListeners.call(this),selectTab=function(_this){return function(selected){var selectedCap,tab,tabCap,tabs,_i,_len;for(tabs=["attributes","code","styles"],_i=0,_len=tabs.length;_len>_i;_i++)tab=tabs[_i],tab!==selected&&(tabCap=tab.charAt(0).toUpperCase()+tab.slice(1),ContentEdit.removeCSSClass(_this._domElement,"ct-properties-dialog--"+tab),ContentEdit.removeCSSClass(_this["_dom"+tabCap+"Tab"],"ct-control--active"));return selectedCap=selected.charAt(0).toUpperCase()+selected.slice(1),ContentEdit.addCSSClass(_this._domElement,"ct-properties-dialog--"+selected),ContentEdit.addCSSClass(_this["_dom"+selectedCap+"Tab"],"ct-control--active"),window.localStorage.setItem("ct-properties-dialog-tab",selected)}}(this),this._domStylesTab.addEventListener("mousedown",function(){return function(){return selectTab("styles")}}(this)),this._domAttributesTab.addEventListener("mousedown",function(){return function(){return selectTab("attributes")}}(this)),this._domCodeTab.addEventListener("mousedown",function(){return function(){return selectTab("code")}}(this)),this._domRemoveAttribute.addEventListener("mousedown",function(_this){return function(ev){var index,last;return ev.preventDefault(),_this._focusedAttributeUI&&(index=_this._attributeUIs.indexOf(_this._focusedAttributeUI),last=index===_this._attributeUIs.length-1,_this._focusedAttributeUI.unmount(),_this._attributeUIs.splice(index,1),last)?_this._addAttributeUI("",""):void 0}}(this)),validateCode=function(_this){return function(){var content;try{return content=new HTMLString.String(_this._domInnerHTML.value),ContentEdit.removeCSSClass(_this._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.removeCSSClass(_this._domApply,"ct-control--muted")}catch(_error){return ContentEdit.addCSSClass(_this._domInnerHTML,"ct-properties-dialog__inner-html--invalid"),ContentEdit.addCSSClass(_this._domApply,"ct-control--muted")}}}(this),this._domInnerHTML.addEventListener("input",validateCode),this._domInnerHTML.addEventListener("propertychange",validateCode),this._domApply.addEventListener("click",function(_this){return function(ev){var cssClass;return ev.preventDefault(),cssClass=_this._domApply.getAttribute("class"),-1===cssClass.indexOf("ct-control--muted")?_this.save():void 0}}(this))},PropertiesDialog}(ContentTools.DialogUI),StyleUI=function(_super){function StyleUI(style,applied){this.style=style,StyleUI.__super__.constructor.call(this),this._applied=applied}return __extends(StyleUI,_super),StyleUI.prototype.applied=function(applied){if(void 0===applied)return this._applied;if(this._applied!==applied)return this._applied=applied,this._applied?ContentEdit.addCSSClass(this._domElement,"ct-section--applied"):ContentEdit.removeCSSClass(this._domElement,"ct-section--applied")},StyleUI.prototype.mount=function(domParent,before){var label;return null==before&&(before=null),this._domElement=this.constructor.createDiv(["ct-section"]),this._applied&&ContentEdit.addCSSClass(this._domElement,"ct-section--applied"),label=this.constructor.createDiv(["ct-section__label"]),label.textContent=this.style.name(),this._domElement.appendChild(label),this._domElement.appendChild(this.constructor.createDiv(["ct-section__switch"])),StyleUI.__super__.mount.call(this,domParent,before)},StyleUI.prototype._addDOMEventListeners=function(){var toggleSection;return toggleSection=function(_this){return function(ev){return ev.preventDefault(),_this.applied(_this.applied()?!1:!0)}}(this),this._domElement.addEventListener("click",toggleSection)},StyleUI}(ContentTools.AnchoredComponentUI),AttributeUI=function(_super){function AttributeUI(name,value){AttributeUI.__super__.constructor.call(this),this._initialName=name,this._initialValue=value}return __extends(AttributeUI,_super),AttributeUI.prototype.name=function(){return this._domName.value.trim()},AttributeUI.prototype.value=function(){return this._domValue.value.trim()},AttributeUI.prototype.mount=function(domParent,before){return null==before&&(before=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),AttributeUI.__super__.mount.call(this,domParent,before)},AttributeUI.prototype.valid=function(valid){return valid?ContentEdit.removeCSSClass(this._domName,"ct-attribute__name--invalid"):ContentEdit.addCSSClass(this._domName,"ct-attribute__name--invalid")},AttributeUI.prototype._addDOMEventListeners=function(){return this._domName.addEventListener("blur",function(_this){return function(){var name,nextDomAttribute,nextNameDom;return name=_this.name(),nextDomAttribute=_this._domElement.nextSibling,_this.trigger("blur"),""===name&&nextDomAttribute?(nextNameDom=nextDomAttribute.querySelector(".ct-attribute__name"),nextNameDom.focus()):void 0}}(this)),this._domName.addEventListener("focus",function(_this){return function(){return _this.trigger("focus")}}(this)),this._domName.addEventListener("input",function(_this){return function(){return _this.trigger("namechange")}}(this)),this._domName.addEventListener("keydown",function(_this){return function(ev){return 13===ev.keyCode?_this._domValue.focus():void 0}}(this)),this._domValue.addEventListener("blur",function(_this){return function(){return _this.trigger("blur")}}(this)),this._domValue.addEventListener("focus",function(_this){return function(){return _this.trigger("focus")}}(this)),this._domValue.addEventListener("keydown",function(_this){return function(ev){var nextDomAttribute,nextNameDom;if(13===ev.keyCode||9===ev.keyCode&&!ev.shiftKey)return ev.preventDefault(),nextDomAttribute=_this._domElement.nextSibling,nextDomAttribute||(_this._domValue.blur(),nextDomAttribute=_this._domElement.nextSibling),nextDomAttribute?(nextNameDom=nextDomAttribute.querySelector(".ct-attribute__name"),nextNameDom.focus()):void 0}}(this))},AttributeUI}(ContentTools.AnchoredComponentUI),ContentTools.TableDialog=function(_super){function TableDialog(table){this.table=table,this.table?TableDialog.__super__.constructor.call(this,"Update table"):TableDialog.__super__.constructor.call(this,"Insert table")}return __extends(TableDialog,_super),TableDialog.prototype.mount=function(){var cfg,domBodyLabel,domControlGroup,domFootLabel,domHeadLabel,footCSSClasses,headCSSClasses;return TableDialog.__super__.mount.call(this),cfg={columns:3,foot:!1,head:!0},this.table&&(cfg={columns:this.table.firstSection().children[0].children.length,foot:this.table.tfoot(),head:this.table.thead()}),ContentEdit.addCSSClass(this._domElement,"ct-table-dialog"),ContentEdit.addCSSClass(this._domView,"ct-table-dialog__view"),headCSSClasses=["ct-section"],cfg.head&&headCSSClasses.push("ct-section--applied"),this._domHeadSection=this.constructor.createDiv(headCSSClasses),this._domView.appendChild(this._domHeadSection),domHeadLabel=this.constructor.createDiv(["ct-section__label"]),domHeadLabel.textContent=ContentEdit._("Table head"),this._domHeadSection.appendChild(domHeadLabel),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),domBodyLabel=this.constructor.createDiv(["ct-section__label"]),domBodyLabel.textContent=ContentEdit._("Table body (columns)"),this._domBodySection.appendChild(domBodyLabel),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",cfg.columns),this._domBodySection.appendChild(this._domBodyInput),footCSSClasses=["ct-section"],cfg.foot&&footCSSClasses.push("ct-section--applied"),this._domFootSection=this.constructor.createDiv(footCSSClasses),this._domView.appendChild(this._domFootSection),domFootLabel=this.constructor.createDiv(["ct-section__label"]),domFootLabel.textContent=ContentEdit._("Table foot"),this._domFootSection.appendChild(domFootLabel),this._domFootSwitch=this.constructor.createDiv(["ct-section__switch"]),this._domFootSection.appendChild(this._domFootSwitch),domControlGroup=this.constructor.createDiv(["ct-control-group","ct-control-group--right"]),this._domControls.appendChild(domControlGroup),this._domApply=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--apply"]),this._domApply.textContent="Apply",domControlGroup.appendChild(this._domApply),this._addDOMEventListeners()},TableDialog.prototype.save=function(){var footCSSClass,headCSSClass,tableCfg;return footCSSClass=this._domFootSection.getAttribute("class"),headCSSClass=this._domHeadSection.getAttribute("class"),tableCfg={columns:parseInt(this._domBodyInput.value),foot:footCSSClass.indexOf("ct-section--applied")>-1,head:headCSSClass.indexOf("ct-section--applied")>-1},this.trigger("save",tableCfg)},TableDialog.prototype.unmount=function(){return TableDialog.__super__.unmount.call(this),this._domBodyInput=null,this._domBodySection=null,this._domApply=null,this._domHeadSection=null,this._domHeadSwitch=null,this._domFootSection=null,this._domFootSwitch=null
  },TableDialog.prototype._addDOMEventListeners=function(){var toggleSection;return TableDialog.__super__._addDOMEventListeners.call(this),toggleSection=function(ev){return ev.preventDefault(),this.getAttribute("class").indexOf("ct-section--applied")>-1?ContentEdit.removeCSSClass(this,"ct-section--applied"):ContentEdit.addCSSClass(this,"ct-section--applied")},this._domHeadSection.addEventListener("click",toggleSection),this._domFootSection.addEventListener("click",toggleSection),this._domBodySection.addEventListener("click",function(_this){return function(){return _this._domBodyInput.focus()}}(this)),this._domBodyInput.addEventListener("input",function(_this){return function(ev){var valid;return valid=/^[1-9]\d{0,1}$/.test(ev.target.value),valid?(ContentEdit.removeCSSClass(_this._domBodyInput,"ct-section__input--invalid"),ContentEdit.removeCSSClass(_this._domApply,"ct-control--muted")):(ContentEdit.addCSSClass(_this._domBodyInput,"ct-section__input--invalid"),ContentEdit.addCSSClass(_this._domApply,"ct-control--muted"))}}(this)),this._domApply.addEventListener("click",function(_this){return function(ev){var cssClass;return ev.preventDefault(),cssClass=_this._domApply.getAttribute("class"),-1===cssClass.indexOf("ct-control--muted")?_this.save():void 0}}(this))},TableDialog}(ContentTools.DialogUI),ContentTools.VideoDialog=function(_super){function VideoDialog(){VideoDialog.__super__.constructor.call(this,"Insert video")}return __extends(VideoDialog,_super),VideoDialog.prototype.clearPreview=function(){return this._domPreview?(this._domPreview.parentNode.removeChild(this._domPreview),this._domPreview=void 0):void 0},VideoDialog.prototype.mount=function(){var domControlGroup;return VideoDialog.__super__.mount.call(this),ContentEdit.addCSSClass(this._domElement,"ct-video-dialog"),ContentEdit.addCSSClass(this._domView,"ct-video-dialog__preview"),domControlGroup=this.constructor.createDiv(["ct-control-group"]),this._domControls.appendChild(domControlGroup),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"),domControlGroup.appendChild(this._domInput),this._domButton=this.constructor.createDiv(["ct-control","ct-control--text","ct-control--insert","ct-control--muted"]),this._domButton.textContent=ContentEdit._("Insert"),domControlGroup.appendChild(this._domButton),this._addDOMEventListeners()},VideoDialog.prototype.preview=function(url){return this.clearPreview(),this._domPreview=document.createElement("iframe"),this._domPreview.setAttribute("frameborder","0"),this._domPreview.setAttribute("height","100%"),this._domPreview.setAttribute("src",url),this._domPreview.setAttribute("width","100%"),this._domView.appendChild(this._domPreview)},VideoDialog.prototype.save=function(){var embedURL,videoURL;return videoURL=this._domInput.value.trim(),embedURL=ContentTools.getEmbedVideoURL(videoURL),embedURL?this.trigger("save",embedURL):this.trigger("save",videoURL)},VideoDialog.prototype.show=function(){return VideoDialog.__super__.show.call(this),this._domInput.focus()},VideoDialog.prototype.unmount=function(){return this.isMounted()&&this._domInput.blur(),VideoDialog.__super__.unmount.call(this),this._domButton=null,this._domInput=null,this._domPreview=null},VideoDialog.prototype._addDOMEventListeners=function(){return VideoDialog.__super__._addDOMEventListeners.call(this),this._domInput.addEventListener("input",function(_this){return function(ev){var updatePreview;return ev.target.value?ContentEdit.removeCSSClass(_this._domButton,"ct-control--muted"):ContentEdit.addCSSClass(_this._domButton,"ct-control--muted"),_this._updatePreviewTimeout&&clearTimeout(_this._updatePreviewTimeout),updatePreview=function(){var embedURL,videoURL;return videoURL=_this._domInput.value.trim(),embedURL=ContentTools.getEmbedVideoURL(videoURL),embedURL?_this.preview(embedURL):_this.clearPreview()},_this._updatePreviewTimeout=setTimeout(updatePreview,500)}}(this)),this._domInput.addEventListener("keypress",function(_this){return function(ev){return 13===ev.keyCode?_this.save():void 0}}(this)),this._domButton.addEventListener("click",function(_this){return function(ev){var cssClass;return ev.preventDefault(),cssClass=_this._domButton.getAttribute("class"),-1===cssClass.indexOf("ct-control--muted")?_this.save():void 0}}(this))},VideoDialog}(ContentTools.DialogUI),_EditorApp=function(_super){function _EditorApp(){_EditorApp.__super__.constructor.call(this),this.history=null,this._state=ContentTools.EditorApp.DORMANT,this._regions=null,this._orderedRegions=null,this._rootLastModified=null,this._regionsLastModified={},this._ignition=null,this._inspector=null,this._toolbox=null}return __extends(_EditorApp,_super),_EditorApp.prototype.ctrlDown=function(){return this._ctrlDown},_EditorApp.prototype.domRegions=function(){return this._domRegions},_EditorApp.prototype.orderedRegions=function(){var name;return function(){var _i,_len,_ref,_results;for(_ref=this._orderedRegions,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)name=_ref[_i],_results.push(this._regions[name]);return _results}.call(this)},_EditorApp.prototype.regions=function(){return this._regions},_EditorApp.prototype.shiftDown=function(){return this._shiftDown},_EditorApp.prototype.busy=function(busy){return this._ignition.busy(busy)},_EditorApp.prototype.init=function(queryOrDOMElements,namingProp){return null==namingProp&&(namingProp="id"),this._namingProp=namingProp,this._domRegions=queryOrDOMElements.length>0&&queryOrDOMElements[0].nodeType===Node.ELEMENT_NODE?queryOrDOMElements:document.querySelectorAll(queryOrDOMElements),0!==this._domRegions.length?(this.mount(),this._ignition=new ContentTools.IgnitionUI,this.attach(this._ignition),this._ignition.bind("start",function(_this){return function(){return _this.start()}}(this)),this._ignition.bind("stop",function(_this){return function(save){var focused;if(focused=ContentEdit.Root.get().focused(),focused&&void 0!==focused._syncContent&&focused._syncContent(),save)_this.save();else if(!_this.revert())return void _this._ignition.changeState("editing");return _this.stop()}}(this)),this._domRegions.length&&this._ignition.show(),this._toolbox=new ContentTools.ToolboxUI(ContentTools.DEFAULT_TOOLS),this.attach(this._toolbox),this._inspector=new ContentTools.InspectorUI,this.attach(this._inspector),this._state=ContentTools.EditorApp.READY,ContentEdit.Root.get().bind("detach",function(_this){return function(){return _this._preventEmptyRegions()}}(this)),ContentEdit.Root.get().bind("paste",function(_this){return function(element,ev){return _this.paste(element,ev.clipboardData)}}(this)),ContentEdit.Root.get().bind("next-region",function(_this){return function(region){var child,element,index,regions,_i,_len,_ref;if(regions=_this.orderedRegions(),index=regions.indexOf(region),!(index>=regions.length-1)){for(region=regions[index+1],element=null,_ref=region.descendants(),_i=0,_len=_ref.length;_len>_i;_i++)if(child=_ref[_i],void 0!==child.content){element=child;break}return element?(element.focus(),void element.selection(new ContentSelect.Range(0,0))):ContentEdit.Root.get().trigger("next-region",region)}}}(this)),ContentEdit.Root.get().bind("previous-region",function(_this){return function(region){var child,descendants,element,index,length,regions,_i,_len;if(regions=_this.orderedRegions(),index=regions.indexOf(region),!(0>=index)){for(region=regions[index-1],element=null,descendants=region.descendants(),descendants.reverse(),_i=0,_len=descendants.length;_len>_i;_i++)if(child=descendants[_i],void 0!==child.content){element=child;break}return element?(length=element.content.length(),element.focus(),void element.selection(new ContentSelect.Range(length,length))):ContentEdit.Root.get().trigger("previous-region",region)}}}(this))):void 0},_EditorApp.prototype.destroy=function(){return this.unmount()},_EditorApp.prototype.highlightRegions=function(highlight){var domRegion,_i,_len,_ref,_results;for(_ref=this._domRegions,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)domRegion=_ref[_i],_results.push(highlight?ContentEdit.addCSSClass(domRegion,"ct--highlight"):ContentEdit.removeCSSClass(domRegion,"ct--highlight"));return _results},_EditorApp.prototype.mount=function(){return this._domElement=this.constructor.createDiv(["ct-app"]),document.body.insertBefore(this._domElement,null),this._addDOMEventListeners()},_EditorApp.prototype.paste=function(element,clipboardData){var className,content,cursor,encodeHTML,i,insertAt,insertIn,insertNode,item,itemText,lastItem,line,lineLength,lines,selection,tail,tip,_i,_len;if(content=clipboardData.getData("text/plain"),lines=content.split("\n"),lines=lines.filter(function(line){return""!==line.trim()})){if(encodeHTML=HTMLString.String.encode,className=element.constructor.name,(lines.length>1||!element.content)&&"PreText"!==className){for("ListItemText"===className?(insertNode=element.parent(),insertIn=element.parent().parent(),insertAt=insertIn.children.indexOf(insertNode)+1):(insertNode=element,"Region"!==insertNode.parent().constructor.name&&(insertNode=element.closest(function(node){return"Region"===node.parent().constructor.name})),insertIn=insertNode.parent(),insertAt=insertIn.children.indexOf(insertNode)+1),i=_i=0,_len=lines.length;_len>_i;i=++_i)line=lines[i],line=encodeHTML(line),"ListItemText"===className?(item=new ContentEdit.ListItem,itemText=new ContentEdit.ListItemText(line),item.attach(itemText),lastItem=itemText):(item=new ContentEdit.Text("p",{},line),lastItem=item),insertIn.attach(item,insertAt+i);return lineLength=lastItem.content.length(),lastItem.focus(),lastItem.selection(new ContentSelect.Range(lineLength,lineLength))}return content=encodeHTML(content),content=new HTMLString.String(content,"PreText"===className),selection=element.selection(),cursor=selection.get()[0]+content.length(),tip=element.content.substring(0,selection.get()[0]),tail=element.content.substring(selection.get()[1]),element.content=tip.concat(content),element.content=element.content.concat(tail,!1),element.updateInnerHTML(),element.taint(),selection.set(cursor,cursor),element.selection(selection)}},_EditorApp.prototype.unmount=function(){return this.isMounted()?(this._domElement.parentNode.removeChild(this._domElement),this._domElement=null,this._removeDOMEventListeners(),this._ignition=null,this._inspector=null,this._toolbox=null):void 0},_EditorApp.prototype.revert=function(){var confirmMessage;return confirmMessage=ContentEdit._("Your changes have not been saved, do you really want to lose them?"),ContentEdit.Root.get().lastModified()>this._rootLastModified&&!window.confirm(confirmMessage)?!1:(this.revertToSnapshot(this.history.goTo(0),!1),!0)},_EditorApp.prototype.revertToSnapshot=function(snapshot,restoreEditable){var domRegion,i,name,region,_i,_len,_ref,_ref1;null==restoreEditable&&(restoreEditable=!0),_ref=this._regions;for(name in _ref)region=_ref[name],region.domElement().innerHTML=snapshot.regions[name];if(restoreEditable){for(this._regions={},_ref1=this._domRegions,i=_i=0,_len=_ref1.length;_len>_i;i=++_i)domRegion=_ref1[i],name=domRegion.getAttribute(this._namingProp),name||(name=i),this._regions[name]=new ContentEdit.Region(domRegion);return this.history.replaceRegions(this._regions),this.history.restoreSelection(snapshot)}},_EditorApp.prototype.save=function(){var args,child,html,modifiedRegions,name,passive,region,root,_ref;if(passive=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[],root=ContentEdit.Root.get(),root.lastModified()!==this._rootLastModified||!passive){modifiedRegions={},_ref=this._regions;for(name in _ref)region=_ref[name],html=region.html(),1===region.children.length&&(child=region.children[0],child.content&&!child.content.html()&&(html="")),passive||(region.domElement().innerHTML=html),region.lastModified()!==this._regionsLastModified[name]&&(modifiedRegions[name]=html);return this.trigger.apply(this,["save",modifiedRegions].concat(__slice.call(args)))}},_EditorApp.prototype.setRegionOrder=function(regionNames){return this._orderedRegions=regionNames.slice()},_EditorApp.prototype.start=function(){var domRegion,i,name,_i,_len,_ref;for(this.busy(!0),this._regions={},this._orderedRegions=[],_ref=this._domRegions,i=_i=0,_len=_ref.length;_len>_i;i=++_i)domRegion=_ref[i],name=domRegion.getAttribute(this._namingProp),name||(name=i),this._regions[name]=new ContentEdit.Region(domRegion),this._orderedRegions.push(name),this._regionsLastModified[name]=this._regions[name].lastModified();return this._preventEmptyRegions(),this._rootLastModified=ContentEdit.Root.get().lastModified(),this.history=new ContentTools.History(this._regions),this.history.watch(),this._state=ContentTools.EditorApp.EDITING,this._toolbox.show(),this._inspector.show(),this.busy(!1)},_EditorApp.prototype.stop=function(){return ContentEdit.Root.get().focused()&&ContentEdit.Root.get().focused().blur(),this.history.stopWatching(),this.history=null,this._toolbox.hide(),this._inspector.hide(),this._regions={},this._state=ContentTools.EditorApp.READY},_EditorApp.prototype._addDOMEventListeners=function(){return this._handleHighlightOn=function(_this){return function(ev){var _ref;if(17===(_ref=ev.keyCode)||224===_ref)return void(_this._ctrlDown=!0);if(16===ev.keyCode){if(_this._highlightTimeout)return;return _this._shiftDown=!0,_this._highlightTimeout=setTimeout(function(){return _this.highlightRegions(!0)},ContentTools.HIGHLIGHT_HOLD_DURATION)}}}(this),this._handleHighlightOff=function(_this){return function(ev){var _ref;return 17===(_ref=ev.keyCode)||224===_ref?void(_this._ctrlDown=!1):16===ev.keyCode?(_this._shiftDown=!1,_this._highlightTimeout&&(clearTimeout(_this._highlightTimeout),_this._highlightTimeout=null),_this.highlightRegions(!1)):void 0}}(this),document.addEventListener("keydown",this._handleHighlightOn),document.addEventListener("keyup",this._handleHighlightOff),window.onbeforeunload=function(_this){return function(){return _this._state===ContentTools.EditorApp.EDITING?ContentEdit._("Your changes have not been saved, do you really want to lose them?"):void 0}}(this),window.addEventListener("unload",function(_this){return function(){return _this.destroy()}}(this))},_EditorApp.prototype._preventEmptyRegions=function(){var name,placeholder,region,_ref,_results;_ref=this._regions,_results=[];for(name in _ref)region=_ref[name],region.children.length>0||(placeholder=new ContentEdit.Text("p",{},""),region.attach(placeholder),_results.push(region.commit()));return _results},_EditorApp.prototype._removeDOMEventListeners=function(){return document.removeEventListener("keydown",this._handleHighlightOn),document.removeEventListener("keyup",this._handleHighlightOff)},_EditorApp}(ContentTools.ComponentUI),ContentTools.EditorApp=function(){function EditorApp(){}var instance;return EditorApp.DORMANT="dormant",EditorApp.READY="ready",EditorApp.EDITING="editing",instance=null,EditorApp.get=function(){var cls;return cls=ContentTools.EditorApp.getCls(),null!=instance?instance:instance=new cls},EditorApp.getCls=function(){return _EditorApp},EditorApp}(),ContentTools.History=function(){function History(regions){this._lastSnapshotTaken=null,this._regions={},this.replaceRegions(regions),this._snapshotIndex=-1,this._snapshots=[],this._store()}return History.prototype.canRedo=function(){return this._snapshotIndex<this._snapshots.length-1},History.prototype.canUndo=function(){return this._snapshotIndex>0},History.prototype.length=function(){return this._snapshots.length},History.prototype.snapshot=function(){return this._snapshots[this._snapshotIndex]},History.prototype.goTo=function(index){return this._snapshotIndex=Math.min(this._snapshots.length-1,Math.max(0,index)),this.snapshot()},History.prototype.redo=function(){return this.goTo(this._snapshotIndex+1)},History.prototype.replaceRegions=function(regions){var k,v,_results;this._regions={},_results=[];for(k in regions)v=regions[k],_results.push(this._regions[k]=v);return _results},History.prototype.restoreSelection=function(snapshot){var element,region;if(snapshot.selected)return region=this._regions[snapshot.selected.region],element=region.descendants()[snapshot.selected.element],element.focus(),element.selection&&snapshot.selected.selection?element.selection(snapshot.selected.selection):void 0},History.prototype.stopWatching=function(){return this._watchInterval&&clearInterval(this._watchInterval),this._delayedStoreTimeout?clearTimeout(this._delayedStoreTimeout):void 0},History.prototype.undo=function(){return this.goTo(this._snapshotIndex-1)},History.prototype.watch=function(){var watch;return this._lastSnapshotTaken=Date.now(),watch=function(_this){return function(){var delayedStore,lastModified;if(lastModified=ContentEdit.Root.get().lastModified(),null!==lastModified&&lastModified>_this._lastSnapshotTaken){if(_this._delayedStoreRequested===lastModified)return;return _this._delayedStoreTimeout&&clearTimeout(_this._delayedStoreTimeout),delayedStore=function(){return _this._lastSnapshotTaken=lastModified,_this._store()},_this._delayedStoreRequested=lastModified,_this._delayedStoreTimeout=setTimeout(delayedStore,500)}}}(this),this._watchInterval=setInterval(watch,50)},History.prototype._store=function(){var element,name,other_region,region,snapshot,_ref,_ref1;snapshot={regions:{},selected:null},_ref=this._regions;for(name in _ref)region=_ref[name],snapshot.regions[name]=region.html();if(element=ContentEdit.Root.get().focused()){if(snapshot.selected={},region=element.closest(function(node){return"Region"===node.constructor.name}),!region)return;_ref1=this._regions;for(name in _ref1)if(other_region=_ref1[name],region===other_region){snapshot.selected.region=name;break}snapshot.selected.element=region.descendants().indexOf(element),element.selection&&(snapshot.selected.selection=element.selection())}return this._snapshotIndex<this._snapshots.length-1&&(this._snapshots=this._snapshots.slice(0,this._snapshotIndex+1)),this._snapshotIndex++,this._snapshots.splice(this._snapshotIndex,0,snapshot)},History}(),ContentTools.StylePalette=function(){function StylePalette(){}return StylePalette._styles=[],StylePalette.add=function(styles){return this._styles=this._styles.concat(styles)},StylePalette.styles=function(tagName){return void 0===tagName?this._styles.slice():this._styles.filter(function(style){return style._applicableTo?-1!==style._applicableTo.indexOf(tagName):!0})},StylePalette}(),ContentTools.Style=function(){function Style(name,cssClass,applicableTo){this._name=name,this._cssClass=cssClass,this._applicableTo=applicableTo?applicableTo:null}return Style.prototype.applicableTo=function(){return this._applicableTo},Style.prototype.cssClass=function(){return this._cssClass},Style.prototype.name=function(){return this._name},Style}(),ContentTools.ToolShelf=function(){function ToolShelf(){}return ToolShelf._tools={},ToolShelf.stow=function(cls,name){return this._tools[name]=cls},ToolShelf.fetch=function(name){if(!this._tools[name])throw new Error("`"+name+"` has not been stowed on the tool shelf");return this._tools[name]},ToolShelf}(),ContentTools.Tool=function(){function Tool(){}return Tool.label="Tool",Tool.icon="tool",Tool.canApply=function(){return!1},Tool.isApplied=function(){return!1},Tool.apply=function(){throw new Error("Not implemented")},Tool._insertAt=function(element){var insertIndex,insertNode;return insertNode=element,"Region"!==insertNode.parent().constructor.name&&(insertNode=element.closest(function(node){return"Region"===node.parent().constructor.name})),insertIndex=insertNode.parent().children.indexOf(insertNode)+1,[insertNode,insertIndex]},Tool}(),ContentTools.Tools.Bold=function(_super){function Bold(){return Bold.__super__.constructor.apply(this,arguments)}return __extends(Bold,_super),ContentTools.ToolShelf.stow(Bold,"bold"),Bold.label="Bold",Bold.icon="bold",Bold.tagName="b",Bold.canApply=function(element,selection){return element.content?selection&&!selection.isCollapsed():!1},Bold.isApplied=function(element,selection){var from,to,_ref;return void 0!==element.content&&element.content.length()?(_ref=selection.get(),from=_ref[0],to=_ref[1],from===to&&(to+=1),element.content.slice(from,to).hasTags(this.tagName,!0)):!1},Bold.apply=function(element,selection,callback){var from,to,_ref;return element.storeState(),_ref=selection.get(),from=_ref[0],to=_ref[1],element.content=this.isApplied(element,selection)?element.content.unformat(from,to,new HTMLString.Tag(this.tagName)):element.content.format(from,to,new HTMLString.Tag(this.tagName)),element.updateInnerHTML(),element.taint(),element.restoreState(),callback(!0)},Bold}(ContentTools.Tool),ContentTools.Tools.Italic=function(_super){function Italic(){return Italic.__super__.constructor.apply(this,arguments)}return __extends(Italic,_super),ContentTools.ToolShelf.stow(Italic,"italic"),Italic.label="Italic",Italic.icon="italic",Italic.tagName="i",Italic}(ContentTools.Tools.Bold),ContentTools.Tools.Link=function(_super){function Link(){return Link.__super__.constructor.apply(this,arguments)}return __extends(Link,_super),ContentTools.ToolShelf.stow(Link,"link"),Link.label="Link",Link.icon="link",Link.tagName="a",Link.getHref=function(element,selection){var c,from,selectedContent,tag,to,_i,_j,_len,_len1,_ref,_ref1,_ref2;if("Image"===element.constructor.name){if(element.a)return element.a.href}else for(_ref=selection.get(),from=_ref[0],to=_ref[1],selectedContent=element.content.slice(from,to),_ref1=selectedContent.characters,_i=0,_len=_ref1.length;_len>_i;_i++)if(c=_ref1[_i],c.hasTags("a"))for(_ref2=c.tags(),_j=0,_len1=_ref2.length;_len1>_j;_j++)if(tag=_ref2[_j],"a"===tag.name())return tag.attr("href");return""},Link.canApply=function(element,selection){return"Image"===element.constructor.name?!0:Link.__super__.constructor.canApply.call(this,element,selection)},Link.isApplied=function(element,selection){return"Image"===element.constructor.name?element.a:Link.__super__.constructor.isApplied.call(this,element,selection)},Link.apply=function(element,selection,callback){var allowScrolling,app,applied,dialog,domElement,from,measureSpan,modal,rect,selectTag,to,transparent,_ref;return applied=!1,"Image"===element.constructor.name?rect=element.domElement().getBoundingClientRect():(element.storeState(),selectTag=new HTMLString.Tag("span",{"class":"ct--puesdo-select"}),_ref=selection.get(),from=_ref[0],to=_ref[1],element.content=element.content.format(from,to,selectTag),element.updateInnerHTML(),domElement=element.domElement(),measureSpan=domElement.getElementsByClassName("ct--puesdo-select"),rect=measureSpan[0].getBoundingClientRect()),app=ContentTools.EditorApp.get(),modal=new ContentTools.ModalUI(transparent=!0,allowScrolling=!0),modal.bind("click",function(){return this.unmount(),dialog.hide(),element.content&&(element.content=element.content.unformat(from,to,selectTag),element.updateInnerHTML(),element.restoreState()),callback(applied)}),dialog=new ContentTools.LinkDialog(this.getHref(element,selection)),dialog.position([rect.left+rect.width/2+window.scrollX,rect.top+rect.height/2+window.scrollY]),dialog.bind("save",function(href){var a;return dialog.unbind("save"),applied=!0,"Image"===element.constructor.name?element.a=href?{href:href}:null:(element.content=element.content.unformat(from,to,"a"),href&&(a=new HTMLString.Tag("a",{href:href}),element.content=element.content.format(from,to,a)),element.updateInnerHTML(),element.taint()),modal.trigger("click")}),app.attach(modal),app.attach(dialog),modal.show(),dialog.show()},Link}(ContentTools.Tools.Bold),ContentTools.Tools.Heading=function(_super){function Heading(){return Heading.__super__.constructor.apply(this,arguments)}return __extends(Heading,_super),ContentTools.ToolShelf.stow(Heading,"heading"),Heading.label="Heading",Heading.icon="heading",Heading.tagName="h1",Heading.canApply=function(element){return void 0!==element.content&&"Region"===element.parent().constructor.name},Heading.apply=function(element,selection,callback){var content,insertAt,parent,textElement;return element.storeState(),"PreText"===element.constructor.name?(content=element.content.html().replace(/&nbsp;/g," "),textElement=new ContentEdit.Text(this.tagName,{},content),parent=element.parent(),insertAt=parent.children.indexOf(element),parent.detach(element),parent.attach(textElement,insertAt),element.blur(),textElement.focus(),textElement.selection(selection)):(element.tagName(this.tagName),element.restoreState()),callback(!0)},Heading}(ContentTools.Tool),ContentTools.Tools.Subheading=function(_super){function Subheading(){return Subheading.__super__.constructor.apply(this,arguments)}return __extends(Subheading,_super),ContentTools.ToolShelf.stow(Subheading,"subheading"),Subheading.label="Subheading",Subheading.icon="subheading",Subheading.tagName="h2",Subheading}(ContentTools.Tools.Heading),ContentTools.Tools.Paragraph=function(_super){function Paragraph(){return Paragraph.__super__.constructor.apply(this,arguments)}return __extends(Paragraph,_super),ContentTools.ToolShelf.stow(Paragraph,"paragraph"),Paragraph.label="Paragraph",Paragraph.icon="paragraph",Paragraph.tagName="p",Paragraph.canApply=function(element){return void 0!==element},Paragraph.apply=function(element,selection,callback){var app,forceAdd,paragraph,region;return app=ContentTools.EditorApp.get(),forceAdd=app.ctrlDown(),ContentTools.Tools.Heading.canApply(element)&&!forceAdd?Paragraph.__super__.constructor.apply.call(this,element,selection,callback):("Region"!==element.parent().constructor.name&&(element=element.closest(function(node){return"Region"===node.parent().constructor.name})),region=element.parent(),paragraph=new ContentEdit.Text("p"),region.attach(paragraph,region.children.indexOf(element)+1),paragraph.focus(),callback(!0))},Paragraph}(ContentTools.Tools.Heading),ContentTools.Tools.Preformatted=function(_super){function Preformatted(){return Preformatted.__super__.constructor.apply(this,arguments)}return __extends(Preformatted,_super),ContentTools.ToolShelf.stow(Preformatted,"preformatted"),Preformatted.label="Preformatted",Preformatted.icon="preformatted",Preformatted.tagName="pre",Preformatted.apply=function(element,selection,callback){var insertAt,parent,preText,text;return text=element.content.text(),preText=new ContentEdit.PreText("pre",{},HTMLString.String.encode(text)),parent=element.parent(),insertAt=parent.children.indexOf(element),parent.detach(element),parent.attach(preText,insertAt),element.blur(),preText.focus(),preText.selection(selection),callback(!0)},Preformatted}(ContentTools.Tools.Heading),ContentTools.Tools.AlignLeft=function(_super){function AlignLeft(){return AlignLeft.__super__.constructor.apply(this,arguments)}return __extends(AlignLeft,_super),ContentTools.ToolShelf.stow(AlignLeft,"align-left"),AlignLeft.label="Align left",AlignLeft.icon="align-left",AlignLeft.className="text-left",AlignLeft.canApply=function(element){return void 0!==element.content},AlignLeft.isApplied=function(element){var _ref;return this.canApply(element)?(("ListItemText"===(_ref=element.constructor.name)||"TableCellText"===_ref)&&(element=element.parent()),element.hasCSSClass(this.className)):!1},AlignLeft.apply=function(element,selection,callback){var className,_i,_len,_ref,_ref1;for(("ListItemText"===(_ref=element.constructor.name)||"TableCellText"===_ref)&&(element=element.parent()),_ref1=["text-center","text-left","text-right"],_i=0,_len=_ref1.length;_len>_i;_i++)if(className=_ref1[_i],element.hasCSSClass(className)&&(element.removeCSSClass(className),className===this.className))return callback(!0);return element.addCSSClass(this.className),callback(!0)},AlignLeft}(ContentTools.Tool),ContentTools.Tools.AlignCenter=function(_super){function AlignCenter(){return AlignCenter.__super__.constructor.apply(this,arguments)}return __extends(AlignCenter,_super),ContentTools.ToolShelf.stow(AlignCenter,"align-center"),AlignCenter.label="Align center",AlignCenter.icon="align-center",AlignCenter.className="text-center",AlignCenter}(ContentTools.Tools.AlignLeft),ContentTools.Tools.AlignRight=function(_super){function AlignRight(){return AlignRight.__super__.constructor.apply(this,arguments)}return __extends(AlignRight,_super),ContentTools.ToolShelf.stow(AlignRight,"align-right"),AlignRight.label="Align right",AlignRight.icon="align-right",AlignRight.className="text-right",AlignRight}(ContentTools.Tools.AlignLeft),ContentTools.Tools.UnorderedList=function(_super){function UnorderedList(){return UnorderedList.__super__.constructor.apply(this,arguments)}return __extends(UnorderedList,_super),ContentTools.ToolShelf.stow(UnorderedList,"unordered-list"),UnorderedList.label="Bullet list",UnorderedList.icon="unordered-list",UnorderedList.listTag="ul",UnorderedList.canApply=function(element){var _ref;return void 0!==element.content&&("Region"===(_ref=element.parent().constructor.name)||"ListItem"===_ref)},UnorderedList.apply=function(element,selection,callback){var insertAt,list,listItem,listItemText,parent;return"ListItem"===element.parent().constructor.name?(element.storeState(),list=element.closest(function(node){return"List"===node.constructor.name}),list.tagName(this.listTag),element.restoreState()):(listItemText=new ContentEdit.ListItemText(element.content.copy()),listItem=new ContentEdit.ListItem,listItem.attach(listItemText),list=new ContentEdit.List(this.listTag,{}),list.attach(listItem),parent=element.parent(),insertAt=parent.children.indexOf(element),parent.detach(element),parent.attach(list,insertAt),listItemText.focus(),listItemText.selection(selection)),callback(!0)},UnorderedList}(ContentTools.Tool),ContentTools.Tools.OrderedList=function(_super){function OrderedList(){return OrderedList.__super__.constructor.apply(this,arguments)}return __extends(OrderedList,_super),ContentTools.ToolShelf.stow(OrderedList,"ordered-list"),OrderedList.label="Numbers list",OrderedList.icon="ordered-list",OrderedList.listTag="ol",OrderedList}(ContentTools.Tools.UnorderedList),ContentTools.Tools.Table=function(_super){function Table(){return Table.__super__.constructor.apply(this,arguments)}return __extends(Table,_super),ContentTools.ToolShelf.stow(Table,"table"),Table.label="Table",Table.icon="table",Table.canApply=function(element){return void 0!==element},Table.apply=function(element,selection,callback){var app,dialog,modal,table;return element.storeState&&element.storeState(),app=ContentTools.EditorApp.get(),modal=new ContentTools.ModalUI,table=element.closest(function(node){return node&&"Table"===node.constructor.name}),dialog=new ContentTools.TableDialog(table),dialog.bind("cancel",function(){return function(){return dialog.unbind("cancel"),modal.hide(),dialog.hide(),element.restoreState&&element.restoreState(),callback(!1)}}(this)),dialog.bind("save",function(_this){return function(tableCfg){var index,keepFocus,node,_ref;return dialog.unbind("save"),keepFocus=!0,table?(_this._updateTable(tableCfg,table),keepFocus=element.closest(function(node){return node&&"Table"===node.constructor.name})):(table=_this._createTable(tableCfg),_ref=_this._insertAt(element),node=_ref[0],index=_ref[1],node.parent().attach(table,index),keepFocus=!1),keepFocus?element.restoreState():table.firstSection().children[0].children[0].children[0].focus(),modal.hide(),dialog.hide(),callback(!0)}}(this)),app.attach(modal),app.attach(dialog),modal.show(),dialog.show()},Table._adjustColumns=function(section,columns){var cell,cellTag,cellText,currentColumns,diff,i,row,_i,_len,_ref,_results;for(_ref=section.children,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)row=_ref[_i],cellTag=row.children[0].tagName(),currentColumns=row.children.length,diff=columns-currentColumns,_results.push(0>diff?function(){var _j,_results1;for(_results1=[],i=_j=diff;0>=diff?0>_j:_j>0;i=0>=diff?++_j:--_j)cell=row.children[row.children.length-1],_results1.push(row.detach(cell));return _results1
  }():diff>0?function(){var _j,_results1;for(_results1=[],i=_j=0;diff>=0?diff>_j:_j>diff;i=diff>=0?++_j:--_j)cell=new ContentEdit.TableCell(cellTag),row.attach(cell),cellText=new ContentEdit.TableCellText(""),_results1.push(cell.attach(cellText));return _results1}():void 0);return _results},Table._createTable=function(tableCfg){var body,foot,head,table;return table=new ContentEdit.Table,tableCfg.head&&(head=this._createTableSection("thead","th",tableCfg.columns),table.attach(head)),body=this._createTableSection("tbody","td",tableCfg.columns),table.attach(body),tableCfg.foot&&(foot=this._createTableSection("tfoot","td",tableCfg.columns),table.attach(foot)),table},Table._createTableSection=function(sectionTag,cellTag,columns){var cell,cellText,i,row,section,_i;for(section=new ContentEdit.TableSection(sectionTag),row=new ContentEdit.TableRow,section.attach(row),i=_i=0;columns>=0?columns>_i:_i>columns;i=columns>=0?++_i:--_i)cell=new ContentEdit.TableCell(cellTag),row.attach(cell),cellText=new ContentEdit.TableCellText(""),cell.attach(cellText);return section},Table._updateTable=function(tableCfg,table){var columns,foot,head,section,_i,_len,_ref;if(!tableCfg.head&&table.thead()&&table.detach(table.thead()),!tableCfg.foot&&table.tfoot()&&table.detach(table.tfoot()),columns=table.firstSection().children[0].children.length,tableCfg.columns!==columns)for(_ref=table.children,_i=0,_len=_ref.length;_len>_i;_i++)section=_ref[_i],this._adjustColumns(section,tableCfg.columns);return tableCfg.head&&!table.thead()&&(head=this._createTableSection("thead","th",tableCfg.columns),table.attach(head)),tableCfg.foot&&!table.tfoot()?(foot=this._createTableSection("tfoot","td",tableCfg.columns),table.attach(foot)):void 0},Table}(ContentTools.Tool),ContentTools.Tools.Indent=function(_super){function Indent(){return Indent.__super__.constructor.apply(this,arguments)}return __extends(Indent,_super),ContentTools.ToolShelf.stow(Indent,"indent"),Indent.label="Indent",Indent.icon="indent",Indent.canApply=function(element){return"ListItem"===element.parent().constructor.name&&element.parent().parent().children.indexOf(element.parent())>0},Indent.apply=function(element,selection,callback){return element.parent().indent(),callback(!0)},Indent}(ContentTools.Tool),ContentTools.Tools.Unindent=function(_super){function Unindent(){return Unindent.__super__.constructor.apply(this,arguments)}return __extends(Unindent,_super),ContentTools.ToolShelf.stow(Unindent,"unindent"),Unindent.label="Unindent",Unindent.icon="unindent",Unindent.canApply=function(element){return"ListItem"===element.parent().constructor.name},Unindent.apply=function(element,selection,callback){return element.parent().unindent(),callback(!0)},Unindent}(ContentTools.Tool),ContentTools.Tools.LineBreak=function(_super){function LineBreak(){return LineBreak.__super__.constructor.apply(this,arguments)}return __extends(LineBreak,_super),ContentTools.ToolShelf.stow(LineBreak,"line-break"),LineBreak.label="Line break",LineBreak.icon="line-break",LineBreak.canApply=function(element){return element.content},LineBreak.apply=function(element,selection,callback){var br,cursor,tail,tip;return cursor=selection.get()[0]+1,tip=element.content.substring(0,selection.get()[0]),tail=element.content.substring(selection.get()[1]),br=new HTMLString.String("<br>",element.content.preserveWhitespace()),element.content=tip.concat(br,tail),element.updateInnerHTML(),element.taint(),selection.set(cursor,cursor),element.selection(selection),callback(!0)},LineBreak}(ContentTools.Tool),ContentTools.Tools.Image=function(_super){function Image(){return Image.__super__.constructor.apply(this,arguments)}return __extends(Image,_super),ContentTools.ToolShelf.stow(Image,"image"),Image.label="Image",Image.icon="image",Image.canApply=function(){return!0},Image.apply=function(element,selection,callback){var app,dialog,modal;return element.storeState&&element.storeState(),app=ContentTools.EditorApp.get(),modal=new ContentTools.ModalUI,dialog=new ContentTools.ImageDialog,dialog.bind("cancel",function(){return function(){return dialog.unbind("cancel"),modal.hide(),dialog.hide(),element.restoreState&&element.restoreState(),callback(!1)}}(this)),dialog.bind("save",function(_this){return function(imageURL,imageSize,imageAttrs){var image,index,node,_ref;return dialog.unbind("save"),imageAttrs||(imageAttrs={}),imageAttrs.height=imageSize[1],imageAttrs.src=imageURL,imageAttrs.width=imageSize[0],image=new ContentEdit.Image(imageAttrs),_ref=_this._insertAt(element),node=_ref[0],index=_ref[1],node.parent().attach(image,index),image.focus(),modal.hide(),dialog.hide(),callback(!0)}}(this)),app.attach(modal),app.attach(dialog),modal.show(),dialog.show()},Image}(ContentTools.Tool),ContentTools.Tools.Video=function(_super){function Video(){return Video.__super__.constructor.apply(this,arguments)}return __extends(Video,_super),ContentTools.ToolShelf.stow(Video,"video"),Video.label="Video",Video.icon="video",Video.canApply=function(){return!0},Video.apply=function(element,selection,callback){var app,dialog,modal;return element.storeState&&element.storeState(),app=ContentTools.EditorApp.get(),modal=new ContentTools.ModalUI,dialog=new ContentTools.VideoDialog,dialog.bind("cancel",function(){return function(){return dialog.unbind("cancel"),modal.hide(),dialog.hide(),element.restoreState&&element.restoreState(),callback(!1)}}(this)),dialog.bind("save",function(_this){return function(videoURL){var index,node,video,_ref;return dialog.unbind("save"),videoURL?(video=new ContentEdit.Video("iframe",{frameborder:0,height:ContentTools.DEFAULT_VIDEO_HEIGHT,src:videoURL,width:ContentTools.DEFAULT_VIDEO_WIDTH}),_ref=_this._insertAt(element),node=_ref[0],index=_ref[1],node.parent().attach(video,index),video.focus()):element.restoreState&&element.restoreState(),modal.hide(),dialog.hide(),callback(""!==videoURL)}}(this)),app.attach(modal),app.attach(dialog),modal.show(),dialog.show()},Video}(ContentTools.Tool),ContentTools.Tools.Undo=function(_super){function Undo(){return Undo.__super__.constructor.apply(this,arguments)}return __extends(Undo,_super),ContentTools.ToolShelf.stow(Undo,"undo"),Undo.label="Undo",Undo.icon="undo",Undo.canApply=function(){var app;return app=ContentTools.EditorApp.get(),app.history&&app.history.canUndo()},Undo.apply=function(){var app,snapshot;return app=ContentTools.EditorApp.get(),app.history.stopWatching(),snapshot=app.history.undo(),app.revertToSnapshot(snapshot),app.history.watch()},Undo}(ContentTools.Tool),ContentTools.Tools.Redo=function(_super){function Redo(){return Redo.__super__.constructor.apply(this,arguments)}return __extends(Redo,_super),ContentTools.ToolShelf.stow(Redo,"redo"),Redo.label="Redo",Redo.icon="redo",Redo.canApply=function(){var app;return app=ContentTools.EditorApp.get(),app.history&&app.history.canRedo()},Redo.apply=function(){var app,snapshot;return app=ContentTools.EditorApp.get(),app.history.stopWatching(),snapshot=app.history.redo(),app.revertToSnapshot(snapshot),app.history.watch()},Redo}(ContentTools.Tool),ContentTools.Tools.Remove=function(_super){function Remove(){return Remove.__super__.constructor.apply(this,arguments)}return __extends(Remove,_super),ContentTools.ToolShelf.stow(Remove,"remove"),Remove.label="Remove",Remove.icon="remove",Remove.canApply=function(){return!0},Remove.apply=function(element,selection,callback){var app,list,row,table;switch(app=ContentTools.EditorApp.get(),element.blur(),element.nextContent()?element.nextContent().focus():element.previousContent()&&element.previousContent().focus(),element.constructor.name){case"ListItemText":app.ctrlDown()?(list=element.closest(function(node){return"Region"===node.parent().constructor.name}),list.parent().detach(list)):element.parent().parent().detach(element.parent());break;case"TableCellText":app.ctrlDown()?(table=element.closest(function(node){return"Table"===node.constructor.name}),table.parent().detach(table)):(row=element.parent().parent(),row.parent().detach(row));break;default:element.parent().detach(element)}return callback(!0)},Remove}(ContentTools.Tool)}.call(this);