(function(){CKEDITOR.plugins.add("pwlink",{requires:"dialog,fakeobjects",init:function(editor){varallowed="a[!href,target,name,title,rel]";varrequired="a[href]";varclassOptions=ProcessWire.config.InputfieldCKEditor.pwlink.classOptions;if(classOptions.length)allowed+="("+classOptions+")";editor.addCommand("pwlink",{allowedContent:allowed,requiredContent:required,exec:loadIframeLinkPicker});editor.addCommand("anchor",newCKEDITOR.dialogCommand("anchor",{allowedContent:"a[!name,id]",requiredContent:"a[name]"}));editor.addCommand("unlink",newCKEDITOR.unlinkCommand);editor.addCommand("removeAnchor",newCKEDITOR.removeAnchorCommand);editor.setKeystroke(CKEDITOR.CTRL+76,"pwlink");if(editor.ui.addButton){editor.ui.addButton("PWLink",{label:editor.lang.link.toolbar,command:"pwlink",toolbar:"links,10",hidpi:true,icon:CKEDITOR.env.hidpi?this.path+"images/hidpi/pwlink.png":this.path+"images/pwlink.png"});editor.ui.addButton("Unlink",{label:editor.lang.link.unlink,command:"unlink",toolbar:"links,20"});editor.ui.addButton("Anchor",{label:editor.lang.link.anchor.toolbar,command:"anchor",toolbar:"links,30"})}editor.on("doubleclick",function(evt){varelement=CKEDITOR.plugins.link.getSelectedLink(editor)||evt.data.element;if(element.is("a")&&!element.getAttribute("name")&&!element.isReadOnly()){var$a=jQuery(element.$);if($a.children("img").length==0){evt.cancel();editor.commands.pwlink.exec()}}});editor.on("instanceReady",function(ck){ck.editor.removeMenuItem("link")});if(editor.contextMenu){editor.addMenuItem("pwlinkitem",{label:ProcessWire.config.InputfieldCKEditor.pwlink.edit,command:"pwlink",group:"link",icon:CKEDITOR.env.hidpi?this.path+"images/hidpi/pwlink.png":this.path+"images/pwlink.png"});editor.contextMenu.addListener(function(element){if(!element||element.isReadOnly())returnnull;varanchor=CKEDITOR.plugins.link.tryRestoreFakeAnchor(editor,element);varmenu={};if(!anchor&&!(anchor=CKEDITOR.plugins.link.getSelectedLink(editor)))returnnull;if(anchor.getAttribute("href")&&anchor.getChildCount())menu={pwlinkitem:CKEDITOR.TRISTATE_OFF};returnmenu})}}});functionloadIframeLinkPicker(editor){var$in=jQuery("#Inputfield_id");varpageID;if($in.length){pageID=$in.val()}else{pageID=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var$textarea=jQuery("#"+editor.name);varselection=editor.getSelection(true);varnode=selection.getStartElement();varnodeName=node.getName();varselectionText=selection.getSelectedText();varselectionHtml=editor.getSelectedHtml(true);var$existingLink=null;varanchors=CKEDITOR.plugins.link.getEditorAnchors(editor);varinlineNodeNames="/em/strong/i/b/u/s/span/small/abbr/cite/figcaption/";if(nodeName!="a"&&nodeName!="img"){varparentNodes=node.getParents();for(varn=0;n<parentNodes.length;n++){varparentNode=parentNodes[n];varparentNodeName=parentNode.getName();if(parentNodeName==="a"){node=parentNode;break}elseif(inlineNodeNames.indexOf("/"+parentNodeName+"/")>-1&&node.getText()===selectionText){node=parentNode;selection.selectElement(node)}}}nodeName=node.getName();if(nodeName=="a"){$existingLink=jQuery(node.$);selectionText=node.getText();selectionHtml=node.getHtml();selection.selectElement(node)}elseif(nodeName=="td"||nodeName=="th"||nodeName=="tr"){varfirstChar=selectionText.substring(0,1);if(firstChar=="\n"||firstChar=="\r"){ProcessWire.alert("Your selection includes part of the table. Please try selecting the text again.");return}}elseif(nodeName=="img"){var$img=jQuery(node.$);$existingLink=$img.parent("a");selectionText=node.$.outerHTML;selectionHtml=selectionText}elseif(selectionText.length<1){return}else{}varmodalUrl=ProcessWire.config.urls.admin+"page/link/?id="+pageID+"&modal=1";var$langWrapper=$textarea.closest(".LanguageSupport");if($langWrapper.length){modalUrl+="&lang="+$langWrapper.data("language")}else{$langWrapper=$textarea.parents(".InputfieldTable_langTabs").find("li.ui-state-active a");if($langWrapper.length&&typeof$langWrapper.data("lang")!="undefined"){modalUrl+="&lang="+$langWrapper.data("lang")}elseif(jQuery("#pw-edit-lang").length){modalUrl+="&lang="+j