",{"class":this.pfx+"color-picker"}),cpStyle=this.$colorPicker.get(0).style;var a=this,b=this.target.config?this.target.config.el:"";this.$colorPicker.spectrum({appendTo:b||"body",showPalette:!0,maxSelectionSize:8,palette:[],showAlpha:!0,chooseText:"Ok",cancelText:"⨯",move:function(a){var b=1==a.getAlpha()?a.toHexString():a.toRgbString();cpStyle.backgroundColor=b},change:function(b){var c=1==b.getAlpha()?b.toHexString():b.toRgbString();c=c.replace(/ /g,""),cpStyle.backgroundColor=c,a.model.set("value",c)}}),this.$el.find("."+this.pfx+"colorp-c").append(this.$colorPicker)}this.setValue(this.componentValue,0)},setValue:function(a,c){b.prototype.setValue.apply(this,arguments);var d=this.model.get("value")||this.defaultValue;d=a||d,this.$colorPicker&&(d="none"===d?"#fff":d,this.$colorPicker.spectrum("set",d),this.$colorPicker.get(0).style.backgroundColor=d)}})}),c("text!StyleManager/templates/propertyFile.html",[],function(){return'
\n
input-holder\'>\n
\n <%= assets %> \n
\n
\n
\n
\n
\n
'}),c("StyleManager/view/PropertyFileView",["backbone","./PropertyView","text!./../templates/propertyFile.html"],function(a,b,c){return b.extend({template:_.template(c),initialize:function(a){b.prototype.initialize.apply(this,arguments),this.assets=this.target.get("assets"),this.modal=this.target.get("Modal"),this.am=this.target.get("AssetManager"),this.className=this.className+" "+this.pfx+"file",this.events["click #"+this.pfx+"close"]="removeFile",this.events["click #"+this.pfx+"images"]="openAssetManager",this.delegateEvents()},renderInput:function(){this.$input||(this.$input=$("
",{placeholder:this.defaultValue,type:"text"})),this.$preview||(this.$preview=this.$el.find("#"+this.pfx+"preview-file")),this.$previewBox||(this.$previewBox=this.$el.find("#"+this.pfx+"preview-box")),this.componentValue&&this.componentValue!=this.defaultValue?this.setPreviewView(1):this.setPreviewView(0),this.setValue(this.componentValue,0)},setPreviewView:function(a){this.$previewBox&&(a?this.$previewBox.addClass(this.pfx+"show"):this.$previewBox.removeClass(this.pfx+"show"))},spreadUrl:function(a){this.setValue('url("'+a+'")'),this.setPreviewView(1)},setPreview:function(a){this.$preview&&this.$preview.css("background-image",a)},setValue:function(a,c){b.prototype.setValue.apply(this,arguments),this.setPreview(a)},renderTemplate:function(){this.$el.append(this.template({upload:"Upload",assets:"Images",pfx:this.pfx}))},cleanValue:function(){this.setPreviewView(0),this.model.set({value:""},{silent:!0})},removeFile:function(){this.model.set("value",this.defaultValue),b.prototype.cleanValue.apply(this,arguments),this.setPreviewView(0)},openAssetManager:function(a){var b=this;this.modal&&this.am&&(this.modal.setTitle("Select image"),this.modal.setContent(this.am.render()),this.am.setTarget(null),this.modal.open(),this.am.onSelect(function(c){b.modal.close(),b.spreadUrl(c.get("src")),b.valueChanged(a)}))}})}),c("text!StyleManager/templates/propertyComposite.html",[],function(){return'
\n input-holder\'> \n
\n
'}),c("StyleManager/view/PropertyCompositeView",["backbone","./PropertyView","text!./../templates/propertyComposite.html","require"],function(a,b,c,d){return b.extend({template:_.template(c),initialize:function(a){b.prototype.initialize.apply(this,arguments),_.bindAll(this,"build"),this.config=a.config||{},this.className=this.className+" "+this.pfx+"composite"},valueUpdated:function(){this.model.get("detached")||b.prototype.valueUpdated.apply(this,arguments)},renderInput:function(){var a=this.model.get("properties");this.model.get("detached");if(a&&a.length){if(this.$input||(this.$input=$("
",{value:0,type:"hidden"})),!this.props){var b=d("./../model/Properties");this.props=new b(a),this.model.set("properties",this.props)}if(!this.$props){this.props.each(function(a,b){a&&"composite"==a.get("type")&&(this.props.remove(a),console.warn("Nested composite types not yet allowed."))},this);var c=d("./PropertiesView"),e=new c(this.getPropsConfig());this.$props=e.render().$el,this.$el.find("#"+this.pfx+"input-holder").html(this.$props)}}},getPropsConfig:function(a){var b=this;return result={config:this.config,collection:this.props,target:this.target,propTarget:this.propTarget,onChange:function(a,c,d){var e=b.build();b.model.set("value",e,d)},customValue:function(a,c){return b.valueOnIndex(c,a)}},this.model.get("detached")&&delete result.onChange,result},getDefaultValue:function(){var a="";return this.props.each(function(b,c){a+=b.get("defaults")+b.get("unit")+" "}),a.replace(/ +$/,"")},valueOnIndex:function(a,b){var c=null,d=this.getComponentValue().split(" ");if(d.length&&d[a]&&(c=d[a],b&&b.model&&b.model.get("functionName"))){var e=this.fetchFromFunction(c);e&&(c=e)}return c},build:function(a,b,c){var d="";return this.model.get("properties").each(function(a){var b=a.getValue();func=a.get("functionName"),func&&(b=func+"("+b+")"),d+=b+" "}),d.replace(/ +$/,"")}})}),c("text!StyleManager/templates/propertyStack.html",[],function(){return"
field <%= pfx %>stack\">\n + \n \n
\n
"}),c("text!StyleManager/templates/layer.html",[],function(){return'
\n \n
\n
<%= label %>
\n
\n
⨯
\n
\n
'}),c("StyleManager/view/LayerView",["backbone","text!./../templates/layer.html"],function(a,b){return a.View.extend({events:{click:"updateIndex"},template:_.template(b),initialize:function(a){this.stackModel=a.stackModel||{},this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.className=this.pfx+"layer",this.sorter=a.sorter||null,this.listenTo(this.model,"destroy remove",this.remove),this.listenTo(this.model,"change:value",this.valueChanged),this.listenTo(this.model,"change:props",this.showProps),this.events["click #"+this.pfx+"close-layer"]="remove",this.events["mousedown > #"+this.pfx+"move"]="initSorter",this.model.get("preview")||this.$el.addClass(this.pfx+"no-preview"),this.$el.data("model",this.model),this.delegateEvents()},initSorter:function(a){this.sorter&&this.sorter.startSort(this.el)},getProps:function(){return this.stackModel.get?this.stackModel.get("properties"):null},valueChanged:function(){var a=this.model.get("preview");if(a){this.$preview||(this.$preview=this.$el.find("#"+this.pfx+"preview"));"function"==typeof a?a(this.getProps(),this.$preview):this.onPreview(this.getProps(),this.$preview)}},onPreview:function(a,b){var c=this.model.get("value").split(" "),d=3,e="";if(a.each(function(a,b){var f=c[b]||"";if(f&&"integer"==a.get("type")){var g=parseInt(f,10),h=f.replace(g,"");g=isNaN(g)?0:g,g>d&&(g=d),-d>g&&(g=-d),f=g+h}e+=f+" "}),this.stackModel.get){var f=this.stackModel.get("property");f&&(this.$preview.get(0).style[f]=e)}},showProps:function(){this.$props=this.model.get("props"),this.$el.find("#"+this.pfx+"inputs").html(this.$props.show()),this.model.set({props:null},{silent:!0})},remove:function(b){this.$props&&this.$props.detach(),b&&b.stopPropagation&&b.stopPropagation(),a.View.prototype.remove.apply(this,arguments),this.model.collection.contains(this.model)&&this.model.collection.remove(this.model),this.stackModel&&this.stackModel.set&&(this.stackModel.set({stackIndex:null},{silent:!0}),this.stackModel.trigger("updateValue"))},updateIndex:function(a){var b=this.getIndex();this.stackModel.set("stackIndex",b),this.model.collection&&this.model.collection.trigger("deselectAll"),this.$el.addClass(this.pfx+"active")},getIndex:function(){var a=0;return this.model.collection&&(a=this.model.collection.indexOf(this.model)),a},render:function(){return this.$el.html(this.template({label:"Layer "+this.model.get("index"),pfx:this.pfx})),this.$el.attr("class",this.className),this.valueChanged(),this}})}),c("StyleManager/view/LayersView",["backbone","./LayerView"],function(a,b){return a.View.extend({initialize:function(a){this.config=a.config||{},this.stackModel=a.stackModel,this.preview=a.preview,this.pfx=this.config.stylePrefix||"",this.className=this.pfx+"layers",this.listenTo(this.collection,"add",this.addTo),this.listenTo(this.collection,"deselectAll",this.deselectAll),this.listenTo(this.collection,"reset",this.render);var b=this.config.em||"",c=b?b.get("Utils"):"";this.sorter=c?new c.Sorter({container:this.el,containerSel:"."+this.pfx+"layers",itemSel:"."+this.pfx+"layer",pfx:this.config.pStylePrefix}):"",this.$el.data("collection",this.collection)},addTo:function(a){var b=this.collection.indexOf(a);this.addToCollection(a,null,b)},addToCollection:function(a,c,d){var e=c||null,f=b;"undefined"!=typeof this.preview&&a.set("preview",this.preview);var g=new f({model:a,stackModel:this.stackModel,config:this.config,sorter:this.sorter}),h=g.render().el;if(e)e.appendChild(h);else if("undefined"!=typeof d){var i="before";this.$el.children().length==d&&(d--,i="after"),0>d?this.$el.append(h):this.$el.children().eq(d)[i](h)}else this.$el.append(h);return h},deselectAll:function(){this.$el.find("."+this.pfx+"layer").removeClass(this.pfx+"active")},render:function(){var a=document.createDocumentFragment();return this.$el.empty(),this.collection.each(function(b){this.addToCollection(b,a)},this),this.$el.append(a),this.$el.attr("class",this.className),this.sorter&&(this.sorter.plh=null),this}})}),c("StyleManager/view/PropertyStackView",["backbone","./PropertyCompositeView","text!./../templates/propertyStack.html","./../model/Layers","./LayersView"],function(a,b,c,d,e){return b.extend({template:_.template(c),initialize:function(a){b.prototype.initialize.apply(this,arguments),this.model.set("stackIndex",null),this.className=this.pfx+"property "+this.pfx+"stack",this.events["click #"+this.pfx+"add"]="addLayer",this.listenTo(this.model,"change:stackIndex",this.indexChanged),this.listenTo(this.model,"updateValue",this.valueUpdated),this.delegateEvents()},targetUpdated:function(){this.model.get("detached")?this.refreshLayers():b.prototype.targetUpdated.apply(this,arguments)},getLayers:function(){return this.model.get("layers")},indexChanged:function(a){var b=this.getLayers().at(this.model.get("stackIndex"));b.set("props",this.$props),this.model.get("properties").each(function(a){a.trigger("targetUpdated")})},getStackValues:function(){return this.getLayers().pluck("value")},getPropsConfig:function(a){var c=this,d=b.prototype.getPropsConfig.apply(this,arguments);return d.onChange=function(a,b,d){var e=b.model,f=c.build();if(c.model.get("detached")){var g="";e.collection.indexOf(e);c.getLayers().each(function(a){var b=a.get("values")[e.get("property")];b&&(g+=(g?",":"")+b)}),b.updateTargetStyle(g,null,d)}else c.model.set("value",f,d)},d},valueOnIndex:function(a,b){var c=null;if(this.model.get("detached")){var d=b.componentValue.split(",");c=d[this.model.get("stackIndex")],c=c?c.trim():c}else{var e=this.getStackValues(),f=e[this.model.get("stackIndex")];if(!f)return;var g=f.split(" ");g.length&&g[a]&&(c=g[a])}return c},build:function(){var a=this.model.get("stackIndex");if(null!==a){var c=b.prototype.build.apply(this,arguments),d=this.getLayers().at(a);if(d){var e={};return this.model.get("properties").each(function(a){var b=a.getValue(),c=a.get("functionName");c&&(b=c+"("+b+")"),e[a.get("property")]=b}),d.set("values",e),d.set("value",c),this.createValue()}}},addLayer:function(a){if(this.getTarget()){var b=this.getLayers(),c=b.add({name:"test"}),d=b.indexOf(c);return c.set("value",this.getDefaultValue()),this.valueUpdated(),this.model.set("stackIndex",d),c}},valueUpdated:function(){this.model.get("detached")?this.model.get("properties").each(function(a){a.trigger("change:value")}):this.model.set("value",this.createValue())},createValue:function(){return this.getStackValues().join(", ")},renderLayers:function(){return this.$field||(this.$field=this.$el.find("> ."+this.pfx+"field")),this.$layers||(this.$layers=new e({collection:this.getLayers(),stackModel:this.model,preview:this.model.get("preview"),config:this.config})),this.$field.append(this.$layers.render().el),this.$props.hide(),this},renderInput:function(){b.prototype.renderInput.apply(this,arguments),this.refreshLayers()},getLayersFromTarget:function(){var a=[],b=this.getTarget();if(!b)return a;var c=b.get("style");return this.model.get("properties").each(function(b){var d=c[b.get("property")];if(d)for(var e=d.split(","),f=0,g=e.length;g>f;f++){var h=e[f].trim();if(a[f])a[f][b.get("property")]=h;else{var i={};i[b.get("property")]=h,a[f]=i}}}),a},refreshLayers:function(){var a=[],b=[],c="value";if(this.model.get("detached"))c="values",b=this.getLayersFromTarget();else{var d=this.getComponentValue();d&&(d.replace(/\(([\w\s,.]*)\)/g,function(a){var b=a.replace(/,\s*/g,",");d=d.replace(a,b)}),b=d.split(", "))}_.each(b,function(b){var d={};d[c]=b,a.push(d)},this),this.$props.detach();var e=this.getLayers();e.reset(),e.add(a),this.model.get("detached")||this.valueUpdated(),this.model.set({stackIndex:null},{silent:!0})},render:function(){return this.renderLabel(),this.renderField(),this.renderLayers(),this.$el.attr("class",this.className),this}})}),c("StyleManager/view/PropertiesView",["backbone","./PropertyView","./PropertyIntegerView","./PropertyRadioView","./PropertySelectView","./PropertyColorView","./PropertyFileView","./PropertyCompositeView","./PropertyStackView"],function(a,b,c,d,e,f,g,h,i){return a.View.extend({initialize:function(a){this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.target=a.target||{},this.propTarget=a.propTarget||{},this.onChange=a.onChange||{},this.onInputRender=a.onInputRender||{},this.customValue=a.customValue||{}},render:function(){var a=document.createDocumentFragment();return this.collection.each(function(j){var k=b;switch(j.get("type")){case"integer":k=c;break;case"radio":k=d;break;case"select":k=e;break;case"color":k=f;break;case"file":k=g;break;case"composite":k=h;break;case"stack":k=i}var l=new k({model:j,name:j.get("name"),id:this.pfx+j.get("property"),target:this.target,propTarget:this.propTarget,onChange:this.onChange,onInputRender:this.onInputRender,config:this.config});"composite"!=j.get("type")&&(l.customValue=this.customValue),a.appendChild(l.render().el)},this),this.$el.append(a),this.$el.append($("
",{"class":"clear"})),this.$el.attr("class",this.pfx+"properties"),this}})}),c("text!StyleManager/templates/sector.html",[],function(){return'
\n \n <%= label %>\n
'}),c("StyleManager/view/SectorView",["backbone","./PropertiesView","text!./../templates/sector.html"],function(a,b,c){return a.View.extend({template:_.template(c),events:{},initialize:function(a){this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.target=a.target||{},this.propTarget=a.propTarget||{},this.open=this.model.get("open"),this.caretR="fa-caret-right",this.caretD="fa-caret-down",this.listenTo(this.model,"change:open",this.updateOpen),this.events["click ."+this.pfx+"title"]="toggle",this.delegateEvents()},updateOpen:function(){this.model.get("open")?this.show():this.hide()},show:function(){this.$el.addClass(this.pfx+"open"),this.$el.find("."+this.pfx+"properties").show(),this.$caret.removeClass(this.caretR).addClass(this.caretD)},hide:function(){this.$el.removeClass(this.pfx+"open"),this.$el.find("."+this.pfx+"properties").hide(),this.$caret.removeClass(this.caretD).addClass(this.caretR)},toggle:function(){var a=this.model.get("open")?0:1;this.model.set("open",a)},render:function(){return this.$el.html(this.template({pfx:this.pfx,label:this.model.get("name")})),this.$caret=this.$el.find("#"+this.pfx+"caret"),this.renderProperties(),this.$el.attr("class",this.pfx+"sector no-select"),this.updateOpen(),this},renderProperties:function(){var a=this.model.get("properties");if(a){var c=new b({collection:a,target:this.target,propTarget:this.propTarget,config:this.config});this.$el.append(c.render().el)}}})}),c("StyleManager/view/SectorsView",["backbone","./SectorView"],function(a,b){return a.View.extend({initialize:function(b){this.config=b.config||{},this.pfx=this.config.stylePrefix||"",this.target=b.target||{},this.propTarget={},_.extend(this.propTarget,a.Events),this.listenTo(this.collection,"add",this.addTo),this.listenTo(this.collection,"reset",this.render),this.listenTo(this.target,"change:selectedComponent targetClassAdded targetClassRemoved targetClassUpdated targetStateUpdated change:device",this.targetUpdated)},addTo:function(a){this.addToCollection(a)},targetUpdated:function(){var a=this.target.get("selectedComponent");if(a){var b=a.get("classes"),c=a.get("state"),d=this.propTarget,e=this.target.getDeviceModel(),f=e?e.get("width"):"";if(d.helper=null,b.length){var g=this.target.get("CssComposer"),h=_.filter(b.models,function(a){return a.get("active")}),i=g.get(h,c,f);if(i?1==b.length&&a.set("style",{}):(i=g.add(h,c,f),i.set("style",a.get("style")),a.set("style",{})),c){var j=this.target.get("SelectorManager"),k=j.add("hc-state"),l=g.get([k]);l?(g.getAll().remove(l),g.getAll().add(l)):l=g.add([k]),l.set("style",i.get("style")),d.helper=l}return d.model=i,void d.trigger("update")}d.model=a,d.trigger("update")}},addToCollection:function(a,c){var d=c||null,e=b,f=new e({model:a,id:this.pfx+a.get("name").replace(" ","_").toLowerCase(),name:a.get("name"),properties:a.get("properties"),target:this.target,propTarget:this.propTarget,config:this.config}),g=f.render().el;return d?d.appendChild(g):this.$el.append(g),
-g},render:function(){var a=document.createDocumentFragment();return this.$el.empty(),this.collection.each(function(b){this.addToCollection(b,a)},this),this.$el.attr("id",this.pfx+"sectors"),this.$el.append(a),this}})}),c("StyleManager/main",["require","./config/config","./model/Sectors","./view/SectorsView"],function(a){return function(){var b,c,d={},e=a("./config/config"),f=a("./model/Sectors"),g=a("./view/SectorsView");return{name:"StyleManager",init:function(a){d=a||{};for(var h in e)h in d||(d[h]=e[h]);var i=d.pStylePrefix;return i&&(d.stylePrefix=i+d.stylePrefix),b=new f(d.sectors),c=new g({collection:b,target:d.em,config:d}),this},addSector:function(a,c){var d=this.getSector(a);return d||(c.id=a,d=b.add(c)),d},getSector:function(a){var c=b.where({id:a});return c.length?c[0]:null},getSectors:function(){return b},addProperty:function(a,b){var c=null,d=this.getSector(a);return d&&(c=d.get("properties").add(b)),c},getProperty:function(a,b){var c=null,d=this.getSector(a);return d&&(c=d.get("properties").where({property:b}),c=1==c.length?c[0]:c),c},getProperties:function(a){var b=null,c=this.getSector(a);return c&&(b=c.get("properties")),b},render:function(){return c.render().el}}}}),c("StyleManager",["StyleManager/main"],function(a){return a}),c("AssetManager/model/Asset",["backbone"],function(a){return a.Model.extend({idAttribute:"src",defaults:{type:"",src:""},getFilename:function(){return this.get("src").split("/").pop()},getExtension:function(){return this.getFilename().split(".").pop()}})}),c("AssetManager/model/AssetImage",["backbone","./Asset"],function(a,b){return b.extend({defaults:_.extend({},b.prototype.defaults,{type:"image",unitDim:"px",height:0,width:0})})}),c("AssetManager/model/Assets",["backbone","./Asset","./AssetImage"],function(a,b,c){return a.Collection.extend({model:c,initialize:function(a,b){this.model=function(a,b){var d;switch(a.type){default:d=new c(a,b)}return d}},addImg:function(a,b){return this.add({type:"image",src:a},b),this},add:function(b,c){var d=[];b=b instanceof Array?b:[b];for(var e=0,f=b.length;f>e;e++){var g=b[e];if("string"==typeof g&&(g={src:g,type:"image"}),g&&g.src){var h=this.where({src:g.src});h.length||d.push(g)}}return 1==d.length&&(d=d[0]),a.Collection.prototype.add.apply(this,[d,c])}})}),c("AssetManager/view/AssetView",["backbone"],function(a){return a.View.extend({initialize:function(a){this.options=a,this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.ppfx=this.config.pStylePrefix||"",this.className=this.pfx+"asset",this.listenTo(this.model,"destroy remove",this.remove)}})}),c("text!AssetManager/template/assetImage.html",[],function(){return'
\n
\n
⨯
\n
'}),c("AssetManager/view/AssetImageView",["./AssetView","text!./../template/assetImage.html"],function(a,b){return a.extend({events:{click:"selected",dblclick:"chosen"},template:_.template(b),initialize:function(b){a.prototype.initialize.apply(this,arguments),this.className+=" "+this.pfx+"asset-image",this.events["click #"+this.pfx+"close"]="removeItem",this.delegateEvents()},selected:function(){this.model.collection.trigger("deselectAll"),this.$el.addClass(this.pfx+"highlight"),this.updateTarget(this.model.get("src"))},chosen:function(){this.updateTarget(this.model.get("src"));var a=this.model.collection.onSelect;a&&"function"==typeof a&&a(this.model)},updateTarget:function(a){var b=this.model.collection.target;if(b&&b.set){var c=_.clone(b.get("attributes"));b.set("attributes",c),b.set("src",a)}},removeItem:function(a){a.stopPropagation(),this.model.collection.remove(this.model)},render:function(){var a=this.model.get("name"),b=this.model.get("width")&&this.model.get("height")?this.model.get("width")+" x "+this.model.get("height"):"";return a=a?a:this.model.get("src").split("/").pop(),a=a&&a.length>30?a.substring(0,30)+"...":a,b=b?b+(this.model.get("unitDim")?this.model.get("unitDim"):" px"):"",this.$el.html(this.template({name:a,src:this.model.get("src"),dim:b,pfx:this.pfx,ppfx:this.ppfx})),this.$el.attr("class",this.className),this}})}),c("text!AssetManager/template/fileUploader.html",[],function(){return'
'}),c("AssetManager/view/FileUploader",["backbone","text!./../template/fileUploader.html"],function(a,b){return a.View.extend({template:_.template(b),events:{},initialize:function(a){this.options=a||{},this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.target=this.collection||{},this.uploadId=this.pfx+"uploadFile",this.disabled=!this.config.upload,this.events["change #"+this.uploadId]="uploadFile",this.delegateEvents()},uploadFile:function(a){for(var b=a.dataTransfer?a.dataTransfer.files:a.target.files,c=new FormData,d=0;d
\n \n
\n
\n '}),c("AssetManager/view/AssetsView",["backbone","./AssetView","./AssetImageView","./FileUploader","text!./../template/assets.html"],function(a,b,c,d,e){return a.View.extend({template:_.template(e),initialize:function(a){this.options=a,this.config=a.config,this.pfx=this.config.stylePrefix||"",this.ppfx=this.config.pStylePrefix||"",this.listenTo(this.collection,"add",this.addToAsset),this.listenTo(this.collection,"deselectAll",this.deselectAll),this.className=this.pfx+"assets",this.events={},this.events.submit="addFromStr",this.delegateEvents()},addFromStr:function(a){a.preventDefault();var b=this.getInputUrl(),c=b.value.trim();return c?(this.collection.addImg(c,{at:0}),this.getAssetsEl().scrollTop=0,b.value="",this):void 0},getAssetsEl:function(){return this.assets=this.el.querySelector("."+this.pfx+"assets"),this.assets},getInputUrl:function(){return this.inputUrl&&this.inputUrl.value||(this.inputUrl=this.el.querySelector("."+this.pfx+"add-asset input")),this.inputUrl},addToAsset:function(a){this.addAsset(a)},addAsset:function(a,d){var e=d||null,f=b;a.get("type").indexOf("image")>-1&&(f=c);var g=new f({model:a,config:this.config}),h=g.render().el;if(e)e.appendChild(h);else{var i=this.getAssetsEl();i&&i.insertBefore(h,i.firstChild)}return h},deselectAll:function(){this.$el.find("."+this.pfx+"highlight").removeClass(this.pfx+"highlight")},render:function(){var a=document.createDocumentFragment();return this.$el.empty(),this.collection.each(function(b){this.addAsset(b,a)},this),this.$el.html(this.template({pfx:this.pfx,ppfx:this.ppfx})),this.$el.find("."+this.pfx+"assets").append(a),this}})}),c("AssetManager/config/config",[],function(){return{assets:[],stylePrefix:"am-",upload:"http://localhost/assets/upload",uploadText:"Drop files here or click to upload"}}),c("AssetManager/main",["require","./model/Assets","./view/AssetsView","./view/FileUploader","./config/config"],function(a){return function(){var b,c,d,e={},f=a("./model/Assets"),g=a("./view/AssetsView"),h=a("./view/FileUploader");return{name:"AssetManager",storageKey:"assets",init:function(i){e=i||{};var j=a("./config/config");for(var k in j)k in e||(e[k]=j[k]);var l=e.pStylePrefix;l&&(e.stylePrefix=l+e.stylePrefix),b=new f(e.assets);var m={collection:b,config:e};return c=new g(m),d=new h(m),this},add:function(a){return b.add(a)},get:function(a){return b.where({src:a})[0]},getAll:function(){return b},remove:function(a){var b=this.get(a);return this.getAll().remove(b),this},store:function(a){var b={},c=JSON.stringify(this.getAll().toJSON());return b[this.storageKey]=c,!a&&e.stm&&e.stm.store(b),b},load:function(a){var b=a||"",c=this.storageKey;!b&&e.stm&&(b=e.stm.load(c));var d=[];try{d=JSON.parse(b[c])}catch(f){}return this.getAll().add(d),d},render:function(a){return(!this.rendered||a)&&(this.rendered=c.render().$el.add(d.render().$el)),this.rendered},setTarget:function(a){c.collection.target=a},onSelect:function(a){c.collection.onSelect=a}}}}),c("AssetManager",["AssetManager/main"],function(a){return a}),c("CssComposer/config/config",[],function(){return{stylePrefix:"css-",staticRules:"",rules:[]}}),c("CssComposer/model/Selectors",["backbone","require"],function(a,b){return a.Collection.extend({initialize:function(a,c){this.model=function(a,c){var d;return this.ClassTag||(this.ClassTag=b("SelectorManager/model/Selector")),d=new this.ClassTag(a,c)}}})}),c("CssComposer/model/CssRule",["backbone","./Selectors"],function(a,b){return a.Model.extend({defaults:{selectors:{},style:{},maxWidth:"",state:"",stylable:!0},initialize:function(a,c){if(this.config=a||{},this.sm=c?c.sm||{}:{},this.slct=this.config.selectors||[],this.sm.get){for(var d=[],e=0;e
=0&&(c.css=d.em.getCss()),e.indexOf("style")>=0&&(c.styles=JSON.stringify(b)),a||d.stm.store(c),c}},add:function(a,c,d){var e=c||"",g=d||"",h=this.get(a,e,g);return h?h:(h=new f({state:e,maxWidth:g}),h.get("selectors").add(a),b.add(h),h)},get:function(a,c,d){var e=null;return b.each(function(b){e||b.compare(a,c,d)&&(e=b)}),e},getAll:function(){return b},render:function(){return c.render().el}}}}),c("CssComposer",["CssComposer/main"],function(a){return a}),c("DomComponents/config/config",[],function(){return{stylePrefix:"comp-",wrapperId:"wrapper",wrapper:{removable:!1,copyable:!1,stylable:["background","background-color","background-image","background-repeat","background-attachment","background-position"],draggable:!1,badgable:!1,components:[]},components:[],rte:{},imageCompClass:"fa fa-picture-o",oAssetsOnCreate:!0,voidElements:["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"]}}),c("DomComponents/model/Components",["backbone","require"],function(a,b){return a.Collection.extend({initialize:function(a,c){this.on("add",this.onAdd),this.config=c&&c.config?c.config:null,c&&c.sm&&(this.editor=c.sm),this.model=function(a,d){var e;switch(!d.sm&&c&&c.sm&&(d.sm=c.sm),c&&c.config&&(d.config=c.config),a.type){case"text":this.mComponentText||(this.mComponentText=b("./ComponentText")),e=new this.mComponentText(a,d);break;case"image":this.mComponentImage||(this.mComponentImage=b("./ComponentImage")),e=new this.mComponentImage(a,d);break;default:this.mComponent||(this.mComponent=b("./Component")),e=new this.mComponent(a,d)}return e}},add:function(b,c){if("string"==typeof b){var d=this.editor.get("Parser").parseHtml(b);b=d.html;var e=this.editor.get("CssComposer");d.css&&e&&e.getAll().add(d.css)}return a.Collection.prototype.add.apply(this,[b,c])},onAdd:function(a,b,c){var d=a.get("style");if(!_.isEmpty(d)&&this.editor){var e=this.editor.get("CssComposer"),f=this.editor.get("SelectorManager").add(a.cid);a.set({style:{}}),a.get("classes").add(f);var g=e.add(f);g.set("style",d)}}})}),c("DomComponents/model/Component",["backbone","./Components","SelectorManager/model/Selectors"],function(a,b,c){return a.Model.extend({defaults:{tagName:"div",type:"",editable:!1,removable:!0,draggable:!0,droppable:!0,badgable:!0,stylable:!0,copyable:!0,"void":!1,state:"",status:"",previousModel:"",content:"",style:{},attributes:{}},initialize:function(a,d){d&&d.config&&d.config.voidElements.indexOf(this.get("tagName"))>=0&&this.set("void",!0),this.sm=d?d.sm||{}:{},this.config=a||{},this.defaultC=this.config.components||[],this.defaultCl=this.normalizeClasses(this.config.classes||[]),this.components=new b(this.defaultC,d),this.set("components",this.components),this.set("classes",new c(this.defaultCl))},normalizeClasses:function(a){var b=[];if(this.sm.get){var c=this.sm.get("SelectorManager");if(c)return a.forEach(function(a){var d="";d="string"==typeof a?a:a.name;var e=c.add(d);b.push(e)}),b}},clone:function(){var a=_.clone(this.attributes),b=this.get("components"),c=this.get("classes");return a.components=[],a.classes=[],b.length&&b.each(function(b,c){a.components[c]=b.clone()}),c.length&&c.each(function(b,c){a.classes[c]=b.get("name")}),a.status="",new this.constructor(a,{sm:this.sm})},getName:function(){if(!this.name){var a=this.cid.replace(/\D/g,""),b=this.get("type"),c=this.get("tagName");c="div"==c?"box":c,c=b?b:c,this.name=c.charAt(0).toUpperCase()+c.slice(1)+" "+a}return this.name}})}),c("DomComponents/model/ComponentText",["./Component"],function(a){return a.extend({defaults:_.extend({},a.prototype.defaults,{content:"",droppable:!1})})}),c("DomComponents/model/ComponentImage",["./Component"],function(a){return a.extend({defaults:_.extend({},a.prototype.defaults,{src:"",droppable:!1})})}),c("DomComponents/view/ComponentsView",["backbone","require"],function(a,b){return a.View.extend({initialize:function(a){this.config=a.config,this.listenTo(this.collection,"add",this.addTo),this.listenTo(this.collection,"reset",this.render)},addTo:function(a){var b=this.collection.indexOf(a);this.addToCollection(a,null,b)},addToCollection:function(a,c,d){this.compView||(this.compView=b("./ComponentView"));var e=c||null,f=this.compView;switch(a.get("type")){case"text":this.compViewText||(this.compViewText=b("./ComponentTextView")),f=this.compViewText;break;case"image":this.compViewImage||(this.compViewImage=b("./ComponentImageView")),f=this.compViewImage}var g=new f({model:a,config:this.config}),h=g.render().el;if(e)e.appendChild(h);else{var i=this.$parent;if("undefined"!=typeof d){var j="before";i.children().length==d&&(d--,j="after"),0>d?i.append(h):i.children().eq(d)[j](h)}else i.append(h)}return h},render:function(a){var b=document.createDocumentFragment();return this.$parent=a||this.$el,this.$el.empty(),this.collection.each(function(a){this.addToCollection(a,b)},this),this.$el.append(b),this}})}),c("DomComponents/view/ComponentView",["backbone","./ComponentsView"],function(a,b){return a.View.extend({className:function(){return this.getClasses()},tagName:function(){return this.model.get("tagName")},initialize:function(a){this.config=a.config||{},this.pfx=this.config.stylePrefix||"",this.ppfx=this.config.pStylePrefix||"",this.components=this.model.get("components"),this.attr=this.model.get("attributes"),this.classe=this.attr["class"]||[],this.listenTo(this.model,"destroy remove",this.remove),this.listenTo(this.model,"change:style",this.updateStyle),this.listenTo(this.model,"change:attributes",this.updateAttributes),this.listenTo(this.model,"change:status",this.updateStatus),this.listenTo(this.model,"change:state",this.updateState),this.listenTo(this.model.get("classes"),"add remove change",this.updateClasses),this.$el.data("model",this.model),this.$el.data("collection",this.components),this.model.get("classes").length&&this.importClasses()},importClasses:function(){var a=this.config.em.get("SelectorManager");a&&this.model.get("classes").each(function(b){a.add(b.get("name"))})},updateState:function(a){var b="hc-state",c=this.model.get("state");c?this.$el.addClass(b):this.$el.removeClass(b)},updateStatus:function(a){var b=this.model.get("status"),c=this.pfx;switch(b){case"selected":this.$el.addClass(c+"selected");break;case"moving":break;default:this.$el.removeClass(c+"selected")}},getClasses:function(){var a=this.model.get("attributes"),b=a["class"]||[];return b.length?b.join(" "):null},updateAttributes:function(){var a={},b=this.model.get("attributes");for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);this.model.get("src")&&(a.src=this.model.get("src"));var d=this.getStyleString();d&&(a.style=d),this.$el.attr(a)},updateStyle:function(){this.$el.attr("style",this.getStyleString())},getStyleString:function(){var a="";this.style=this.model.get("style");for(var b in this.style)this.style.hasOwnProperty(b)&&(a+=b+":"+this.style[b]+";");return a},updateClasses:function(){var a="";this.model.get("classes").each(function(b){a+=b.get("name")+" "}),a=a.trim(),a?this.$el.attr("class",a):this.$el.removeAttr("class"),this.updateStatus()},eventCall:function(a){a.viewResponse=this},render:function(){this.updateAttributes(),this.updateClasses(),this.$el.html(this.model.get("content"));var a=new b({collection:this.components,config:this.config});return this.$el.append(a.render(this.$el).el.childNodes),this}})}),c("DomComponents/view/ComponentImageView",["backbone","./ComponentView"],function(a,b){return b.extend({tagName:"img",events:{dblclick:"openModal"},initialize:function(a){b.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"change:src",this.updateSrc),this.listenTo(this.model,"dblclick active",this.openModal),this.classEmpty=this.ppfx+"plh-image",this.config.modal&&(this.modal=this.config.modal),this.config.am&&(this.am=this.config.am)},updateSrc:function(){var a=this.model.get("src");this.$el.attr("src",a),a?this.$el.removeClass(this.classEmpty):this.$el.addClass(this.classEmpty)},openModal:function(a){var b=this;this.modal&&this.am&&(this.modal.setTitle("Select image"),this.modal.setContent(this.am.render(1)),this.am.setTarget(this.model),this.modal.open(),this.am.onSelect(function(){b.modal.close(),b.am.setTarget(null)}))},render:function(){return this.updateAttributes(),this.updateClasses(),this.model.get("src")||this.$el.attr("class",this.classEmpty),this.$el.attr("onmousedown","return false"),this}})}),c("DomComponents/view/ComponentTextView",["backbone","./ComponentView"],function(a,b){return b.extend({events:{dblclick:"enableEditing"},initialize:function(a){b.prototype.initialize.apply(this,arguments),_.bindAll(this,"disableEditing"),this.listenTo(this.model,"focus active",this.enableEditing),this.rte=this.config.rte||""},enableEditing:function(a){this.rte&&this.rte.attach(this),this.toggleEvents(1)},disableEditing:function(a){this.rte&&this.rte.detach(this),this.toggleEvents(),this.updateContents()},disablePropagation:function(a){a.stopPropagation()},updateContents:function(){this.model.set("content",this.el.innerHTML)},toggleEvents:function(a){var b=a?"on":"off",c=[this.el.ownerDocument,document,this.rte];$(c)[b]("mousedown",this.disableEditing),this.$el[b]("mousedown",this.disablePropagation)},render:function(){return this.updateAttributes(),this.updateClasses(),this.el.innerHTML=this.model.get("content"),this}})}),c("DomComponents/main",["require","./config/config","./model/Component","./model/ComponentText","./model/ComponentImage","./view/ComponentView","./view/ComponentImageView","./view/ComponentTextView"],function(a){return function(){var b,c,d={},e=a("./config/config"),f=a("./model/Component"),g=(a("./model/ComponentText"),a("./model/ComponentImage"),a("./view/ComponentView"));a("./view/ComponentImageView"),a("./view/ComponentTextView");return{name:"DomComponents",storageKey:function(){var a=[],b=d.stm&&d.stm.getConfig()||{};return b.storeHtml&&a.push("html"),b.storeComponents&&a.push("components"),a},init:function(a){d=a||{},d.em&&(d.components=d.em.config.components||d.components);for(var h in e)h in d||(d[h]=e[h]);var i=d.pStylePrefix;return i&&(d.stylePrefix=i+d.stylePrefix),d.em&&(d.rte=d.em.get("rte")||"",d.modal=d.em.get("Modal")||"",d.am=d.em.get("AssetManager")||""),b=new f(d.wrapper,{sm:d.em,config:d}),b.set({attributes:{id:"wrapper"}}),b.get("components").add(d.components),c=new g({model:b,config:d}),this},onLoad:function(){d.stm&&d.stm.getConfig().autoload&&this.load(),d.stm&&d.stm.isAutosave()&&(d.em.initUndoManager(),d.em.initChildrenComp(this.getWrapper()))},load:function(a){var b=a||"";!b&&d.stm&&(b=d.em.getCacheLoad());var c="";if(b.components)try{c=JSON.parse(b.components)}catch(e){}else b.html&&(c=b.html);return c&&this.getComponents().reset(c),c},store:function(a){if(d.stm){var b={},c=this.storageKey();return c.indexOf("html")>=0&&(b.html=d.em.getHtml()),c.indexOf("components")>=0&&(b.components=JSON.stringify(d.em.getComponents())),a||d.stm.store(b),b}},getComponent:function(){return b},getWrapper:function(){return this.getComponent()},getComponents:function(){return this.getWrapper().get("components")},addComponent:function(a){return this.getComponents().add(a)},render:function(){return c.render().el},clear:function(){for(var a=this.getComponents(),b=0,c=a.length;c>b;b++)a.pop();return this},setComponents:function(a){this.clear().addComponent(a)}}}}),c("DomComponents",["DomComponents/main"],function(a){return a}),c("Canvas/config/config",[],function(){return{stylePrefix:"cv-",rulers:!1}}),c("Canvas/model/Frame",["backbone"],function(a){return a.Model.extend({defaults:{wrapper:"",width:"",height:"",attributes:{}}})}),c("Canvas/model/Canvas",["backbone","./Frame"],function(a,b){return a.Model.extend({defaults:{frame:"",wrapper:"",rulers:!1},initialize:function(a){var c=this.conf||{};this.set("frame",new b(c.frame))}})}),c("Canvas/view/FrameView",["backbone"],function(a){return a.View.extend({tagName:"iframe",attributes:{src:"about:blank"},initialize:function(a){_.bindAll(this,"udpateOffset"),this.config=a.config||{},this.ppfx=this.config.pStylePrefix||"",this.em=this.config.em,this.motionsEv="transitionend oTransitionEnd transitionend webkitTransitionEnd",this.listenTo(this.em,"change:device",this.updateWidth)},updateWidth:function(a){var b=this.em.getDeviceModel();this.el.style.width=b?b.get("width"):"",this.udpateOffset(),this.$el.on(this.motionsEv,this.udpateOffset)},udpateOffset:function(){var a=this.em.get("Canvas").getOffset();this.em.set("canvasOffset",a),this.$el.off(this.motionsEv,this.udpateOffset)},getBody:function(){this.$el.contents().find("body")},getWrapper:function(){return this.$el.contents().find("body > div")},render:function(){return this.$el.attr({"class":this.ppfx+"frame"}),this}})}),c("Canvas/view/CanvasView",["backbone","./FrameView"],function(a,b){return a.View.extend({initialize:function(a){_.bindAll(this,"renderBody","onFrameScroll"),this.config=a.config||{},this.em=this.config.em||{},this.ppfx=this.config.pStylePrefix||"",this.className=this.config.stylePrefix+"canvas",this.frame=new b({model:this.model.get("frame"),config:this.config})},onFrameScroll:function(){var a="px",b=this.frame.el.contentDocument.body;this.toolsEl.style.top="-"+b.scrollTop+a,this.toolsEl.style.left="-"+b.scrollLeft+a},renderBody:function(){var a=this.model.get("frame").get("wrapper");if(a){var b=this.frame.$el.contents().find("body"),c=this.config.em.get("CssComposer"),d=this.config.em.get("Config");b.append(a.render()).append(c.render());var e=d.protectedCss,f="."+this.ppfx+"dashed *{outline: 1px dashed rgba(170,170,170,0.7); outline-offset: -2px}."+this.ppfx+"comp-selected{outline: 3px solid #3b97e3 !important}."+this.ppfx+"no-select{user-select: none; -webkit-user-select:none; -moz-user-select: none}."+this.ppfx+"freezed{opacity: 0.5; pointer-events: none}."+this.ppfx+"plh-image{background:#f5f5f5; border:none; height:50px; width:50px; display:block; outline:3px solid #ffca6f; cursor:pointer}";e&&b.append(""),this.config.em.trigger("loaded"),this.frame.el.contentWindow.onscroll=this.onFrameScroll,this.frame.udpateOffset();var g=document,h=this.frame.el.contentDocument;h.addEventListener("keydown",function(a){g.dispatchEvent(new KeyboardEvent(a.type,a))}),h.addEventListener("keyup",function(a){g.dispatchEvent(new KeyboardEvent(a.type,a))})}},offset:function(a){var b=a.getBoundingClientRect(),c=a.ownerDocument.body;return{top:b.top+c.scrollTop,left:b.left+c.scrollLeft}},getElementPos:function(a){this.frmOff||(this.frmOff=this.offset(this.frame.el)),this.cvsOff||(this.cvsOff=this.offset(this.el));var b=this.offset(a),c=b.top+this.frmOff.top-this.cvsOff.top,d=b.left+this.frmOff.left-this.cvsOff.left;return{top:c,left:d,height:a.offsetHeight,width:a.offsetWidth}},render:function(){if(this.wrapper=this.model.get("wrapper"),this.wrapper&&"function"==typeof this.wrapper.render){this.model.get("frame").set("wrapper",this.wrapper),this.$el.append(this.frame.render().el);var a=this.frame;a.el.onload=this.renderBody}this.toolsEl=$("",{id:this.ppfx+"tools"}).get(0),this.hlEl=$("
",{"class":this.ppfx+"highlighter"}).get(0),this.badgeEl=$("
",{"class":this.ppfx+"badge"}).get(0),this.placerEl=$("
",{"class":this.ppfx+"placeholder"}).get(0),this.placerIntEl=$("
",{"class":this.ppfx+"placeholder-int"}).get(0),this.ghostEl=$("
",{"class":this.ppfx+"ghost"}).get(0),this.placerEl.appendChild(this.placerIntEl),this.toolsEl.appendChild(this.hlEl),this.toolsEl.appendChild(this.badgeEl),this.toolsEl.appendChild(this.placerEl),this.toolsEl.appendChild(this.ghostEl),this.$el.append(this.toolsEl);var b=this.em.get("rte");return b&&this.toolsEl.appendChild(b.render()),this.$el.attr({"class":this.className}),this}})}),c("Canvas/main",["require","./config/config","./model/Canvas","./view/CanvasView"],function(a){return function(){var b,c={},d=a("./config/config"),e=a("./model/Canvas"),f=a("./view/CanvasView");return{getCanvasView:function(){return f},name:"Canvas",init:function(a){c=a||{};for(var g in d)g in c||(c[g]=d[g]);var h=c.pStylePrefix;h&&(c.stylePrefix=h+c.stylePrefix),b=new e(a),f=new f({model:b,config:c});var i=c.em.get("DomComponents");return i&&this.setWrapper(i),this},setWrapper:function(a){b.set("wrapper",a)},getElement:function(){return f.el},getFrameEl:function(){return f.frame.el},getBody:function(){return f.frame.el.contentDocument.body},getWrapperEl:function(){return this.getBody().querySelector("#wrapper")},getToolsEl:function(){return f.toolsEl},getHighlighter:function(){return f.hlEl},getBadgeEl:function(){return f.badgeEl},getPlacerEl:function(){return f.placerEl},getGhostEl:function(){return f.ghostEl},render:function(){return f.render().el},getOffset:function(){var a=this.offset(this.getFrameEl()),b=this.offset(this.getElement());return{top:a.top-b.top,left:a.left-b.left}},offset:function(a){var b=a.getBoundingClientRect();return{top:b.top+document.body.scrollTop,left:b.left+document.body.scrollLeft}},getFrameWrapperEl:function(){return f.frame.getWrapper()}}}}),c("Canvas",["Canvas/main"],function(a){return a}),c("Commands/config/config",[],function(){return{ESCAPE_KEY:27,stylePrefix:"com-",defaults:[],em:null,firstCentered:!0,newFixedH:!1,minComponentH:50,minComponentW:50}}),c("Commands/view/CommandAbstract",["backbone"],function(a){return a.View.extend({initialize:function(a){this.config=a||{},this.editorModel=this.em=this.config.em||{},this.pfx=this.config.stylePrefix,this.ppfx=this.config.pStylePrefix,this.hoverClass=this.pfx+"hover",this.badgeClass=this.pfx+"badge",this.plhClass=this.pfx+"placeholder",this.freezClass=this.ppfx+"freezed",this.canvas=this.em.get&&this.em.get("Canvas"),this.em.get&&this.setElement(this.getCanvas()),this.canvas&&(this.$canvas=this.$el,
-this.$wrapper=$(this.getCanvasWrapper()),this.frameEl=this.canvas.getFrameEl(),this.canvasTool=this.getCanvasTools(),this.bodyEl=this.getCanvasBody()),this.init(this.config)},onFrameScroll:function(a){},getCanvas:function(){return this.canvas.getElement()},getCanvasBody:function(){return this.canvas.getBody()},getCanvasWrapper:function(){return this.canvas.getWrapperEl()},getCanvasTools:function(){return this.canvas.getToolsEl()},offset:function(a){var b=a.getBoundingClientRect();return{top:b.top+a.ownerDocument.body.scrollTop,left:b.left+a.ownerDocument.body.scrollLeft}},init:function(a){},run:function(a,b){},stop:function(a,b){}})}),c("Commands/view/SelectComponent",[],function(){return{init:function(a){_.bindAll(this,"onHover","onOut","onClick","onKeyPress","clearOff")},enable:function(){_.bindAll(this,"copyComp","pasteComp","onFrameScroll"),this.frameOff=this.canvasOff=this.adjScroll=null;var a=this.config.em.get("Config");this.startSelectComponent(),this.toggleClipboard(a.copyPaste)},toggleClipboard:function(a){var b=a||0;b?(key("⌘+c, ctrl+c",this.copyComp),key("⌘+v, ctrl+v",this.pasteComp)):(key.unbind("⌘+c, ctrl+c"),key.unbind("⌘+v, ctrl+v"))},clearOff:function(){this.frameOff=null,this.canvasOff=null},copyComp:function(){var a=this.editorModel.get("selectedComponent");a&&a.get("copyable")&&this.editorModel.set("clipboard",a)},pasteComp:function(){var a=this.editorModel.get("clipboard"),b=this.editorModel.get("selectedComponent");if(a&&b&&b.collection){var c=b.collection.indexOf(b),d=a.clone();b.collection.add(d,{at:c+1})}},startSelectComponent:function(){this.listenTo(this.em,"change:canvasOffset",this.clearOff),this.selEl=$(this.getCanvasBody()).find("*"),this.selEl.on("mouseover",this.onHover).on("mouseout",this.onOut).on("click",this.onClick);var a=this.getContentWindow();a.on("scroll",this.onFrameScroll),a.on("keydown",this.onKeyPress)},stopSelectComponent:function(){this.stopListening(this.em,"change:canvasOffset",this.clearOff),this.selEl&&this.selEl.trigger("mouseout").off("mouseover",this.onHover).off("mouseout",this.onOut).off("click",this.onClick),this.selEl=null;var a=this.getContentWindow();a.off("scroll",this.onFrameScroll),a.off("keydown",this.onKeyPress)},onKeyPress:function(a){var b=a.which||a.keyCode,c=this.editorModel.get("selectedComponent"),d="BODY"!==this.frameEl.contentDocument.activeElement.tagName;if((8==b||46==b)&&(d||a.preventDefault(),c&&!d)){if(!c.get("removable"))return;c.set("status",""),c.destroy(),this.hideBadge(),this.clean(),this.editorModel.set("selectedComponent",null)}},onHover:function(a){a.stopPropagation();var b=a.target;this.adjScroll||(this.adjScroll=1,this.onFrameScroll(a)),this.updateBadge(b),this.updateHighlighter(b)},onOut:function(a){a.stopPropagation(),this.hideBadge(),this.hl&&this.hl.css({left:-1e4,top:-1e4})},onClick:function(a){var b=$(a.target).data("model");if(b){var c=b.get("stylable");(c instanceof Array||c)&&this.onSelect(a,a.target)}},updateHighlighter:function(a){this.hl||(this.hl=$(this.canvas.getHighlighter()));var b=this.getElementPos($(a));this.hl.css({left:b.left,top:b.topP,height:b.height,width:b.width})},onSelect:function(a,b){a.stopPropagation();var c=this.editorModel.get("selectedComponent");this.cleanPrevious(c);var d=$(b),e=d.data("model");if(e){this.editorModel.set("selectedComponent",e),e.set("status","selected");this.getElementPos(d)}},clean:function(){this.selEl&&this.selEl.removeClass(this.hoverClass)},updateBadge:function(a){var b=$(a);this.cacheEl=b;var c=b.data("model");if(c&&c.get("badgable")){var d=this.getBadge();d.innerHTML=c.getName();var e=d.style,f="px";e.display="block";var g=this.getElementPos(b,d);e.left=g.leftP+f,e.top=g.top+f}},getBadge:function(){return this.canvas.getBadgeEl()},onFrameScroll:function(a){this.cacheEl&&this.updateBadge(this.cacheEl)},getElementPos:function(a,b){this.frameOff||(this.frameOff=this.offset(this.canvas.getFrameEl())),this.canvasOff||(this.canvasOff=this.offset(this.canvas.getElement()));var c=a.offset(),d=this.getCanvasBody(),e=b?b:null,f=e?e.offsetHeight:0,g=e?e.offsetWidth:0,h=c.top+this.frameOff.top-this.canvasOff.top,i=c.left+this.frameOff.left-this.canvasOff.left,j=this.frameOff.top+d.scrollTop,k=this.frameOff.left+d.scrollLeft,l=h;h=j>h-f?j:h-f;var m=k>i+g?k-g:i;return{topP:l,leftP:m,top:h,left:i,height:a.outerHeight(),width:a.outerWidth()}},hideBadge:function(){this.getBadge().style.display="none"},cleanPrevious:function(a){a&&a.set({status:"",state:""})},getContentWindow:function(){return this.contWindow||(this.contWindow=$(this.frameEl.contentWindow)),this.contWindow},run:function(a,b){this.enable()},stop:function(){this.stopSelectComponent(),this.cleanPrevious(this.em.get("selectedComponent")),this.clean(),this.em.set("selectedComponent",null),this.toggleClipboard(),this.hideBadge()}}}),c("Commands/view/SelectPosition",[],function(){return{startSelectPosition:function(a,b){this.isPointed=!1;var c=this.editorModel.get("Utils");c&&!this.sorter&&(this.sorter=new c.Sorter({container:this.getCanvasBody(),placer:this.canvas.getPlacerEl(),containerSel:"*",itemSel:"*",pfx:this.ppfx,direction:"a",document:b,wmargin:1,nested:1,em:this.editorModel})),this.sorter.startSort(a)},getOffsetDim:function(){var a=this.offset(this.canvas.getFrameEl()),b=this.offset(this.canvas.getElement()),c=a.top-b.top,d=a.left-b.left;return{top:c,left:d}},stopSelectPosition:function(){this.posTargetCollection=null,this.posIndex="after"==this.posMethod&&0!==this.cDim.length?this.posIndex+1:this.posIndex,this.sorter&&(this.sorter.moved=0,this.sorter.endMove()),this.cDim&&(this.posIsLastEl=0!==this.cDim.length&&"after"==this.posMethod&&this.posIndex==this.cDim.length,this.posTargetEl=0===this.cDim.length?$(this.outsideElem):!this.posIsLastEl&&this.cDim[this.posIndex]?$(this.cDim[this.posIndex][5]).parent():$(this.outsideElem),this.posTargetModel=this.posTargetEl.data("model"),this.posTargetCollection=this.posTargetEl.data("model-comp"))},enable:function(){this.startSelectPosition()},nearFloat:function(a,b,c){var d=a||0,e=b||"before",f=c.length,g=0!==f&&"after"==e&&d==f;return 0!==f&&(!g&&!c[d][4]||c[d-1]&&!c[d-1][4]||g&&!c[d-1][4])?1:0},run:function(){this.enable()},stop:function(){this.stopSelectPosition(),this.$wrapper.css("cursor",""),this.$wrapper.unbind()}}}),c("Commands/view/CreateComponent",["backbone","./SelectPosition"],function(a,b){return _.extend({},b,{init:function(a){_.bindAll(this,"startDraw","draw","endDraw","rollback"),this.config=a||{},this.hType=this.config.newFixedH?"height":"min-height",this.allowDraw=1},enable:function(){b.enable.apply(this,arguments),this.$wr.css("cursor","crosshair"),this.allowDraw&&this.$wr.on("mousedown",this.startDraw),this.ghost=this.canvas.getGhostEl()},startDraw:function(a){a.preventDefault(),this.stopSelectPosition(),this.ghost.style.display="block",this.frameOff=this.getOffsetDim(),this.startPos={top:a.pageY+this.frameOff.top,left:a.pageX+this.frameOff.left},this.isDragged=!1,this.tempComponent={style:{}},this.beforeDraw(this.tempComponent),this.updateSize(this.startPos.top,this.startPos.left,0,0),this.toggleEvents(1)},toggleEvents:function(a){var b=a?"on":"off";this.$wr[b]("mousemove",this.draw),this.$wr[b]("mouseup",this.endDraw),this.$canvas[b]("mousemove",this.draw),$(document)[b]("mouseup",this.endDraw),$(document)[b]("keypress",this.rollback)},draw:function(a){this.isDragged=!0,this.updateComponentSize(a)},endDraw:function(a){this.toggleEvents();var b={};if(this.isDragged){this.updateComponentSize(a),this.setRequirements(this.tempComponent);var c=this.sorter.lastPos;b=this.create(this.sorter.target,this.tempComponent,c.index,c.method),this.sorter.prevTarget=null}this.ghost.style.display="none",this.startSelectPosition(),this.afterDraw(b)},create:function(a,b,c,d,e){c="after"===d?c+1:c;var f=e||{},g=$(a),h=g.data("model"),i=g.data("collection"),j=h?h.get("droppable"):1;return f.at=c,i&&j?i.add(b,f):void console.warn("Invalid target position")},setRequirements:function(a){var b=this.config,c=a.style;c.width.replace(/\D/g,"")
c&&(f=c,h=d.left-c),e>b&&(e=b,g=d.top-b),this.updateSize(e,f,h,g)},updateSize:function(a,b,c,d){var e="px",f=this.ghost.style,g=this.tempComponent.style;f.top=g.top=a+e,f.left=g.left=b+e,f.width=g.width=c+e,f[this.hType]=g[this.hType]=d+e},rollback:function(a,b){var c=a.which||a.keyCode;(c==this.config.ESCAPE_KEY||b)&&(this.isDragged=!1,this.endDraw())},beforeDraw:function(a){a.editable=!1},afterDraw:function(a){},run:function(a,b,c){this.editor=a,this.sender=b,this.$wr=this.$wrapper,this.enable()},stop:function(){this.stopSelectPosition(),this.$wrapper.css("cursor",""),this.$wrapper.unbind()}})}),c("Commands/view/DeleteComponent",["backbone","./SelectComponent"],function(a,b){return _.extend({},b,{init:function(a){_.bindAll(this,"startDelete","stopDelete","onDelete"),this.hoverClass=this.pfx+"hover-delete",this.badgeClass=this.pfx+"badge-red"},enable:function(){this.$el.find("*").mouseover(this.startDelete).mouseout(this.stopDelete).click(this.onDelete)},startDelete:function(a){a.stopPropagation();var b=$(a.target);b.data("model").get("removable")&&(b.addClass(this.hoverClass),this.attachBadge(b.get(0)))},stopDelete:function(a){a.stopPropagation();var b=$(a.target);b.removeClass(this.hoverClass),this.badge&&this.badge.css({left:-1e3,top:-1e3})},onDelete:function(a){a.stopPropagation();var b=$(a.target);b.data("model").get("removable")&&(b.data("model").destroy(),this.removeBadge(),this.clean())},updateBadgeLabel:function(a){this.badge.html("Remove "+a.getName())}})}),c("Commands/view/InsertCustom",["backbone","./CreateComponent"],function(a,b){return _.extend({},b,{init:function(){b.init.apply(this,arguments),_.bindAll(this,"insertComponent"),this.allowDraw=0},run:function(a,b,c){this.em=a,this.sender=b,this.opt=c||{},this.$wr=this.$wrapper,this.enable()},enable:function(){b.enable.apply(this,arguments),this.$wr.on("click",this.insertComponent)},insertComponent:function(){this.$wr.off("click",this.insertComponent),this.stopSelectPosition();var a=this.buildContent();this.beforeInsert(a);var b=this.sorter.lastPos.index,c=this.create(this.sorter.target,a,b,null,{silent:!1});this.opt.terminateAfterInsert&&this.sender?this.sender.set("active",!1):this.enable(),c&&(this.em&&this.em.editor.initChildrenComp(c),this.afterInsert(c,this))},beforeInsert:function(a){},afterInsert:function(a){},buildContent:function(){return this.opt.content||{}}})}),c("Commands/view/ImageComponent",["backbone","./InsertCustom"],function(a,b){return _.extend({},b,{beforeInsert:function(a){a.type="image",a.style={},a.attributes={},a.attributes.onmousedown="return false",this.config.firstCentered&&this.getCanvasWrapper()==this.sorter.target&&(a.style.margin="0 auto")},afterInsert:function(a){a.trigger("dblclick"),this.sender&&this.sender.set("active",!1)}})}),c("Commands/view/MoveComponent",["backbone","./SelectComponent","./SelectPosition"],function(a,b,c){return _.extend({},c,b,{init:function(a){b.init.apply(this,arguments),_.bindAll(this,"initSorter","rollback","onEndMove"),this.opt=a,this.hoverClass=this.ppfx+"highlighter-warning",this.badgeClass=this.ppfx+"badge-warning",this.noSelClass=this.ppfx+"no-select"},enable:function(){b.enable.apply(this,arguments),this.getBadgeEl().addClass(this.badgeClass),this.getHighlighterEl().addClass(this.hoverClass);var a=this.$wrapper;a.css("cursor","move"),a.on("mousedown",this.initSorter),a.addClass(this.noSelClass)},toggleClipboard:function(){},initSorter:function(a){var b=$(a.target).data("model");b.get("draggable")&&(this.cacheEl=null,this.startSelectPosition(a.target,this.frameEl.contentDocument),this.sorter.onEndMove=this.onEndMove.bind(this),this.stopSelectComponent(),this.$wrapper.off("mousedown",this.initSorter),this.getContentWindow().on("keydown",this.rollback))},onEndMove:function(){this.enable(),this.getContentWindow().off("keydown",this.rollback)},onSelect:function(a,b){},rollback:function(a,b){var c=a.which||a.keyCode;(c==this.opt.ESCAPE_KEY||b)&&(this.sorter.moved=!1,this.sorter.endMove())},getBadgeEl:function(){return this.$badge||(this.$badge=$(this.getBadge())),this.$badge},getHighlighterEl:function(){return this.$hl||(this.$hl=$(this.canvas.getHighlighter())),this.$hl},stop:function(){b.stop.apply(this,arguments),this.getBadgeEl().removeClass(this.badgeClass),this.getHighlighterEl().removeClass(this.hoverClass);var a=this.$wrapper;a.css("cursor","").unbind().removeClass(this.noSelClass)}})}),c("Commands/view/TextComponent",["backbone","./CreateComponent"],function(a,b){return _.extend({},b,{beforeDraw:function(a){a.type="text",a.style||(a.style={}),a.style.padding="10px"},afterDraw:function(a){a&&a.set&&(a.trigger("focus"),this.sender&&this.sender.set("active",!1))}})}),c("Commands/view/ExportTemplate",[],function(){return{run:function(a,b){this.sender=b,this.components=a.DomComponents.getComponents(),this.modal=a.Modal||null,this.cm=a.CodeManager||null,this.cssc=a.CssComposer||null,this.protCss=a.Config.protectedCss,this.pfx=a.Config.stylePrefix||"",this.enable()},buildEditor:function(a,b,c){this.codeMirror||(this.codeMirror=this.cm.getViewer("CodeMirror"));var d=$("