div.js 4.6 KB

1
  1. !function(){function e(e,t,n){t.is&&t.getCustomData("block_processed")||(t.is&&CKEDITOR.dom.element.setMarker(n,t,"block_processed",!0),e.push(t))}function t(t,n){function l(){this.foreach(function(e){/^(?!vbox|hbox)/.test(e.type)&&(e.setup||(e.setup=function(t){e.setValue(t.getAttribute(e.id)||"",1)}),e.commit||(e.commit=function(t){var n=this.getValue();("dir"!=e.id||t.getComputedStyle("direction")!=n)&&(n?t.setAttribute(e.id,n):t.removeAttribute(e.id))}))})}var i=function(){var e=CKEDITOR.tools.extend({},CKEDITOR.dtd.$blockLimit);return t.config.div_wrapTable&&(delete e.td,delete e.th),e}(),o=CKEDITOR.dtd.div,a={},d=[];return{title:t.lang.div.title,minWidth:400,minHeight:165,contents:[{id:"info",label:t.lang.common.generalTab,title:t.lang.common.generalTab,elements:[{type:"hbox",widths:["50%","50%"],children:[{id:"elementStyle",type:"select",style:"width: 100%;",label:t.lang.div.styleSelectLabel,"default":"",items:[[t.lang.common.notSet,""]],onChange:function(){var e=["info:elementStyle","info:class","advanced:dir","advanced:style"],n=this.getDialog(),l=n.getModel(t),l=l&&l.clone()||new CKEDITOR.dom.element("div",t.document);this.commit(l,!0);for(var i,e=[].concat(e),o=e.length,a=0;o>a;a++)(i=n.getContentElement.apply(n,e[a].split(":")))&&i.setup&&i.setup(l,!0)},setup:function(e){for(var n in a)a[n].checkElementRemovable(e,!0,t)&&this.setValue(n,1)},commit:function(e){var n;(n=this.getValue())?a[n].applyToObject(e,t):e.removeAttribute("style")}},{id:"class",type:"text",requiredContent:"div(cke-xyz)",label:t.lang.common.cssClass,"default":""}]}]},{id:"advanced",label:t.lang.common.advancedTab,title:t.lang.common.advancedTab,elements:[{type:"vbox",padding:1,children:[{type:"hbox",widths:["50%","50%"],children:[{type:"text",id:"id",requiredContent:"div[id]",label:t.lang.common.id,"default":""},{type:"text",id:"lang",requiredContent:"div[lang]",label:t.lang.common.langCode,"default":""}]},{type:"hbox",children:[{type:"text",id:"style",requiredContent:"div{cke-xyz}",style:"width: 100%;",label:t.lang.common.cssStyle,"default":"",commit:function(e){e.setAttribute("style",this.getValue())}}]},{type:"hbox",children:[{type:"text",id:"title",requiredContent:"div[title]",style:"width: 100%;",label:t.lang.common.advisoryTitle,"default":""}]},{type:"select",id:"dir",requiredContent:"div[dir]",style:"width: 100%;",label:t.lang.common.langDir,"default":"",items:[[t.lang.common.notSet,""],[t.lang.common.langDirLtr,"ltr"],[t.lang.common.langDirRtl,"rtl"]]}]}]}],getModel:function(e){return"editdiv"===n?CKEDITOR.plugins.div.getSurroundDiv(e):null},onLoad:function(){l.call(this);var e=this,n=this.getContentElement("info","elementStyle");t.getStylesSet(function(l){var i,o;if(l)for(var d=0;d<l.length;d++)o=l[d],o.element&&"div"==o.element&&(i=o.name,a[i]=o=new CKEDITOR.style(o),t.filter.check(o)&&(n.items.push([i,i]),n.add(i,i)));n[1<n.items.length?"enable":"disable"](),setTimeout(function(){var l=e.getModel(t);l&&n.setup(l)},0)})},onShow:function(){"editdiv"==n&&this.setupContent(this.getModel(t))},onOk:function(){if("editdiv"==n)d=[this.getModel(t)];else{var l,a,r,s=[],c={},m=[],g=t.getSelection(),u=g.getRanges(),h=g.createBookmarks();for(a=0;a<u.length;a++)for(r=u[a].createIterator();l=r.getNextParagraph();)if(l.getName()in i&&!l.isReadOnly()){var f=l.getChildren();for(l=0;l<f.count();l++)e(m,f.getItem(l),c)}else{for(;!o[l.getName()]&&!l.equals(u[a].root);)l=l.getParent();e(m,l,c)}for(CKEDITOR.dom.element.clearAllMarkers(c),u=[],a=null,r=0;r<m.length;r++)l=m[r],f=t.elementPath(l).blockLimit,f.isReadOnly()&&(f=f.getParent()),t.config.div_wrapTable&&f.is(["td","th"])&&(f=t.elementPath(f.getParent()).blockLimit),f.equals(a)||(a=f,u.push([])),l.getParent()&&u[u.length-1].push(l);for(a=0;a<u.length;a++)if(u[a].length){for(f=u[a][0],m=f.getParent(),l=1;l<u[a].length;l++)m=m.getCommonAncestor(u[a][l]);for(m||(m=t.editable()),r=new CKEDITOR.dom.element("div",t.document),l=0;l<u[a].length;l++){for(f=u[a][l];f.getParent()&&!f.getParent().equals(m);)f=f.getParent();u[a][l]=f}for(l=0;l<u[a].length;l++)f=u[a][l],f.getCustomData&&f.getCustomData("block_processed")||(f.is&&CKEDITOR.dom.element.setMarker(c,f,"block_processed",!0),l||r.insertBefore(f),r.append(f));CKEDITOR.dom.element.clearAllMarkers(c),s.push(r)}g.selectBookmarks(h),d=s}for(s=d.length,c=0;s>c;c++)this.commitContent(d[c]),!d[c].getAttribute("style")&&d[c].removeAttribute("style");this.hide()},onHide:function(){this.getMode(t)===CKEDITOR.dialog.EDITING_MODE&&this.getModel(t).removeCustomData("elementStyle")}}}CKEDITOR.dialog.add("creatediv",function(e){return t(e,"creatediv")}),CKEDITOR.dialog.add("editdiv",function(e){return t(e,"editdiv")})}();