Skip to content

Commit

Permalink
DRY please
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko committed Nov 16, 2015
1 parent a7026fc commit d8aad68
Showing 1 changed file with 46 additions and 87 deletions.
133 changes: 46 additions & 87 deletions plugins/editors/tinymce/tinymce.php
Expand Up @@ -707,13 +707,12 @@ public function onInit()
$mode = 0;
}

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

// General
$script .= "
directionality: \"$text_direction\",
selector: \"textarea.mce_editable\",
language : \"$langPrefix\",
Expand All @@ -722,111 +721,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,34 +811,18 @@ 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;
}

if (!empty($btnsNames))
{
JFactory::getDocument()->addScriptDeclaration(
"
function jInsertEditorText( text, editor )
{
tinyMCE.activeEditor.execCommand('mceInsertContent', false, text);
}
"
);
}
JFactory::getDocument()->addScriptDeclaration($script);

return;
}
Expand All @@ -886,7 +836,7 @@ function jInsertEditorText( text, editor )
*/
public function onGetContent($editor)
{
return 'tinyMCE.activeEditor.getContent();';
return 'tinyMCE.getElementById("' . $editor . '").getContent();';
}

/**
Expand All @@ -899,7 +849,7 @@ public function onGetContent($editor)
*/
public function onSetContent($editor, $html)
{
return 'tinyMCE.activeEditor.setContent(' . $html . ');';
return 'tinyMCE.getElementById("' . $editor .'").setContent(' . $html . ');';
}

/**
Expand All @@ -925,6 +875,15 @@ public function onSave($editor)
*/
public function onGetInsertMethod($name)
{
JFactory::getDocument()->addScriptDeclaration(
"
function jInsertEditorText( text, editor )
{
tinyMCE.get('" . $name . "').execCommand('mceInsertContent', false, text);
}
"
);

return;
}

Expand Down

0 comments on commit d8aad68

Please sign in to comment.