From 8e11b0ba2f2770dbb95272e3470fc94f974e0ad0 Mon Sep 17 00:00:00 2001 From: dgt41 Date: Sun, 18 Feb 2018 23:27:45 +0100 Subject: [PATCH 1/5] remove tabs and returns and spaces --- plugins/editors/tinymce/tinymce.php | 68 ++++++++++++----------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index 22018c7de155b..f43f4fc92794f 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -778,73 +778,59 @@ private function tinyButtons($name, $excluded) $icon = 'none icon-' . $icon; // Now we can built the script - $tempConstructor = '!(function(){'; + $tempConstructor[] = '!(function(){'; // Get the modal width/height if ($options && is_scalar($options)) { - $tempConstructor .= ' - var getBtnOptions = new Function("return ' . addslashes($options) . '"), - btnOptions = getBtnOptions(), - modalWidth = btnOptions.size && btnOptions.size.x ? btnOptions.size.x : null, - modalHeight = btnOptions.size && btnOptions.size.y ? btnOptions.size.y : null;'; + $tempConstructor[] = 'var getBtnOptions=new Function("return ' . addslashes($options) . '");'; + $tempConstructor[] = 'var btnOptions=getBtnOptions();var modalWidth=btnOptions.size&&'; + $tempConstructor[] = 'btnOptions.size.x?btnOptions.size.x:null;var modalHeight=btnOptions.size&&'; + $tempConstructor[] = 'btnOptions.size.y?btnOptions.size.y:null;'; } else { - $tempConstructor .= ' - var btnOptions = {}, modalWidth = null, modalHeight = null;'; + $tempConstructor[] = 'var btnOptions={},modalWidth=null,modalHeight=null;'; } - $tempConstructor .= " - editor.addButton(\"" . $name . "\", { - text: \"" . $title . "\", - title: \"" . $title . "\", - icon: \"" . $icon . "\", - onclick: function () {"; + // Now we can built the script + $tempConstructor[] = 'editor.addButton("' . $name . '",{'; + $tempConstructor[] = 'text:"' . $title . '",'; + $tempConstructor[] = 'title:"' . $title . '",'; + $tempConstructor[] = 'icon:"' . $icon . '",'; + $tempConstructor[] = 'onclick:function(){'; if ($href || $button->get('modal')) { - $tempConstructor .= " - var modalOptions = { - title : \"" . $title . "\", - url : '" . $href . "', - buttons: [{ - text : \"Close\", - onclick: \"close\" - }] - } - if(modalWidth){ - modalOptions.width = modalWidth; - } - if(modalHeight){ - modalOptions.height = modalHeight; - } - editor.windowManager.open(modalOptions);"; + $tempConstructor[] = 'var modalOptions={'; + $tempConstructor[] = 'title:"' . $title . '",'; + $tempConstructor[] = 'url:"' . $href . '",'; + $tempConstructor[] = 'buttons:[{text: "Close",onclick:"close"}]};'; + $tempConstructor[] = 'modalOptions.width=parseInt(' . intval($options["width"]) . ', 10);'; + $tempConstructor[] = 'modalOptions.height=parseInt(' . intval($options["height"]) . ', 10);'; + $tempConstructor[] = 'if(modalWidth){modalOptions.width=modalWidth;} '; + $tempConstructor[] = 'if(modalHeight){modalOptions.height = modalHeight;} '; + $tempConstructor[] = 'editor.windowManager.open(modalOptions);'; if ($onclick && ($button->get('modal') || $href)) { - $tempConstructor .= "\r\n - " . $onclick . ' - '; + $tempConstructor[] = $onclick . ';'; } } else { - $tempConstructor .= "\r\n - " . $onclick . ' - '; + $tempConstructor[] = $onclick . ';'; } - $tempConstructor .= ' - } - }); - })();'; + $tempConstructor[] = '}'; + $tempConstructor[] = '});'; + $tempConstructor[] = '})();'; // The array with the toolbar buttons $btnsNames[] = $name . ' | '; // The array with code for each button - $tinyBtns[] = $tempConstructor; + $tinyBtns[] = implode($tempConstructor, ''); } } From 77a82c1a7b75a720fe1672c51bb8939639d1b82b Mon Sep 17 00:00:00 2001 From: dgt41 Date: Sun, 18 Feb 2018 23:36:00 +0100 Subject: [PATCH 2/5] more compression --- plugins/editors/tinymce/tinymce.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index f43f4fc92794f..2dc69c5223213 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -783,10 +783,10 @@ private function tinyButtons($name, $excluded) // Get the modal width/height if ($options && is_scalar($options)) { - $tempConstructor[] = 'var getBtnOptions=new Function("return ' . addslashes($options) . '");'; - $tempConstructor[] = 'var btnOptions=getBtnOptions();var modalWidth=btnOptions.size&&'; - $tempConstructor[] = 'btnOptions.size.x?btnOptions.size.x:null;var modalHeight=btnOptions.size&&'; - $tempConstructor[] = 'btnOptions.size.y?btnOptions.size.y:null;'; + $tempConstructor[] = 'var getBtnOptions=new Function("return ' . addslashes($options) . '"),'; + $tempConstructor[] = 'btnOptions=getBtnOptions(),'; + $tempConstructor[] = 'modalWidth=btnOptions.size&&btnOptions.size.x?btnOptions.size.x:null,'; + $tempConstructor[] = 'modalHeight=btnOptions.size&&btnOptions.size.y?btnOptions.size.y:null;'; } else { From 5492af6849d12e6e9d42ac5901acd436f74f89c6 Mon Sep 17 00:00:00 2001 From: dgt41 Date: Sun, 18 Feb 2018 23:53:19 +0100 Subject: [PATCH 3/5] Add some comments so others can follow the code --- plugins/editors/tinymce/tinymce.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index 2dc69c5223213..415877c9e380d 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -794,36 +794,50 @@ private function tinyButtons($name, $excluded) } // Now we can built the script + // AddButton starts here $tempConstructor[] = 'editor.addButton("' . $name . '",{'; $tempConstructor[] = 'text:"' . $title . '",'; $tempConstructor[] = 'title:"' . $title . '",'; $tempConstructor[] = 'icon:"' . $icon . '",'; + + // Onclick starts here $tempConstructor[] = 'onclick:function(){'; if ($href || $button->get('modal')) { + // TinyMCE standard modal options $tempConstructor[] = 'var modalOptions={'; $tempConstructor[] = 'title:"' . $title . '",'; $tempConstructor[] = 'url:"' . $href . '",'; - $tempConstructor[] = 'buttons:[{text: "Close",onclick:"close"}]};'; + $tempConstructor[] = 'buttons:[{text: "Close",onclick:"close"}]'; + $tempConstructor[] = '};'; + + // Set width/height $tempConstructor[] = 'modalOptions.width=parseInt(' . intval($options["width"]) . ', 10);'; $tempConstructor[] = 'modalOptions.height=parseInt(' . intval($options["height"]) . ', 10);'; - $tempConstructor[] = 'if(modalWidth){modalOptions.width=modalWidth;} '; - $tempConstructor[] = 'if(modalHeight){modalOptions.height = modalHeight;} '; + $tempConstructor[] = 'if(modalWidth){modalOptions.width=modalWidth;}'; + $tempConstructor[] = 'if(modalHeight){modalOptions.height = modalHeight;}'; $tempConstructor[] = 'editor.windowManager.open(modalOptions);'; if ($onclick && ($button->get('modal') || $href)) { + // Adds callback for close button $tempConstructor[] = $onclick . ';'; } } else { + // Adds callback for the button, eg: readmore $tempConstructor[] = $onclick . ';'; } + // Onclick ends here $tempConstructor[] = '}'; + + // AddButton ends here $tempConstructor[] = '});'; + + // IIFE ends here $tempConstructor[] = '})();'; // The array with the toolbar buttons From 0efe3c5ab7b7f03102ce3c7fe7eb2597aa7c9b2d Mon Sep 17 00:00:00 2001 From: dgt41 Date: Mon, 19 Feb 2018 21:57:41 +0100 Subject: [PATCH 4/5] Doh, this code was for J4 --- plugins/editors/tinymce/tinymce.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index 415877c9e380d..bb8ef10e58e01 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -813,8 +813,6 @@ private function tinyButtons($name, $excluded) $tempConstructor[] = '};'; // Set width/height - $tempConstructor[] = 'modalOptions.width=parseInt(' . intval($options["width"]) . ', 10);'; - $tempConstructor[] = 'modalOptions.height=parseInt(' . intval($options["height"]) . ', 10);'; $tempConstructor[] = 'if(modalWidth){modalOptions.width=modalWidth;}'; $tempConstructor[] = 'if(modalHeight){modalOptions.height = modalHeight;}'; $tempConstructor[] = 'editor.windowManager.open(modalOptions);'; From 4e3b7ffbbdf253d63d309f3d7c725ad57de41352 Mon Sep 17 00:00:00 2001 From: dgt41 Date: Mon, 19 Feb 2018 23:48:39 +0100 Subject: [PATCH 5/5] =?UTF-8?q?reninitialise=20the=20array=20=F0=9F=98=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/editors/tinymce/tinymce.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index bb8ef10e58e01..4fe0c22d4cb16 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -777,6 +777,8 @@ private function tinyButtons($name, $excluded) // We do some hack here to set the correct icon for 3PD buttons $icon = 'none icon-' . $icon; + $tempConstructor = array(); + // Now we can built the script $tempConstructor[] = '!(function(){';