diff --git a/wire/modules/Inputfield/InputfieldCKEditor/InputfieldCKEditor.module b/wire/modules/Inputfield/InputfieldCKEditor/InputfieldCKEditor.module index 22b8793c..d826f494 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/InputfieldCKEditor.module +++ b/wire/modules/Inputfield/InputfieldCKEditor/InputfieldCKEditor.module @@ -3,10 +3,10 @@ /** * ProcessWire Inputfield for CKEditor * - * CKEditor Copyright (C) 2003-2019, CKSource - Frederico Knabben + * CKEditor Copyright (C) 2003-2021, CKSource - Frederico Knabben * http://ckeditor.com * - * ProcessWire 3.x, Copyright 2019 by Ryan Cramer + * ProcessWire 3.x, Copyright 2021 by Ryan Cramer * https://processwire.com * * FIELD CONFIGURATION @@ -40,7 +40,7 @@ class InputfieldCKEditor extends InputfieldTextarea implements ConfigModule { public static function getModuleInfo() { return array( 'title' => 'CKEditor', - 'version' => 167, + 'version' => 168, 'summary' => __('CKEditor textarea rich text editor.', __FILE__), 'installs' => array('MarkupHTMLPurifier'), ); diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js index 801cdbb3..dceb476b 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js +++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.js @@ -103,6 +103,24 @@ var $figureCaption = null; var nodeParentName = nodeParent.$.nodeName.toUpperCase(); var nodeGrandparentName = nodeGrandparent ? nodeGrandparent.$.nodeName.toUpperCase() : ''; + var figureNodeSafari = null; + + if(selection.getType() == CKEDITOR.SELECTION_TEXT) { + // Safari doesn’t support independent selection of figure elements without display:block, + // so restart selection after changing display property of
to block which then + // makes it selectable in Safari + if(nodeParentName == 'FIGURE') { + figureNodeSafari = nodeParent; + } else if(nodeGrandparentName == 'FIGURE') { + figureNodeSafari = nodeGrandparent; + } + if(figureNodeSafari) { + selection.reset(); + selection.removeAllRanges(); + figureNodeSafari.$.style.display = 'block'; + selection.selectElement(figureNodeSafari); + } + } if(typeof ckeGetProcessWireConfig != "undefined") { // note: ckeGetProcessWireConfig not yet present in front-end editor @@ -263,6 +281,7 @@ } var html = $insertHTML[0].outerHTML; + if(figureNodeSafari) figureNodeSafari.remove(); // Safari inserts an extra
, so remove the original editor.insertHtml(html); editor.fire('change'); $iframe.dialog("close"); diff --git a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js index 70484994..b79c8841 100644 --- a/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js +++ b/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwimage/plugin.min.js @@ -1 +1 @@ -(function(){CKEDITOR.plugins.add("pwimage",{requires:"dialog",init:function(c){var d="pwimage";var f="img[alt,id,!src,title,width](align_left,align_center,align_right,hidpi,align-left,align-center,align-right);a[!href];figure{width}(align_left,align_center,align_right,hidpi,align-left,align-center,align-right);figcaption;";var e="img[alt,src]";c.addCommand(d,{allowedContent:f,requiredContent:e,exec:b});c.ui.addButton("PWImage",{label:c.lang.common.image,command:d,hidpi:true,icon:(CKEDITOR.env.hidpi?this.path+"images/hidpi/pwimage.png":this.path+"images/pwimage.png")});c.on("doubleclick",function(g){var h=g.data.element;if((h.is("img"))&&!h.data("cke-realelement")&&!h.isReadOnly()){g.cancel();c.commands.pwimage.exec()}});if(c.addMenuItems){c.addMenuItems({image:{label:c.lang.image.menu,command:"pwimage",group:"image"}})}if(c.contextMenu){c.contextMenu.addListener(function(g,h){if(a(c,g)){return{image:CKEDITOR.TRISTATE_OFF}}})}}});function a(d,c){if(!c){var e=d.getSelection();c=e.getSelectedElement()}if(c&&c.is("img")&&!c.data("cke-realelement")&&!c.isReadOnly()){return c}}function b(h){var o=jQuery("#Inputfield_id");if(o.length){var p=o.val()}else{var p=jQuery("#"+h.name).closest(".Inputfield").attr("data-pid")}var j=p;var C="";var k="";var s=0;var B=0;var y="";var i="";var c=false;var F=h.getSelection();var G=F.getSelectedElement();var z=F.getStartElement();var D=jQuery(z);var g=z.getParent();var r=g.getParent();var m=D.attr("src");var q=null;var E=null;var v=null;var e=g.$.nodeName.toUpperCase();var l=r?r.$.nodeName.toUpperCase():"";if(typeof ckeGetProcessWireConfig!="undefined"){var A=ckeGetProcessWireConfig(h);if(A&&A.pwAssetPageID){p=A.pwAssetPageID}}F.lock();h.lockSelection();if(l=="FIGURE"){E=jQuery(r.getOuterHtml());v=E.find("figcaption");E.find("img").remove()}else{if(e=="FIGURE"){E=jQuery(g.getOuterHtml());v=E.find("figcaption");E.find("img").remove()}}if(e==="A"){q=jQuery(g.getOuterHtml());q.find("img").remove()}if(m){k=E?E.attr("class"):D.attr("class");c=k&&k.indexOf("hidpi")>-1;s=D.attr("width");B=D.attr("height");y=D.attr("alt");i=e==="A"?g.$.href:"";var x=m.split("/");C=x.pop();x=x.reverse();p="";for(var w=0;w "+ProcessWire.config.InputfieldCKEditor.pwimage.selectLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}}};var u=pwModalWindow(t+f,d,"large");u.load(function(){var I=u.contents();if(I.find("#selected_image").length>0){var n=[{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.insertBtn,click:function(){function O(U){var ae=u.contents();var V=jQuery("#selected_image",ae);var W=V.attr("width");var af=V.attr("height");var aa=jQuery("#selected_image_description",ae).val();var ah=jQuery("#selected_image_caption",ae).is(":checked")?true:false;var ad=jQuery("#selected_image_hidpi",ae).is(":checked")?true:false;var ag=V.removeClass("ui-resizable No Alignment resizable_setup").removeClass("rotate90 rotate180 rotate270 rotate-90 rotate-180 rotate-270").removeClass("flip_vertical flip_horizontal").attr("class");var T=jQuery("#selected_image_link",ae);var ab=T.is(":checked")?T.val():"";var ac=jQuery("").attr("src",U).attr("alt",aa);if(ad){ag+=(ag.length>0?" ":"")+"hidpi"}if(ah===false){ac.addClass(ag)}if(W>0&&V.attr("data-nosize")!="1"){ac.attr("width",W)}if(q){if(ab&&ab.length>0){q.attr("href",ab).attr("data-cke-saved-href",ab)}else{if(T.attr("data-was-checked")==1){q=null}}if(q!==null){q.append(ac);ac=q}}else{if(ab&&ab.length>0){var Y=jQuery("").attr("href",ab).append(ac);ac=Y}}if(ah){var X=jQuery("
");if(ag.length){X.addClass(ag)}if(!v){v=jQuery("
");if(aa.length>1){v.append(aa)}else{v.append(ProcessWire.config.InputfieldCKEditor.pwimage.captionLabel)}}if(v){X.append(v)}X.prepend(ac);ac=X}if(l==="FIGURE"){h.unlockSelection();F.unlock();F.selectElement(r)}else{if(e==="A"||e=="FIGURE"){h.unlockSelection();F.unlock();F.selectElement(g)}}var Z=ac[0].outerHTML;h.insertHtml(Z);h.fire("change");u.dialog("close")}var Q=u.contents();var J=jQuery("#selected_image",Q);u.dialog("disable");u.setTitle(" "+ProcessWire.config.InputfieldCKEditor.pwimage.savingNote);J.removeClass("resized");var K=J.attr("width");if(!K){K=J.width()}var R=J.attr("height");if(!R){R=J.height()}var L=J.attr("src");var S=jQuery("#page_id",Q).val();var P=jQuery("#selected_image_hidpi",Q).is(":checked")?1:0;var N=parseInt(jQuery("#selected_image_rotate",Q).val());L=L.substring(L.lastIndexOf("/")+1);var M=t+"resize?id="+S+"&file="+L+"&width="+K+"&height="+R+"&hidpi="+P;if(N){M+="&rotate="+N}if(J.hasClass("flip_horizontal")){M+="&flip=h"}else{if(J.hasClass("flip_vertical")){M+="&flip=v"}}jQuery.get(M,function(U){var T=jQuery("
").html(U);var V=T.find("#selected_image").attr("src");O(V)})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.selectBtn,"class":"ui-priority-secondary",click:function(){var K=u.contents();var J=jQuery("#page_id",K).val();u.attr("src",t+"?id="+J+"&modal=1");u.setButtons({})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,"class":"ui-priority-secondary",click:function(){u.dialog("close")}}];u.setButtons(n);u.setTitle(" "+I.find("title").html())}else{var n=[];jQuery("button.pw-modal-button, button[type=submit]:visible",I).each(function(){var K=jQuery(this);var J={html:K.html(),click:function(){K.click()}};n.push(J);if(!K.hasClass("pw-modal-button-visible")){K.hide()}});var H={html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,"class":"ui-priority-secondary",click:function(){u.dialog("close")}};n.push(H);u.setButtons(n)}})}})(); \ No newline at end of file +(function(){CKEDITOR.plugins.add("pwimage",{requires:"dialog",init:function(editor){var pluginName="pwimage";var allowed="img[alt,id,!src,title,width](align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"a[!href];"+"figure{width}(align_left,align_center,align_right,hidpi,align-left,align-center,align-right);"+"figcaption;";var required="img[alt,src]";editor.addCommand(pluginName,{allowedContent:allowed,requiredContent:required,exec:loadIframeImagePicker});editor.ui.addButton("PWImage",{label:editor.lang.common.image,command:pluginName,hidpi:true,icon:CKEDITOR.env.hidpi?this.path+"images/hidpi/pwimage.png":this.path+"images/pwimage.png"});editor.on("doubleclick",function(evt){var element=evt.data.element;if(element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly()){evt.cancel();editor.commands.pwimage.exec()}});if(editor.addMenuItems){editor.addMenuItems({image:{label:editor.lang.image.menu,command:"pwimage",group:"image"}})}if(editor.contextMenu){editor.contextMenu.addListener(function(element,selection){if(getSelectedImage(editor,element))return{image:CKEDITOR.TRISTATE_OFF}})}}});function getSelectedImage(editor,element){if(!element){var sel=editor.getSelection();element=sel.getSelectedElement()}if(element&&element.is("img")&&!element.data("cke-realelement")&&!element.isReadOnly())return element}function loadIframeImagePicker(editor){var $in=jQuery("#Inputfield_id");if($in.length){var page_id=$in.val()}else{var page_id=jQuery("#"+editor.name).closest(".Inputfield").attr("data-pid")}var edit_page_id=page_id;var file="";var imgClass="";var imgWidth=0;var imgHeight=0;var imgDescription="";var imgLink="";var hidpi=false;var selection=editor.getSelection();var se=selection.getSelectedElement();var node=selection.getStartElement();var $node=jQuery(node);var nodeParent=node.getParent();var nodeGrandparent=nodeParent.getParent();var src=$node.attr("src");var $linkWrapper=null;var $figureWrapper=null;var $figureCaption=null;var nodeParentName=nodeParent.$.nodeName.toUpperCase();var nodeGrandparentName=nodeGrandparent?nodeGrandparent.$.nodeName.toUpperCase():"";var figureNodeSafari=null;if(selection.getType()==CKEDITOR.SELECTION_TEXT){if(nodeParentName=="FIGURE"){figureNodeSafari=nodeParent}else if(nodeGrandparentName=="FIGURE"){figureNodeSafari=nodeGrandparent}if(figureNodeSafari){selection.reset();selection.removeAllRanges();figureNodeSafari.$.style.display="block";selection.selectElement(figureNodeSafari)}}if(typeof ckeGetProcessWireConfig!="undefined"){var pwCkeSettings=ckeGetProcessWireConfig(editor);if(pwCkeSettings&&pwCkeSettings["pwAssetPageID"])page_id=pwCkeSettings["pwAssetPageID"]}selection.lock();editor.lockSelection();if(nodeGrandparentName=="FIGURE"){$figureWrapper=jQuery(nodeGrandparent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}else if(nodeParentName=="FIGURE"){$figureWrapper=jQuery(nodeParent.getOuterHtml());$figureCaption=$figureWrapper.find("figcaption");$figureWrapper.find("img").remove()}if(nodeParentName==="A"){$linkWrapper=jQuery(nodeParent.getOuterHtml());$linkWrapper.find("img").remove()}if(src){imgClass=$figureWrapper?$figureWrapper.attr("class"):$node.attr("class");hidpi=imgClass&&imgClass.indexOf("hidpi")>-1;imgWidth=$node.attr("width");imgHeight=$node.attr("height");imgDescription=$node.attr("alt");imgLink=nodeParentName==="A"?nodeParent.$.href:"";var parts=src.split("/");file=parts.pop();parts=parts.reverse();page_id="";for(var n=0;n "+ProcessWire.config.InputfieldCKEditor.pwimage.selectLabel,open:function(){if(jQuery(".cke_maximized").length>0){jQuery(".ui-dialog").css("z-index",9999);jQuery(".ui-widget-overlay").css("z-index",9998)}}};var $iframe=pwModalWindow(modalUri+queryString,modalSettings,"large");$iframe.load(function(){var $i=$iframe.contents();if($i.find("#selected_image").length>0){var buttons=[{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.insertBtn,click:function(){function insertImage(src){var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);var width=$img.attr("width");var height=$img.attr("height");var alt=jQuery("#selected_image_description",$i).val();var caption=jQuery("#selected_image_caption",$i).is(":checked")?true:false;var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?true:false;var cls=$img.removeClass("ui-resizable No Alignment resizable_setup").removeClass("rotate90 rotate180 rotate270 rotate-90 rotate-180 rotate-270").removeClass("flip_vertical flip_horizontal").attr("class");var $linkToLarger=jQuery("#selected_image_link",$i);var link=$linkToLarger.is(":checked")?$linkToLarger.val():"";var $insertHTML=jQuery("").attr("src",src).attr("alt",alt);if(hidpi)cls+=(cls.length>0?" ":"")+"hidpi";if(caption===false)$insertHTML.addClass(cls);if(width>0&&$img.attr("data-nosize")!="1")$insertHTML.attr("width",width);if($linkWrapper){if(link&&link.length>0){$linkWrapper.attr("href",link).attr("data-cke-saved-href",link)}else if($linkToLarger.attr("data-was-checked")==1){$linkWrapper=null}if($linkWrapper!==null){$linkWrapper.append($insertHTML);$insertHTML=$linkWrapper}}else if(link&&link.length>0){var $a=jQuery("
").attr("href",link).append($insertHTML);$insertHTML=$a}if(caption){var $figure=jQuery("
");if(cls.length)$figure.addClass(cls);if(!$figureCaption){$figureCaption=jQuery("
");if(alt.length>1){$figureCaption.append(alt)}else{$figureCaption.append(ProcessWire.config.InputfieldCKEditor.pwimage.captionLabel)}}if($figureCaption)$figure.append($figureCaption);$figure.prepend($insertHTML);$insertHTML=$figure}if(nodeGrandparentName==="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeGrandparent)}else if(nodeParentName==="A"||nodeParentName=="FIGURE"){editor.unlockSelection();selection.unlock();selection.selectElement(nodeParent)}var html=$insertHTML[0].outerHTML;if(figureNodeSafari)figureNodeSafari.remove();editor.insertHtml(html);editor.fire("change");$iframe.dialog("close")}var $i=$iframe.contents();var $img=jQuery("#selected_image",$i);$iframe.dialog("disable");$iframe.setTitle(" "+ProcessWire.config.InputfieldCKEditor.pwimage.savingNote);$img.removeClass("resized");var width=$img.attr("width");if(!width)width=$img.width();var height=$img.attr("height");if(!height)height=$img.height();var file=$img.attr("src");var page_id=jQuery("#page_id",$i).val();var hidpi=jQuery("#selected_image_hidpi",$i).is(":checked")?1:0;var rotate=parseInt(jQuery("#selected_image_rotate",$i).val());file=file.substring(file.lastIndexOf("/")+1);var resizeURL=modalUri+"resize?id="+page_id+"&file="+file+"&width="+width+"&height="+height+"&hidpi="+hidpi;if(rotate)resizeURL+="&rotate="+rotate;if($img.hasClass("flip_horizontal"))resizeURL+="&flip=h";else if($img.hasClass("flip_vertical"))resizeURL+="&flip=v";jQuery.get(resizeURL,function(data){var $div=jQuery("
").html(data);var src=$div.find("#selected_image").attr("src");insertImage(src)})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.selectBtn,class:"ui-priority-secondary",click:function(){var $i=$iframe.contents();var page_id=jQuery("#page_id",$i).val();$iframe.attr("src",modalUri+"?id="+page_id+"&modal=1");$iframe.setButtons({})}},{html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}}];$iframe.setButtons(buttons);$iframe.setTitle(" "+$i.find("title").html())}else{var buttons=[];jQuery("button.pw-modal-button, button[type=submit]:visible",$i).each(function(){var $button=jQuery(this);var button={html:$button.html(),click:function(){$button.click()}};buttons.push(button);if(!$button.hasClass("pw-modal-button-visible"))$button.hide()});var cancelButton={html:" "+ProcessWire.config.InputfieldCKEditor.pwimage.cancelBtn,class:"ui-priority-secondary",click:function(){$iframe.dialog("close")}};buttons.push(cancelButton);$iframe.setButtons(buttons)}})}})(); \ No newline at end of file