From 108ee2384a7a5c04006a3eb392f0e62c181eafe4 Mon Sep 17 00:00:00 2001 From: rolandtoth Date: Wed, 12 May 2021 15:47:39 -0400 Subject: [PATCH] Add PR #38 which adds an edit-link-text feature to ProcessPageEditLink, via @rolandtoth --- .../InputfieldCKEditor/plugins/pwlink/plugin.js | 12 +++++++++++- .../plugins/pwlink/plugin.min.js | 2 +- .../ProcessPageEditLink/ProcessPageEditLink.js | 15 +++++++++++---- .../ProcessPageEditLink.min.js | 2 +- .../ProcessPageEditLink.module | 17 +++++++++++++++-- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js index 31665715..bdd66d63 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js +++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js @@ -172,6 +172,13 @@ modalUrl += '&anchors[]=' + encodeURIComponent(anchors[n].id); } } + + // set link text + var linkText = ($existingLink && $existingLink.text().length) ? $existingLink.text() : selectionText; + + if(nodeName !== 'img' && linkText.length) { + modalUrl += '&text=' + encodeURIComponent(linkText); + } // labels var insertLinkLabel = ProcessWire.config.InputfieldCKEditor.pwlink.label; @@ -184,7 +191,10 @@ var $i = $iframe.contents(); var $a = jQuery(jQuery("#link_markup", $i).text()); if($a.attr('href') && $a.attr('href').length) { - $a.html(selectionText); + // $a.html(selectionText); + if(!$a.text().length) { + $a.html(selectionText); + } var html = jQuery("
").append($a).html(); editor.insertHtml(html); } diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js index 5a945934..0643dcba 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js +++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js @@ -1 +1 @@ -(function(){CKEDITOR.plugins.add("pwlink",{requires:"dialog,fakeobjects",init:function(editor){var allowed="a[!href,target,name,title,rel]";var required="a[href]";var classOptions=ProcessWire.config.InputfieldCKEditor.pwlink.classOptions;if(classOptions.length)allowed+="("+classOptions+")";editor.addCommand("pwlink",{allowedContent:allowed,requiredContent:required,exec:loadIframeLinkPicker});editor.addCommand("anchor",new CKEDITOR.dialogCommand("anchor",{allowedContent:"a[!name,id]",requiredContent:"a[name]"}));editor.addCommand("unlink",new CKEDITOR.unlinkCommand);editor.addCommand("removeAnchor",new CKEDITOR.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){var element=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())return null;var anchor=CKEDITOR.plugins.link.tryRestoreFakeAnchor(editor,element);var menu={};if(!anchor&&!(anchor=CKEDITOR.plugins.link.getSelectedLink(editor)))return null;if(anchor.getAttribute("href")&&anchor.getChildCount())menu={pwlinkitem:CKEDITOR.TRISTATE_OFF};return menu})}}});function loadIframeLinkPicker(editor){var $in=jQuery("#Inputfield_id");var pageID;if($in.length){pageID=$in.val()}else{pageID=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var $textarea=jQuery("#"+editor.name);var selection=editor.getSelection(true);var node=selection.getStartElement();var nodeName=node.getName();var selectionText=selection.getSelectedText();var $existingLink=null;var anchors=CKEDITOR.plugins.link.getEditorAnchors(editor);if(nodeName=="a"){$existingLink=jQuery(node.$);selectionText=node.getHtml();selection.selectElement(node)}else if(nodeName=="td"||nodeName=="th"||nodeName=="tr"){var firstChar=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}}else if(nodeName=="img"){var $img=jQuery(node.$);$existingLink=$img.parent("a");selectionText=node.$.outerHTML}else if(selectionText.length<1){return}else{}var modalUrl=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")}else if(jQuery("#pw-edit-lang").length){modalUrl+="&lang="+jQuery("#pw-edit-lang").val()}}if($existingLink!=null){var attrs=["href","title","class","rel","target"];for(var n=0;n0){for(var n=0;n").append($a).html();editor.insertHtml(html)}$iframe.dialog("close")}var modalSettings={title:" "+insertLinkLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}},buttons:[{class:"pw_link_submit_insert",html:" "+insertLinkLabel,click:clickInsert},{html:" "+cancelLabel,click:function(){$iframe.dialog("close")},class:"ui-priority-secondary"}]};var $iframe=pwModalWindow(modalUrl,modalSettings,"medium");$iframe.load(function(){var $i=$iframe.contents();$i.find("#ProcessPageEditLinkForm").data("iframe",$iframe);jQuery("#link_page_url_input",$i).keydown(function(event){var $this=jQuery(this);var val=jQuery.trim($this.val());if(event.keyCode==13){event.preventDefault();if(val.length>0)clickInsert();return false}})})}})(); \ No newline at end of file +(function(){CKEDITOR.plugins.add("pwlink",{requires:"dialog,fakeobjects",init:function(editor){var allowed="a[!href,target,name,title,rel]";var required="a[href]";var classOptions=ProcessWire.config.InputfieldCKEditor.pwlink.classOptions;if(classOptions.length)allowed+="("+classOptions+")";editor.addCommand("pwlink",{allowedContent:allowed,requiredContent:required,exec:loadIframeLinkPicker});editor.addCommand("anchor",new CKEDITOR.dialogCommand("anchor",{allowedContent:"a[!name,id]",requiredContent:"a[name]"}));editor.addCommand("unlink",new CKEDITOR.unlinkCommand);editor.addCommand("removeAnchor",new CKEDITOR.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){var element=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())return null;var anchor=CKEDITOR.plugins.link.tryRestoreFakeAnchor(editor,element);var menu={};if(!anchor&&!(anchor=CKEDITOR.plugins.link.getSelectedLink(editor)))return null;if(anchor.getAttribute("href")&&anchor.getChildCount())menu={pwlinkitem:CKEDITOR.TRISTATE_OFF};return menu})}}});function loadIframeLinkPicker(editor){var $in=jQuery("#Inputfield_id");var pageID;if($in.length){pageID=$in.val()}else{pageID=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var $textarea=jQuery("#"+editor.name);var selection=editor.getSelection(true);var node=selection.getStartElement();var nodeName=node.getName();var selectionText=selection.getSelectedText();var $existingLink=null;var anchors=CKEDITOR.plugins.link.getEditorAnchors(editor);if(nodeName=="a"){$existingLink=jQuery(node.$);selectionText=node.getHtml();selection.selectElement(node)}else if(nodeName=="td"||nodeName=="th"||nodeName=="tr"){var firstChar=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}}else if(nodeName=="img"){var $img=jQuery(node.$);$existingLink=$img.parent("a");selectionText=node.$.outerHTML}else if(selectionText.length<1){return}else{}var modalUrl=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")}else if(jQuery("#pw-edit-lang").length){modalUrl+="&lang="+jQuery("#pw-edit-lang").val()}}if($existingLink!=null){var attrs=["href","title","class","rel","target"];for(var n=0;n0){for(var n=0;n").append($a).html();editor.insertHtml(html)}$iframe.dialog("close")}var modalSettings={title:" "+insertLinkLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}},buttons:[{class:"pw_link_submit_insert",html:" "+insertLinkLabel,click:clickInsert},{html:" "+cancelLabel,click:function(){$iframe.dialog("close")},class:"ui-priority-secondary"}]};var $iframe=pwModalWindow(modalUrl,modalSettings,"medium");$iframe.load(function(){var $i=$iframe.contents();$i.find("#ProcessPageEditLinkForm").data("iframe",$iframe);jQuery("#link_page_url_input",$i).keydown(function(event){var $this=jQuery(this);var val=jQuery.trim($this.val());if(event.keyCode==13){event.preventDefault();if(val.length>0)clickInsert();return false}})})}})(); \ No newline at end of file diff --git a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.js b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.js index 6096a75a..e14943db 100644 --- a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.js +++ b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.js @@ -21,8 +21,9 @@ $(document).ready(function() { var $fileSelect = $("#link_page_file"); var $anchorSelect = $("#link_page_anchor"); - var $linkPageURL = $("#link_page_url_input"); - + var $linkPageURL = $("#link_page_url_input"); + var $linkText = $("#link_text"); + $linkPageURL.val($("#link_page_url").val()); // copy from hidden function populateFileSelect(selectedPageData) { @@ -152,7 +153,11 @@ $(document).ready(function() { var val = $("
").text($linkTitle.val()).html(); $link.attr('title', val); } - + + if($linkText.length && $linkText.val().length) { + $link.text($linkText.val()); + } + var $linkRel = $("#link_rel"); if($linkRel.length && $linkRel.val().length) { $link.attr('rel', $linkRel.val()); @@ -307,10 +312,12 @@ $(document).ready(function() { setTimeout(function() { $linkPageURL.change(); + $linkText.change(); }, 250); $(":input").change(updateLinkPreview); - $("#link_title").keydown(function(event) { updateLinkPreview(); }); + $("#link_title").keydown(function(event) { updateLinkPreview(); }); + $linkText.keyup(function(event) { updateLinkPreview(); }); // when header is clicked, open up the pageList right away $(".InputfieldInteger .InputfieldHeader").click(function() { diff --git a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.min.js b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.min.js index bf1b9850..57f4b248 100644 --- a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.min.js +++ b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.min.js @@ -1 +1 @@ -$(document).ready(function(){var options={selectStartLabel:ProcessWire.config.ProcessPageEditLink.selectStartLabel,selectSelectLabel:ProcessWire.config.ProcessPageEditLink.selectStartLabel,langID:ProcessWire.config.ProcessPageEditLink.langID};var options2={selectStartLabel:options.selectStartLabel,selectSelectLabel:options.selectStartLabel,langID:options.langID,rootPageID:ProcessWire.config.ProcessPageEditLink.pageID};var selectedPageData={id:0,title:"",url:""};var $fileSelect=$("#link_page_file");var $anchorSelect=$("#link_page_anchor");var $linkPageURL=$("#link_page_url_input");$linkPageURL.val($("#link_page_url").val());function populateFileSelect(selectedPageData){var $wrap=$("#wrap_link_page_file");$.getJSON("./files?id="+selectedPageData.id,function(data){$fileSelect.empty();$fileSelect.append("");$.each(data,function(key,val){var $option=$("");$fileSelect.append($option)});$wrap.find("p.notes strong").text(selectedPageData.url);if($fileSelect.is(":visible")){$wrap.children().effect("highlight",{},500);$fileSelect.effect("bounce",{},50)}})}function absoluteToRelativePath(path){if(ProcessWire.config.ProcessPageEditLink.urlType==0)return path;function slashesToRelative(url){url=url.replace(/\//g,"../");url=url.replace(/[^.\/]/g,"");return url}var url;if(path===ProcessWire.config.ProcessPageEditLink.pageUrl){path="./";if(!ProcessWire.config.ProcessPageEditLink.slashUrls)path+=ProcessWire.config.ProcessPageEditLink.pageName}else if(path.indexOf(ProcessWire.config.ProcessPageEditLink.pageUrl)===0){path=path.substring(ProcessWire.config.ProcessPageEditLink.pageUrl.length);if(!ProcessWire.config.ProcessPageEditLink.slashUrls)path=ProcessWire.config.ProcessPageEditLink.pageName+path}else if(ProcessWire.config.ProcessPageEditLink.pageUrl.indexOf(path)===0){url=ProcessWire.config.ProcessPageEditLink.pageUrl.substring(path.length);if(url.indexOf("/")!=-1){url=slashesToRelative(url)}else{url="./"}path=url}else if(path.indexOf(ProcessWire.config.ProcessPageEditLink.rootParentUrl)===0){url=path.substring(ProcessWire.config.ProcessPageEditLink.rootParentUrl.length);var url2=url;url=slashesToRelative(url)+url2;path=url}else if(ProcessWire.config.ProcessPageEditLink.urlType==2){url=ProcessWire.config.ProcessPageEditLink.pageUrl.substring(config.urls.root.length);url=slashesToRelative(url);path=path.substring(ProcessWire.config.urls.root.length);path=url+path}return path}function pageSelected(event,data){if(data.url&&data.url.length){selectedPageData=data;selectedPageData.url=ProcessWire.config.urls.root+data.url.substring(1);selectedPageData.url=absoluteToRelativePath(selectedPageData.url);$linkPageURL.val(selectedPageData.url).change();populateFileSelect(selectedPageData)}$(this).parents(".InputfieldInteger").children(".InputfieldHeader").click().parent().find(".PageListSelectHeader").removeClass("hidden").show()}$("#link_page_id").ProcessPageList(options).hide().bind("pageSelected",pageSelected);$("#child_page_id").ProcessPageList(options2).hide().bind("pageSelected",pageSelected);$fileSelect.change(function(){var $t=$(this);var src=$t.val();if(src.length)$linkPageURL.val(src).change()});if($anchorSelect.length){var anchorPreviousValue=$anchorSelect.val();$anchorSelect.change(function(){var val=$(this).val();if(val.length){$linkPageURL.val(val);anchorPreviousValue=val}else{if($linkPageURL.val()==anchorPreviousValue)$linkPageURL.val("")}$linkPageURL.change()})}function updateLinkPreview(){if(!$linkPageURL.val().length){$("#link_markup").text("");return}var $link=$("");$link.attr("href",$linkPageURL.val());var $linkTitle=$("#link_title");if($linkTitle.length&&$linkTitle.val().length){var val=$("
").text($linkTitle.val()).html();$link.attr("title",val)}var $linkRel=$("#link_rel");if($linkRel.length&&$linkRel.val().length){$link.attr("rel",$linkRel.val())}var $linkTarget=$("#link_target");if($linkTarget.length&&$linkTarget.val().length){$link.attr("target",$linkTarget.val())}var $linkClass=$("#wrap_link_class").find("input:checked");if($linkClass.length){$linkClass.each(function(){$link.addClass($(this).val())})}$("#link_markup").text($link[0].outerHTML)}function urlKeydown(){var $this=$linkPageURL;var val=$.trim($this.val());var dotpos=val.indexOf(".");var slashespos=val.indexOf("//");var hasScheme=slashespos>-1&&slashespos-1?val.indexOf("/",slashespos+2):val.indexOf("/");var httpHost;var n;if(dotpos>-1&&val.indexOf("..")==-1&&val.indexOf("./")==-1&&(slashpos>dotpos&&!hasScheme||slashpos==-1&&dotpos>1&&val.match(/^[a-z][-a-z.0-9]+\.[a-z]{2,}($|\/)/i))){var domain=val.substring(0,slashpos>0?slashpos:val.length);hasScheme=true;if($this.attr("data-ignore")==domain){}else{$this.val("http://"+val);$this.closest(".InputfieldContent").find(".notes").text("http://"+val);$this.attr("data-ignore",domain)}}else if(dotpos>0&&val.indexOf("@")>0&&val.indexOf(":")==-1&&val.match(/^[^@]+@[-.a-z0-9]{2,}\.[a-z]{2,}$/i)){$this.val("mailto:"+val);$this.addClass("email")}else if(val.indexOf("@")==-1&&$this.hasClass("email")){$this.removeClass("email")}if(val.substring(0,1)=="#"){$this.addClass("anchor")}else if($this.hasClass("anchor")){$this.removeClass("anchor")}if(hasScheme){if(slashpos==-1)slashpos=val.length;httpHost=slashespos>-1?val.substring(slashespos+2,slashpos):val.substring(0,slashpos);$this.attr("data-httphost",httpHost)}else{$this.removeAttr("data-httphost")}function icon(){return $this.closest(".Inputfield").children(".InputfieldHeader").children("i").eq(0)}var external=false;httpHost=$this.attr("data-httphost");if(httpHost&&httpHost.length){external=true;for(n=0;n0){$("#link_target").val(extLinkTarget)}var extLinkRel=ProcessWire.config.ProcessPageEditLink.extLinkRel;if(extLinkRel.length>0){$("#link_rel").val(extLinkRel)}var extLinkClass=ProcessWire.config.ProcessPageEditLink.extLinkClass;if(extLinkClass.length>0){extLinkClass=extLinkClass.split(" ");for(n=0;n");$.each(data,function(key,val){var $option=$("");$fileSelect.append($option)});$wrap.find("p.notes strong").text(selectedPageData.url);if($fileSelect.is(":visible")){$wrap.children().effect("highlight",{},500);$fileSelect.effect("bounce",{},50)}})}function absoluteToRelativePath(path){if(ProcessWire.config.ProcessPageEditLink.urlType==0)return path;function slashesToRelative(url){url=url.replace(/\//g,"../");url=url.replace(/[^.\/]/g,"");return url}var url;if(path===ProcessWire.config.ProcessPageEditLink.pageUrl){path="./";if(!ProcessWire.config.ProcessPageEditLink.slashUrls)path+=ProcessWire.config.ProcessPageEditLink.pageName}else if(path.indexOf(ProcessWire.config.ProcessPageEditLink.pageUrl)===0){path=path.substring(ProcessWire.config.ProcessPageEditLink.pageUrl.length);if(!ProcessWire.config.ProcessPageEditLink.slashUrls)path=ProcessWire.config.ProcessPageEditLink.pageName+path}else if(ProcessWire.config.ProcessPageEditLink.pageUrl.indexOf(path)===0){url=ProcessWire.config.ProcessPageEditLink.pageUrl.substring(path.length);if(url.indexOf("/")!=-1){url=slashesToRelative(url)}else{url="./"}path=url}else if(path.indexOf(ProcessWire.config.ProcessPageEditLink.rootParentUrl)===0){url=path.substring(ProcessWire.config.ProcessPageEditLink.rootParentUrl.length);var url2=url;url=slashesToRelative(url)+url2;path=url}else if(ProcessWire.config.ProcessPageEditLink.urlType==2){url=ProcessWire.config.ProcessPageEditLink.pageUrl.substring(config.urls.root.length);url=slashesToRelative(url);path=path.substring(ProcessWire.config.urls.root.length);path=url+path}return path}function pageSelected(event,data){if(data.url&&data.url.length){selectedPageData=data;selectedPageData.url=ProcessWire.config.urls.root+data.url.substring(1);selectedPageData.url=absoluteToRelativePath(selectedPageData.url);$linkPageURL.val(selectedPageData.url).change();populateFileSelect(selectedPageData)}$(this).parents(".InputfieldInteger").children(".InputfieldHeader").click().parent().find(".PageListSelectHeader").removeClass("hidden").show()}$("#link_page_id").ProcessPageList(options).hide().bind("pageSelected",pageSelected);$("#child_page_id").ProcessPageList(options2).hide().bind("pageSelected",pageSelected);$fileSelect.change(function(){var $t=$(this);var src=$t.val();if(src.length)$linkPageURL.val(src).change()});if($anchorSelect.length){var anchorPreviousValue=$anchorSelect.val();$anchorSelect.change(function(){var val=$(this).val();if(val.length){$linkPageURL.val(val);anchorPreviousValue=val}else{if($linkPageURL.val()==anchorPreviousValue)$linkPageURL.val("")}$linkPageURL.change()})}function updateLinkPreview(){if(!$linkPageURL.val().length){$("#link_markup").text("");return}var $link=$("");$link.attr("href",$linkPageURL.val());var $linkTitle=$("#link_title");if($linkTitle.length&&$linkTitle.val().length){var val=$("
").text($linkTitle.val()).html();$link.attr("title",val)}if($linkText.length&&$linkText.val().length){$link.text($linkText.val())}var $linkRel=$("#link_rel");if($linkRel.length&&$linkRel.val().length){$link.attr("rel",$linkRel.val())}var $linkTarget=$("#link_target");if($linkTarget.length&&$linkTarget.val().length){$link.attr("target",$linkTarget.val())}var $linkClass=$("#wrap_link_class").find("input:checked");if($linkClass.length){$linkClass.each(function(){$link.addClass($(this).val())})}$("#link_markup").text($link[0].outerHTML)}function urlKeydown(){var $this=$linkPageURL;var val=$.trim($this.val());var dotpos=val.indexOf(".");var slashespos=val.indexOf("//");var hasScheme=slashespos>-1&&slashespos-1?val.indexOf("/",slashespos+2):val.indexOf("/");var httpHost;var n;if(dotpos>-1&&val.indexOf("..")==-1&&val.indexOf("./")==-1&&(slashpos>dotpos&&!hasScheme||slashpos==-1&&dotpos>1&&val.match(/^[a-z][-a-z.0-9]+\.[a-z]{2,}($|\/)/i))){var domain=val.substring(0,slashpos>0?slashpos:val.length);hasScheme=true;if($this.attr("data-ignore")==domain){}else{$this.val("http://"+val);$this.closest(".InputfieldContent").find(".notes").text("http://"+val);$this.attr("data-ignore",domain)}}else if(dotpos>0&&val.indexOf("@")>0&&val.indexOf(":")==-1&&val.match(/^[^@]+@[-.a-z0-9]{2,}\.[a-z]{2,}$/i)){$this.val("mailto:"+val);$this.addClass("email")}else if(val.indexOf("@")==-1&&$this.hasClass("email")){$this.removeClass("email")}if(val.substring(0,1)=="#"){$this.addClass("anchor")}else if($this.hasClass("anchor")){$this.removeClass("anchor")}if(hasScheme){if(slashpos==-1)slashpos=val.length;httpHost=slashespos>-1?val.substring(slashespos+2,slashpos):val.substring(0,slashpos);$this.attr("data-httphost",httpHost)}else{$this.removeAttr("data-httphost")}function icon(){return $this.closest(".Inputfield").children(".InputfieldHeader").children("i").eq(0)}var external=false;httpHost=$this.attr("data-httphost");if(httpHost&&httpHost.length){external=true;for(n=0;n0){$("#link_target").val(extLinkTarget)}var extLinkRel=ProcessWire.config.ProcessPageEditLink.extLinkRel;if(extLinkRel.length>0){$("#link_rel").val(extLinkRel)}var extLinkClass=ProcessWire.config.ProcessPageEditLink.extLinkClass;if(extLinkClass.length>0){extLinkClass=extLinkClass.split(" ");for(n=0;n 'Page Edit Link', 'summary' => 'Provides a link capability as used by some Fieldtype modules (like rich text editors).', - 'version' => 108, + 'version' => 109, 'permanent' => true, 'permission' => 'page-edit', 'icon' => 'link', @@ -152,6 +152,9 @@ class ProcessPageEditLink extends Process implements ConfigurableModule { $currentValue = ''; } + $currentText = $this->wire()->input->get('text'); + $currentText = $currentText === null ? '' : $this->wire()->sanitizer->text($currentText); + /** @var InputfieldForm $form */ $form = $this->modules->get("InputfieldForm"); $form->attr('id', 'ProcessPageEditLinkForm'); @@ -163,7 +166,17 @@ class ProcessPageEditLink extends Process implements ConfigurableModule { $fieldset = $this->wire(new InputfieldWrapper()); $fieldset->attr('title', $this->_('Link')); $fieldset->addClass('WireTab'); - $form->add($fieldset); + $form->add($fieldset); + + if($currentText) { + /** @var InputfieldText $field */ + $field = $this->modules->get("InputfieldText"); + $field->label = $this->_('Link text'); + $field->icon = 'pencil-square'; + $field->attr('id+name', 'link_text'); + $field->val($currentText); + $fieldset->add($field); + } /** @var InputfieldPageAutocomplete $field */ $field = $this->modules->get("InputfieldPageAutocomplete");