From b76deded6819124d90eed160ac9332677e2e31d6 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 1 Mar 2019 06:28:10 -0500 Subject: [PATCH] Fix issue processwire/processwire-issues#821 front-edit modal "link" dialog in CKEditor was not respecting current language for link helper tools (autocomplete and PageList selection) --- .../Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js | 2 ++ .../Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js index c7099166..993da876 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js +++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js @@ -148,6 +148,8 @@ $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(); // front-end editor } } diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.min.js index 1119d101..bce28193 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(b){var d="a[!href,target,name,title,rel]";var c="a[href]";var e=ProcessWire.config.InputfieldCKEditor.pwlink.classOptions;if(e.length){d+="("+e+")"}b.addCommand("pwlink",{allowedContent:d,requiredContent:c,exec:a});b.addCommand("anchor",new CKEDITOR.dialogCommand("anchor",{allowedContent:"a[!name,id]",requiredContent:"a[name]"}));b.addCommand("unlink",new CKEDITOR.unlinkCommand());b.addCommand("removeAnchor",new CKEDITOR.removeAnchorCommand());b.setKeystroke(CKEDITOR.CTRL+76,"pwlink");if(b.ui.addButton){b.ui.addButton("PWLink",{label:b.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")});b.ui.addButton("Unlink",{label:b.lang.link.unlink,command:"unlink",toolbar:"links,20"});b.ui.addButton("Anchor",{label:b.lang.link.anchor.toolbar,command:"anchor",toolbar:"links,30"})}b.on("doubleclick",function(f){var g=CKEDITOR.plugins.link.getSelectedLink(b)||f.data.element;if(g.is("a")&&!g.getAttribute("name")&&!g.isReadOnly()){var h=jQuery(g.$);if(h.children("img").length==0){f.cancel();b.commands.pwlink.exec()}}});b.on("instanceReady",function(f){f.editor.removeMenuItem("link")});if(b.contextMenu){b.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")});b.contextMenu.addListener(function(g){if(!g||g.isReadOnly()){return null}var f=CKEDITOR.plugins.link.tryRestoreFakeAnchor(b,g);var h={};if(!f&&!(f=CKEDITOR.plugins.link.getSelectedLink(b))){return null}if(f.getAttribute("href")&&f.getChildCount()){h={pwlinkitem:CKEDITOR.TRISTATE_OFF}}return h})}}});function a(g){var i=jQuery("#Inputfield_id");if(i.length){var f=i.val()}else{var f=jQuery("#"+g.name).closest(".Inputfield").attr("data-pid")}var u=jQuery("#"+g.name);var w=g.getSelection(true);var s=w.getStartElement();var c=s.getName();var j=w.getSelectedText();var t=null;var p=CKEDITOR.plugins.link.getEditorAnchors(g);if(c=="a"){t=jQuery(s.$);j=s.getHtml();w.selectElement(s)}else{if(c=="td"||c=="th"||c=="tr"){var v=j.substring(0,1);if(v=="\n"||v=="\r"){ProcessWire.alert("Your selection includes part of the table. Please try selecting the text again.");return}}else{if(c=="img"){var k=jQuery(s.$);t=k.parent("a");j=s.$.outerHTML}else{if(j.length<1){return}else{}}}}var m=ProcessWire.config.urls.admin+"page/link/?id="+f+"&modal=1";var d=u.closest(".LanguageSupport");if(d.length){m+="&lang="+d.data("language")}else{d=u.parents(".InputfieldTable_langTabs").find("li.ui-state-active a");if(d.length&&typeof d.data("lang")!="undefined"){m+="&lang="+d.data("lang")}}if(t!=null){var q=["href","title","class","rel","target"];for(var r=0;r0){for(var r=0;r").append(y).html();g.insertHtml(n)}o.dialog("close")}var e={title:" "+b,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:" "+b,click:h},{html:" "+l,click:function(){o.dialog("close")},"class":"ui-priority-secondary"}]};var o=pwModalWindow(m,e,"medium");o.load(function(){var n=o.contents();n.find("#ProcessPageEditLinkForm").data("iframe",o);jQuery("#link_page_url_input",n).keydown(function(y){var z=jQuery(this);var A=jQuery.trim(z.val());if(y.keyCode==13){y.preventDefault();if(A.length>0){h()}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");if($in.length){var pageID=$in.val()}else{var 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