CKEDITOR.plugins.add("cms_image",{init:function(a){a.ui.addButton("image",{label:a.lang.common.image,command:"insertImage",toolbar:"insert,0"});if(a.contextMenu){a.addMenuGroup("image");a.addMenuItem("image",{label:a.lang.image.menu,command:"insertImage",group:"image"});a.contextMenu.addListener(function(b){if(b.getAscendant("img",true)){return{image:CKEDITOR.TRISTATE_OFF}}})}a.on("doubleclick",function(b){var c=a.getSelection().getSelectedElement();var d=c&&c.getName()=="img";if(d){a.execCommand("insertImage");b.stop()}});a.addCommand("insertImage",{exec:function(h){var g=h.getSelection().getSelectedElement();var c=g&&g.getName()=="img";if(!c){g=new CKEDITOR.dom.element("img")}var j=g.getAscendant("a");var b=c?g.getAttribute("src"):"";var e=j?j.getAttribute("href"):"";var d="";var i="";if(g.hasClass("s-rounded")){d="s-rounded"}if(g.hasClass("s-circle")){d="s-circle"}if(g.hasClass("s-frame")){d="s-frame"}if(g.hasClass("s-shadow-frame")){d="s-shadow-frame"}if(g.getAttribute("align")){i=g.getAttribute("align")}else{if(g.$.style.margin=="0px auto"){i="center"}}var f=c?g.$.clientWidth:"";var k=c?g.$.clientHeight:"";parent.cms.showImageDialog({url:b,link_url:e,style:d,align:i,title:g.getAttribute("alt"),width:f,height:k,resize:c?1:0},function(m,l){if(c){if(j){if(l.link_url){j.setAttribute("href",l.link_url);j.setAttribute("title",l.title)}else{j.remove(true)}}g.setAttribute("src",l.url);g.setAttribute("alt",l.title);if(l.align=="left"||l.align=="right"){g.setAttribute("align",l.align)}else{g.removeAttribute("align")}g.$.style.margin=l.align=="center"?"0 auto":"";g.$.style.display=l.align=="center"?"block":"";g.removeClass("s-rounded").removeClass("s-circle").removeClass("s-frame").removeClass("s-shadow-frame");if(l.style){g.addClass(l.style)}g.removeAttribute("data-cke-saved-src");return}h.insertElement(new CKEDITOR.dom.element(m));return})}})}});