Skip to content

Commit

Permalink
Improve a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Aug 23, 2016
1 parent 1fb5519 commit 7804f39
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
85 changes: 51 additions & 34 deletions media/editors/tinymce/js/tinymce-init.js
Expand Up @@ -13,50 +13,67 @@
tinyMCE.activeEditor.execCommand('mceInsertContent', false, text);
}

/**
* Find all TinyMCE elements and initialize TinyMCE instance for each
*/
Joomla.setupEditorsTinyMCE = Joomla.setupEditorsTinyMCE || function(target){
target = target || document;
var pluginOptions = Joomla.optionsStorage.plg_editor_tinymce || {},
$editors = $(target).find('.joomla-editor-tinymce');

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

/**
* Initialize TinyMCE instance
*/
Joomla.initializeEditorTinyMCE = Joomla.initializeEditorTinyMCE || 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) {
options.selector = null;
options.target = element;
}
/**
* 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

if (options.setupCallbacString && !options.setup) {
options.setup = new Function('editor', options.setupCallbacString);
// 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);
}

tinyMCE.init(options);
}
};

Joomla.JoomlaTinyMCE = JoomlaTinyMCE;

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

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

Expand Down
2 changes: 1 addition & 1 deletion 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.

0 comments on commit 7804f39

Please sign in to comment.