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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@ -778,73 +778,73 @@ 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[] = '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[] = '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 . '
';
// 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[] = '})();';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIFE ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Immediately Invoked Function Expression

Basically an anonymous function that is immediately executed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It ends there but where does it start?


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

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

Expand Down