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 DRY for the inline script #8366

Merged
merged 10 commits into from
Nov 18, 2015
Merged
Changes from all 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
193 changes: 96 additions & 97 deletions plugins/editors/tinymce/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,19 @@ public function onInit()
$mode = 0;
}

switch ($mode)
{
case 0: /* Simple mode*/
JFactory::getDocument()->addScriptDeclaration(
"
$script = '';

// Mootools b/c
$script .= '
window.getSize = window.getSize || function(){return {x: jQuery(window).width(), y: jQuery(window).height()};};
';

$script .= "
tinymce.init({
// General
";

// General
$script .= "
directionality: \"$text_direction\",
selector: \"textarea.mce_editable\",
language : \"$langPrefix\",
Expand All @@ -722,111 +728,78 @@ public function onInit()
$skin
theme : \"$theme\",
schema: \"html5\",
menubar: false,
toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist | $toolbar5 | code\",
plugins: \"$dragDropPlg code\",
// Cleanup/Output
";

// Cleanup/Output
$script .= "
inline_styles : true,
gecko_spellcheck : true,
entity_encoding : \"$entity_encoding\",
$forcenewline
$smallButtons
// URL
";

// URL
$script .= "
relative_urls : $relative_urls,
remove_script_host : false,
// Layout
";

// Layout
$script .= "
$content_css
document_base_url : \"" . JUri::root() . "\",
setup: function (editor) {
$tinyBtns
$tinyBtns
},
paste_data_images: $allowImgPaste
paste_data_images: $allowImgPaste,
";
switch ($mode)
{
case 0: /* Simple mode*/
$script .= "
menubar: false,
toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist | $toolbar5 | code\",
plugins: \"$dragDropPlg code\",
});
"
);
";
break;

case 1:
default: /* Advanced mode*/
$toolbar1 = "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect | bullist numlist "
. "| outdent indent | undo redo | link unlink anchor image | hr table | subscript superscript | charmap";
JFactory::getDocument()->addScriptDeclaration(
"
tinyMCE.init({
// General
directionality: \"$text_direction\",
language : \"$langPrefix\",
mode : \"specific_textareas\",
autosave_restore_when_empty: false,
$skin
theme : \"$theme\",
schema: \"html5\",
selector: \"textarea.mce_editable\",
// Cleanup/Output
inline_styles : true,
gecko_spellcheck : true,
entity_encoding : \"$entity_encoding\",

$script .= "
valid_elements : \"$valid_elements\",
extended_valid_elements : \"$elements\",
$forcenewline
$smallButtons
invalid_elements : \"$invalid_elements\",
// Plugins
plugins : \"table link image code hr charmap autolink lists importcss $dragDropPlg\",
// Toolbar
toolbar1: \"$toolbar1 | $toolbar5 | code\",
removed_menuitems: \"newdocument\",
// URL
relative_urls : $relative_urls,
remove_script_host : false,
document_base_url : \"" . JUri::root() . "\",
// Layout
$content_css
importcss_append: true,
// Advanced Options
$resizing
height : \"$html_height\",
width : \"$html_width\",
setup: function (editor) {
$tinyBtns
},
paste_data_images: $allowImgPaste
width : \"$html_width\"
});
"
);
";
break;

case 2: /* Extended mode*/
JFactory::getDocument()->addScriptDeclaration(
"
tinyMCE.init({
// General
directionality: \"$text_direction\",
language : \"$langPrefix\",
mode : \"specific_textareas\",
autosave_restore_when_empty: false,
$skin
theme : \"$theme\",
schema: \"html5\",
selector: \"textarea.mce_editable\",
// Cleanup/Output
inline_styles : true,
gecko_spellcheck : true,
entity_encoding : \"$entity_encoding\",
$script .= "
valid_elements : \"$valid_elements\",
extended_valid_elements : \"$elements\",
$forcenewline
$smallButtons
invalid_elements : \"$invalid_elements\",
// Plugins
plugins : \"$plugins $dragDropPlg\",
// Toolbar
toolbar1: \"$toolbar1 | code\",
removed_menuitems: \"newdocument\",
// URL
relative_urls : $relative_urls,
remove_script_host : false,
document_base_url : \"" . JUri::root() . "\",
rel_list : [
{title: 'Alternate', value: 'alternate'},
{title: 'Author', value: 'author'},
Expand All @@ -845,35 +818,50 @@ public function onInit()
//Templates
" . $templates . "
// Layout
$content_css
importcss_append: true,
// Advanced Options
$resizing
image_advtab: $image_advtab,
height : \"$html_height\",
width : \"$html_width\",
setup: function (editor) {
$tinyBtns
},
paste_data_images: $allowImgPaste
});
"
);
";
break;
}

$script .= "
function jInsertEditorText( text, editor )
{
tinyMCE.activeEditor.execCommand('mceInsertContent', false, text);
}
";

if (!empty($btnsNames))
{
JFactory::getDocument()->addScriptDeclaration(
"
function jInsertEditorText( text, editor )
"
function jModalClose() {
tinyMCE.activeEditor.windowManager.close();
}
var SqueezeBox;
if (SqueezeBox != undefined)
{
tinyMCE.activeEditor.execCommand('mceInsertContent', false, text);
var otherStr = 'SqueezeBox.close', otherCallback;
otherCallback = new Function(otherStr);
otherCallback.call(SqueezeBox.close);
} else {
var SqueezeBox = {};
SqueezeBox.close = function(){
tinyMCE.activeEditor.windowManager.close();
}
}
"
);
}

JFactory::getDocument()->addScriptDeclaration($script);
JFactory::getDocument()->addStyleDeclaration(".mce-in { padding: 5px 10px !important;}");

return;
}

Expand Down Expand Up @@ -1030,17 +1018,27 @@ private function tinyButtons()
// We do some hack here to set the correct icon for 3PD buttons
$icon = 'none icon-' . $icon;

// Now we can built the script
$tempConstructor = '
!(function(){';

// Get the modal width/height
if ($options)
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;';

}
else
{
preg_match('/x:\s*+\d{2,4}/', $options, $modalWidth);
preg_match('/y:\s*+\d{2,4}/', $options, $modalHeight);
$modalWidth = filter_var(implode("", $modalWidth), FILTER_SANITIZE_NUMBER_INT);
$modalHeight = filter_var(implode("", $modalHeight), FILTER_SANITIZE_NUMBER_INT);
$tempConstructor .= '
var btnOptions = {}, modalWidth = null, modalHeight = null;';
}

// Now we can built the script
$tempConstructor = "
$tempConstructor .= "
editor.addButton(\"" . $name . "\", {
text: \"" . $title . "\",
title: \"" . $title . "\",
Expand All @@ -1049,21 +1047,21 @@ private function tinyButtons()
if ($button->get('modal') || $href)
{
$tempConstructor .= "
editor.windowManager.open({
var modalOptions = {
title : \"" . $title . "\",
url : '" . $href . "',";
if (!empty($modalHeight) && !empty($modalWidth))
{
$tempConstructor .= "
width : $modalWidth,
height : $modalHeight,";
}
$tempConstructor .= "
url : '" . $href . "',
buttons: [{
text : \"Close\",
onclick: \"close\"
}]
});";
}
if(modalWidth){
modalOptions.width = modalWidth;
}
if(modalHeight){
modalOptions.height = modalHeight;
}
editor.windowManager.open(modalOptions);";
if ($onclick && ($button->get('modal') || $href))
{
$tempConstructor .= "\r\n
Expand All @@ -1079,7 +1077,8 @@ private function tinyButtons()
}
$tempConstructor .= "
}
})";
});
})();";

// The array with the toolbar buttons
$btnsNames[] = $name;
Expand All @@ -1090,8 +1089,8 @@ private function tinyButtons()
}

return array(
'names' => $btnsNames,
'script' => $tinyBtns
'names' => $btnsNames,
'script' => $tinyBtns
);
}
}