Skip to content

Commit

Permalink
tinyMCE use document "scriptoptions", and allow to override tinyMCE J…
Browse files Browse the repository at this point in the history
…avascript parameters (#11157)

* tinymce initialization, use addScriptOptions and tinymce-init.js

* Finalize tinymce-init.js

* Small improve for code duplication

* Allow multiple editors with diferent options

* Setup default options for the editor script only once

* Minified version of tinymce-init

* code style

* Improve a bit
  • Loading branch information
Fedik authored and rdeutz committed Oct 1, 2016
1 parent c2645d5 commit e488ce4
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 225 deletions.
2 changes: 1 addition & 1 deletion layouts/joomla/tinymce/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
cols="<?php echo $data->cols; ?>"
rows="<?php echo $data->rows; ?>"
style="width: <?php echo $data->width; ?>; height: <?php echo $data->height; ?>;"
class="mce_editable"
class="<?php echo empty($data->class) ? 'mce_editable' : $data->class; ?>"
>
<?php echo $data->content; ?>
</textarea>
80 changes: 80 additions & 0 deletions media/editors/tinymce/js/tinymce-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

;(function(tinyMCE, Joomla, $, window, document){
"use strict";

// This line is for Mootools b/c
window.getSize = window.getSize || function(){return {x: $(window).width(), y: $(window).height()};};

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

var JoomlaTinyMCE = {

/**
* Find all TinyMCE elements and initialize TinyMCE instance for each
*
* @param {HTMLElement} target Target Element where to search for the editor element
*
* @since __DEPLOY_VERSION__
*/
setupEditors: function ( target ) {
target = target || document;
var pluginOptions = Joomla.getOptions ? Joomla.getOptions('plg_editor_tinymce', {})
: (Joomla.optionsStorage.plg_editor_tinymce || {}),
$editors = $(target).find('.joomla-editor-tinymce');

for(var i = 0, l = $editors.length; i < l; i++) {
this.setupEditor($editors[i], pluginOptions);
}
},

/**
* Initialize TinyMCE editor instance
*
* @param {HTMLElement} element
* @param {Object} pluginOptions
*
* @since __DEPLOY_VERSION__
*/
setupEditor: function ( element, pluginOptions ) {
var name = element ? $(element).attr('name').replace(/\[\]|\]/g, '').split('[').pop() : 'default', // Get Editor name
tinyMCEOptions = pluginOptions ? pluginOptions.tinyMCE || {} : {},
defaultOptions = tinyMCEOptions['default'] || {},
options = tinyMCEOptions[name] ? tinyMCEOptions[name] : defaultOptions; // Check specific options by the name

// Avoid unexpected changes
options = jQuery.extend({}, options);

if (element) {
// We already have the Target, so reset the selector and assign given element as target
options.selector = null;
options.target = element;
}

if (options.setupCallbacString && !options.setup) {
options.setup = new Function('editor', options.setupCallbacString);
}

tinyMCE.init(options);
}

};

Joomla.JoomlaTinyMCE = JoomlaTinyMCE;

// Init on doomready
$(document).ready(function(){
Joomla.JoomlaTinyMCE.setupEditors();

// Init in subform field
$(document).on('subform-row-add', function(event, row){
Joomla.JoomlaTinyMCE.setupEditors(row);
})
});

}(tinyMCE, Joomla, jQuery, window, document));
1 change: 1 addition & 0 deletions media/editors/tinymce/js/tinymce-init.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e488ce4

Please sign in to comment.