CKEDITOR.plugins.add("ipslink",{icons:"ipslink",hidpi:!0,init:function(b){b.addCommand("ipsLink",{allowedContent:"a",exec:function(a){var c="",b=ips.getString("editorLinkButton"),c="?app=core&module=system&controller=editor&do=link&editorId="+$("."+a.id).parent().data("ipseditor-name")+"&title="+encodeURIComponent(a.getSelection().getSelectedText()).replace(/%C2%A0/gi,"%20"),d=CKEDITOR.plugins.ipslink.getSelectedLink(a);d&&d.is("img")?a.execCommand("ipsImage"):(d&&(c=d.getAttribute("href"),c="?app=core&module=system&controller=editor&do=link&current="+
encodeURIComponent(c)+"&editorId="+$("."+a.id).parent().data("ipseditor-name")+"&title="+encodeURIComponent(a.getSelection().getSelectedText()).replace(/%C2%A0/gi,"%20")),ips.ui.dialog.create({title:b,fixed:!1,url:c}).show())}});b.ui.addButton("ipsLink",{label:ips.getString("editorLinkButton"),command:"ipsLink",toolbar:"insert"});b.on("doubleclick",function(a){a=CKEDITOR.plugins.ipslink.getSelectedLink(b)||a.data.element;if(!a.isReadOnly()&&a.is("a")&&a.getAttribute("href")){var c=!1;if(1==a.getChildCount())for(var f=
a.getChildren(),d=0;d<f.count();d++){var e=f.getItem(d);if(e.$.nodeType==e.$.ELEMENT_NODE&&e.is("img")){c=!0;b.getSelection().selectElement(e);b.execCommand("ipsImage");break}}c||(b.getSelection().selectElement(a),b.execCommand("ipsLink"))}})}});CKEDITOR.plugins.ipslink={getSelectedLink:function(b){var a=b.getSelection(),c=a.getSelectedElement();return c&&(c.is("a")||c.is("img"))?c:(a=a.getRanges(!0)[0])?(a.shrink(CKEDITOR.SHRINK_TEXT),b.elementPath(a.getCommonAncestor()).contains("a",1)):null}};