CKEDITOR.plugins.add('link',{init:function(a){a.addCommand('link',new CKEDITOR.dialogCommand('link'));a.addCommand('anchor',new CKEDITOR.dialogCommand('anchor'));a.addCommand('unlink',new CKEDITOR.unlinkCommand());a.ui.addButton('Link',{label:a.lang.link.toolbar,command:'link'});a.ui.addButton('Unlink',{label:a.lang.unlink,command:'unlink'});a.ui.addButton('Anchor',{label:a.lang.anchor.toolbar,command:'anchor'});CKEDITOR.dialog.add('link',this.path+'dialogs/link.js');CKEDITOR.dialog.add('anchor',this.path+'dialogs/anchor.js');var b=a.lang.dir=='rtl'?'right':'left',c='background:url('+CKEDITOR.getUrl(this.path+'images/anchor.gif')+') no-repeat '+b+' center;'+'border:1px dotted #00f;';a.addCss('a.cke_anchor,a.cke_anchor_empty'+(CKEDITOR.env.ie&&CKEDITOR.env.version<7?'':',a[name],a[data-cke-saved-name]')+'{'+c+'padding-'+b+':18px;'+'cursor:auto;'+'}'+(CKEDITOR.env.ie?'a.cke_anchor_empty{display:inline-block;}':'')+'img.cke_anchor'+'{'+c+'width:16px;'+'min-height:15px;'+'height:1.15em;'+'vertical-align:'+(CKEDITOR.env.opera?'middle':'text-bottom')+';'+'}');a.on('selectionChange',function(d){if(a.readOnly)return;var e=a.getCommand('unlink'),f=d.data.path.lastElement&&d.data.path.lastElement.getAscendant('a',true);if(f&&f.getName()=='a'&&f.getAttribute('href')&&f.getChildCount())e.setState(CKEDITOR.TRISTATE_OFF);else e.setState(CKEDITOR.TRISTATE_DISABLED);});a.on('doubleclick',function(d){var e=CKEDITOR.plugins.link.getSelectedLink(a)||d.data.element;if(!e.isReadOnly())if(e.is('a')){d.data.dialog=e.getAttribute('name')&&(!e.getAttribute('href')||!e.getChildCount())?'anchor':'link';a.getSelection().selectElement(e);}else if(CKEDITOR.plugins.link.tryRestoreFakeAnchor(a,e))d.data.dialog='anchor';});if(a.addMenuItems)a.addMenuItems({anchor:{label:a.lang.anchor.menu,command:'anchor',group:'anchor'},link:{label:a.lang.link.menu,command:'link',group:'link',order:1},unlink:{label:a.lang.unlink,command:'unlink',group:'link',order:5}});if(a.contextMenu)a.contextMenu.addListener(function(d,e){if(!d||d.isReadOnly())return null;var f=CKEDITOR.plugins.link.tryRestoreFakeAnchor(a,d);if(!f&&!(f=CKEDITOR.plugins.link.getSelectedLink(a)))return null;var g={};if(f.getAttribute('href')&&f.getChildCount())g={link:CKEDITOR.TRISTATE_OFF,unlink:CKEDITOR.TRISTATE_OFF};if(f&&f.hasAttribute('name'))g.anchor=CKEDITOR.TRISTATE_OFF;return g;});},afterInit:function(a){var b=a.dataProcessor,c=b&&b.dataFilter,d=b&&b.htmlFilter,e=a._.elementsPath&&a._.elementsPath.filters;if(c)c.addRules({elements:{a:function(f){var g=f.attributes;
if(!g.name)return null;var h=!f.children.length;if(CKEDITOR.plugins.link.synAnchorSelector){var i=h?'cke_anchor_empty':'cke_anchor',j=g['class'];if(g.name&&(!j||j.indexOf(i)<0))g['class']=(j||'')+' '+i;if(h&&CKEDITOR.plugins.link.emptyAnchorFix){g.contenteditable='false';g['data-cke-editable']=1;}}else if(CKEDITOR.plugins.link.fakeAnchor&&h)return a.createFakeParserElement(f,'cke_anchor','anchor');return null;}}});if(CKEDITOR.plugins.link.emptyAnchorFix&&d)d.addRules({elements:{a:function(f){delete f.attributes.contenteditable;}}});if(e)e.push(function(f,g){if(g=='a')if(CKEDITOR.plugins.link.tryRestoreFakeAnchor(a,f)||f.getAttribute('name')&&(!f.getAttribute('href')||!f.getChildCount()))return 'anchor';});},requires:['fakeobjects']});CKEDITOR.plugins.link={getSelectedLink:function(a){try{var b=a.getSelection();if(b.getType()==CKEDITOR.SELECTION_ELEMENT){var c=b.getSelectedElement();if(c.is('a'))return c;}var d=b.getRanges(true)[0];d.shrink(CKEDITOR.SHRINK_TEXT);var e=d.getCommonAncestor();return e.getAscendant('a',true);}catch(f){return null;}},fakeAnchor:CKEDITOR.env.opera||CKEDITOR.env.webkit,synAnchorSelector:CKEDITOR.env.ie,emptyAnchorFix:CKEDITOR.env.ie&&CKEDITOR.env.version<8,tryRestoreFakeAnchor:function(a,b){if(b&&b.data('cke-real-element-type')&&b.data('cke-real-element-type')=='anchor'){var c=a.restoreRealElement(b);if(c.data('cke-saved-name'))return c;}}};CKEDITOR.unlinkCommand=function(){};CKEDITOR.unlinkCommand.prototype={exec:function(a){var b=a.getSelection(),c=b.createBookmarks(),d=b.getRanges(),e,f;for(var g=0;g<d.length;g++){e=d[g].getCommonAncestor(true);f=e.getAscendant('a',true);if(!f)continue;d[g].selectNodeContents(f);}b.selectRanges(d);a.document.$.execCommand('unlink',false,null);b.selectBookmarks(c);},startDisabled:true};CKEDITOR.tools.extend(CKEDITOR.config,{linkShowAdvancedTab:true,linkShowTargetTab:true});
