Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyMCE: uglify the inline XTD-btns script #19731

Merged
merged 5 commits into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions plugins/editors/tinymce/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,74 +777,74 @@ 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(){';
$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[] = '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
{
$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
// 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'))
{
$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);";
// TinyMCE standard modal options
$tempConstructor[] = 'var modalOptions={';
$tempConstructor[] = 'title:"' . $title . '",';
$tempConstructor[] = 'url:"' . $href . '",';
$tempConstructor[] = 'buttons:[{text: "Close",onclick:"close"}]';
$tempConstructor[] = '};';

// Set width/height
$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 . '
';
// Adds callback for close button
$tempConstructor[] = $onclick . ';';
}
}
else
{
$tempConstructor .= "\r\n
" . $onclick . '
';
// Adds callback for the button, eg: readmore
$tempConstructor[] = $onclick . ';';
}

$tempConstructor .= '
}
});
})();';
// Onclick ends here
$tempConstructor[] = '}';

// AddButton ends here
$tempConstructor[] = '});';

// IIFE ends here
$tempConstructor[] = '})();';

// The array with the toolbar buttons
$btnsNames[] = $name . ' | ';

// The array with code for each button
$tinyBtns[] = $tempConstructor;
$tinyBtns[] = implode($tempConstructor, '');
}
}

Expand Down