NEW_CKEDITOR.dialog.add("anchor",(function(e){function t(e,t){return e.createFakeElement(e.document.createElement("a",{attributes:t}),"edi_anchor","anchor")}return{title:e.lang.link.anchor.title,minWidth:300,minHeight:60,getModel:function(e){var t=e.getSelection();return e=t.getRanges()[0],t=t.getSelectedElement(),e.shrink(NEW_CKEDITOR.SHRINK_ELEMENT),(t=e.getEnclosedNode())&&t.type===NEW_CKEDITOR.NODE_TEXT&&(t=t.getParent()),t&&!t.is("a")&&(t=t.getAscendant("a")||t),(e=t&&t.type===NEW_CKEDITOR.NODE_ELEMENT&&("anchor"===t.data("edi-real-element-type")||t.is("a"))?t:void 0)||null},onOk:function(){var n={id:n=NEW_CKEDITOR.tools.trim(this.getValueOf("info","txtName")),name:n,"data-edi-saved-name":n},a=this.getModel(e);if(a)a.data("edi-realelement")?((n=t(e,n)).replace(a),NEW_CKEDITOR.env.ie&&e.getSelection().selectElement(n)):a.setAttributes(n);else if((a=(a=e.getSelection())&&a.getRanges()[0]).collapsed)n=t(e,n),a.insertNode(n);else{NEW_CKEDITOR.env.ie&&9>NEW_CKEDITOR.env.version&&(n.class="edi_anchor"),(i=a.clone()).enlarge(NEW_CKEDITOR.ENLARGE_ELEMENT);for(var l=new NEW_CKEDITOR.dom.walker(i),i=i.collapsed?i.startContainer:l.next(),r=a.createBookmark();i;)i.type===NEW_CKEDITOR.NODE_ELEMENT&&i.getAttribute("data-edi-saved-name")&&(i.remove(!0),l.reset()),i=l.next();a.moveToBookmark(r),(n=new NEW_CKEDITOR.style({element:"a",attributes:n})).type=NEW_CKEDITOR.STYLE_INLINE,n.applyToRange(a)}},onShow:function(){var t=e.getSelection(),n=this.getModel(e),a=n&&n.data("edi-realelement");if(n=a?NEW_CKEDITOR.plugins.link.tryRestoreFakeAnchor(e,n):NEW_CKEDITOR.plugins.link.getSelectedLink(e)){var l=n.data("edi-saved-name");this.setValueOf("info","txtName",l||""),!a&&t.selectElement(n)}this.getContentElement("info","txtName").focus()},contents:[{id:"info",label:e.lang.link.anchor.title,accessKey:"I",elements:[{type:"text",id:"txtName",label:e.lang.link.anchor.name,required:!0,validate:function(){var t=this.getValue();return t?!/[\u0020\u0009\u000a\u000c\u000d]/g.test(t)||(alert(e.lang.link.anchor.errorWhitespace),!1):(alert(e.lang.link.anchor.errorName),!1)}}]}]}}));