CKEDITOR.plugins.add("layoutmanager",{requires:"basewidget",icons:"addlayout",lang:"en",init:pluginInit});
function pluginInit(a){a.config.layoutmanager_loadbootstrap&&("object"==typeof a.config.contentsCss?a.config.contentsCss.push(CKEDITOR.getUrl(this.path+"css/bootstrap.css")):a.config.contentsCss=[CKEDITOR.getUrl(this.path+"css/bootstrap.css")]);"object"==typeof a.config.contentsCss?a.config.contentsCss.push(CKEDITOR.getUrl(this.path+"css/style.css")):a.config.contentsCss=[CKEDITOR.getUrl(this.path+"css/style.css")];var b=new LayoutManager(a);b.generateWidgets();a.layoutmanager={};var c;c=a.config.layoutmanager_allowedContent?
a.config.layoutmanager_allowedContent():"p a div span h2 h3 h4 h5 h6 section article iframe object embed strong b i em cite pre blockquote small sub sup code ul ol li dl dt dd table thead tbody th tr td img caption mediawrapper br[href,src,target,width,height,colspan,span,alt,name,title,class,id,data-options]{text-align,float,margin}(*)";b.setAllowedContent(c);c=b.addLayoutDialog.bind(b);b=b.manageLayoutDialog.bind(b);CKEDITOR.dialog.add("addLayoutDialog"+a.name,c);CKEDITOR.dialog.add("manageLayoutDialog"+
a.name,b);a.addCommand("addlayout",{exec:function(a){a.openDialog("addLayoutDialog"+a.name)}});a.addCommand("managelayout",{exec:function(a,c){a.openDialog("manageLayoutDialog"+a.name)}});a.ui.addButton("AddLayout",{title:a.lang.layoutmanager.title,command:"addlayout"})}function LayoutManager(a){this.editor=a;this.layoutBuilder=new LayoutBuilder;a.config.layoutmanager_buildDefaultLayouts||this.layoutBuilder.buildDefaultLayouts()}
LayoutManager.prototype.setAllowedContent=function(a){this.allowedContent=a};
LayoutManager.prototype.createButtonView=function(a,b){var c=[],e=58;this.editor.config.layoutmanager_buttonBoxWidth&&(e=editor.config.layoutmanager_buttonBoxWidth);for(var g=(e-2)/12,d=1;12>=d;d++)c[d]=g*d;g='\x3cdiv class\x3d"container-fluid"\x3e';for(d=0;d<a;d++)g=g.concat('\x3cdiv style\x3d"cursor:pointer;border:1px solid #778899;float:left;position:relative;background:#B0C4DE;text-align:center;height:30px;line-height: 30px;width:'+(c[b[d]]-1)+"px;"+(0!=d?"border-left:none":"")+' "\x3e \x3c/div\x3e');
g=g.concat("\x3c/div\x3e");return{html:g,width:e}};LayoutManager.prototype.createButton=function(a,b){var c=a.split("/"),c=this.createButtonView(c.length,c);return{type:"html",id:a,html:c.html,className:" ",style:"width:"+c.width+"px;",onClick:function(c){b(a);this._.dialog.hide()}}};
LayoutManager.prototype.generateButtonObjects=function(a){var b=this.layoutBuilder.getLayouts(),c={},e;for(e in b)if(b.hasOwnProperty(e)){var g=this.createButton(e,a);c.hasOwnProperty(b[e].rowPosition)||(c[b[e].rowPosition]=[]);c[b[e].rowPosition].push(g)}return c};
LayoutManager.prototype.createDialogDefinition=function(a,b,c,e){var g=[],d;for(d in e)e.hasOwnProperty(d)&&g.push({type:"hbox",id:"row"+d,children:e[d]});return{title:a,minWidth:b,minHeight:c,resizable:CKEDITOR.DIALOG_RESIZE_NONE,buttons:[CKEDITOR.dialog.cancelButton],contents:[{elements:g}]}};LayoutManager.prototype.insertLayoutAction=function(a){this.editor.execCommand(a);this.editor.fire("layoutmanager:layout-inserted")};
LayoutManager.prototype.addLayoutDialog=function(){var a=this.generateButtonObjects(this.insertLayoutAction.bind(this));return this.createDialogDefinition(this.editor.lang.layoutmanager.addLayoutDialogTitle,200,100,a)};
LayoutManager.prototype.changeLayoutAction=function(a){var b=this.editor.layoutmanager.selectedWidget;b.name=a;var c=b.element,e=$(b.element.$).find(".layout-row"),c=c.getChildren().getItem(0).getChildren().getItem(0),g=e.find(".layout-column");c.getChildren();var d=g.length,l=a.split("/");a=l.length;var h=[];h.push("col-xs-{size}");h.push("col-sm-{size}");h.push("col-md-{size}");h.push("col-lg-{size}");var k=/col-(xs|sm|md|lg)-/;if(a<=d){for(c=0;c<a;c++){for(var m=$(g[c]),f=m.attr("class"),n=f.split(" "),
f=0;f<n.length;f++)k.test(n[f])&&m.removeClass(n[f]);for(f=0;f<h.length;f++)m.addClass(h[f].replace("{size}",l[c]))}for(c=d-1;c>=a;c--)b=$(g[c]),e=$(g[c-1]),$(b.children()[0]).children().appendTo($(e.children()[0])),b.remove()}else{for(c=0;c<d;c++){m=$(g[c]);f=m.attr("class");n=f.split(" ");for(f=0;f<n.length;f++)k.test(n[f])&&m.removeClass(n[f]);for(f=0;f<h.length;f++)m.addClass(h[f].replace("{size}",l[c]))}g=["one","two","three"];for(c=d;c<a;c++){d=$("\x3cdiv\x3e").addClass("layout-column");for(f=
0;f<h.length;f++)d.addClass(h[f].replace("{size}",l[c]));f=(new Date).getTime()+Math.floor(100*Math.random()+1);k=$("\x3cdiv\x3e").addClass("layout-column-editable").addClass("layout-column-"+g[c]);d.append(k);e.append(d);b.initEditable(f,{selector:".layout-column-"+g[c]})}}};LayoutManager.prototype.manageLayoutDialog=function(){var a=this.generateButtonObjects(this.changeLayoutAction.bind(this));return this.createDialogDefinition(this.editor.lang.layoutmanager.manageLayoutDialogTitle,200,100,a)};
LayoutManager.prototype.createWidget=function(a,b){CKEDITOR.basewidget.addWidget(this.editor,a,b)};LayoutManager.prototype.createWidgetDefinition=function(a,b,c,e){return{template:a,extend:{init:function(){}},configuration:{init:{blockEvents:!1,configToolbar:{defaultButtons:{edit:{onClick:function(){this.editor.layoutmanager.selectedWidget=this;this.editor.execCommand("managelayout",this)}}}},onDestroy:function(){}}},editables:b,upcast:c,allowedContent:e}};
LayoutManager.prototype.generateWidgets=function(){var a=this.layoutBuilder.getLayouts();this.editables={layoutColumn1:{selector:".layout-column-one",allowedContent:this.allowedContent},layoutColumn2:{selector:".layout-column-two",allowedContent:this.allowedContent},layoutColumn3:{selector:".layout-column-three",allowedContent:this.allowedContent}};var b=function(a){return a.hasClass("layout-container")},c;for(c in a)if(a.hasOwnProperty(c)){var e=this.createWidgetDefinition(a[c].template,this.editables,
b,this.allowedContent);this.createWidget(c,e)}};LayoutManager.prototype.removeLayoutWidget=function(){this.editor.layoutmanager.selectedLayout.widget.repository.del(this.editor.layoutmanager.selectedLayout.widget)};
function LayoutBuilder(){var a=[];a.push(new CKEDITOR.template('\x3cdiv class\x3d"layoutmanager"\x3e\x3cdiv class\x3d"container-fluid layout-container"\x3e\x3cdiv class\x3d"row layout-row" \x3e\x3cdiv class\x3d"col-xs-{size1} col-sm-{size1} col-md-{size1} col-lg-{size1} layout-column"\x3e\x3cdiv class\x3d"layout-column-one layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e'));a.push(new CKEDITOR.template('\x3cdiv class\x3d"layoutmanager"\x3e\x3cdiv class\x3d"container-fluid layout-container"\x3e\x3cdiv class\x3d"row layout-row"\x3e\x3cdiv class\x3d"col-xs-{size1} col-sm-{size1} col-md-{size1} col-lg-{size1} layout-column "\x3e\x3cdiv class\x3d"layout-column-one layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"col-xs-{size2} col-sm-{size2} col-md-{size2} col-lg-{size2} layout-column"\x3e\x3cdiv class\x3d"layout-column-two layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e'));
a.push(new CKEDITOR.template('\x3cdiv class\x3d"layoutmanager"\x3e\x3cdiv class\x3d"container-fluid layout-container"\x3e\x3cdiv class\x3d"row layout-row"\x3e\x3cdiv class\x3d"col-xs-{size1} col-sm-{size1} col-md-{size1} col-lg-{size1} layout-column"\x3e\x3cdiv class\x3d"layout-column-one layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"col-xs-{size2} col-sm-{size2} col-md-{size2} col-lg-{size2} layout-column"\x3e\x3cdiv class\x3d"layout-column-two layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"col-xs-{size3} col-sm-{size3} col-md-{size3} col-lg-{size3} layout-column"\x3e\x3cdiv class\x3d"layout-column-three layout-column-editable"\x3e\x3cp\x3e\x3c/p\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e'));
var b=[];b.push("12");b.push("6/6");b.push("9/3");b.push("3/9");b.push("8/4");b.push("4/8");b.push("7/5");b.push("5/7");b.push("4/4/4");b.push("6/3/3");b.push("3/6/3");b.push("3/3/6");var c={},e=function(a,c){for(var b=c.split("/"),e={},k=0;k<b.length;k++)e["size"+(k+1)]=b[k];b=a.output(e);b=b.replace(/\n/g,"");b=b.replace(/[\t ]+\</g,"\x3c");b=b.replace(/\>[\t ]+\</g,"\x3e\x3c");return b=b.replace(/\>[\t ]+$/g,"\x3e")};this.addLayout=function(b,d){var l=b.split("/").length;c[b]={template:e(a[l-1],
b),rowPosition:d}};this.buildDefaultLayouts=function(){for(var g=0,d=0;d<b.length;d++){0==d%4&&(g+=1);var l=b[d].split("/").length,h=b[d],k=g;c[h]={template:e(a[l-1],h),rowPosition:k}}};this.getLayout=function(a){return c[a]};this.getLayouts=function(){return c}};