grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026/** * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ ;(function($) { "use strict"; /** * Fake TinyMCE object to allow to use TinyMCE translation for the button labels * * @since 3.7.0 */ window.tinymce = { langCode: 'en', langStrings: {}, addI18n: function (code, strings){ this.langCode = code; this.langStrings = strings || {}; }, translate: function (string){ return this.langStrings[string] ? this.langStrings[string] : string; } }; /** * Joomla TinyMCE Builder * * @param {HTMLElement} container * @param {Object} options * @constructor * * @since 3.7.0 */ var JoomlaTinyMCEBuilder = function(container, options) { this.$container = $(container); this.options = options; // Find source containers this.$sourceMenu = this.$container.find('.timymce-builder-menu.source'); this.$sourceToolbar = this.$container.find('.timymce-builder-toolbar.source'); // Find target containers this.$targetMenu = this.$container.find('.timymce-builder-menu.target'); this.$targetToolbar = this.$container.find('.timymce-builder-toolbar.target'); // Render Source elements this.$sourceMenu.each(function(i, element){ this.renderBar(element, 'menu'); }.bind(this)); this.$sourceToolbar.each(function(i, element){ this.renderBar(element, 'toolbar'); }.bind(this)); // Render Target elements this.$targetMenu.each(function(i, element){ this.renderBar(element, 'menu', null, true); }.bind(this)); this.$targetToolbar.each(function(i, element){ this.renderBar(element, 'toolbar', null, true); }.bind(this)); // Set up "drag&drop" stuff var $copyHelper = null, removeIntent = false, self = this; this.$sourceMenu.sortable({ connectWith: this.$targetMenu, items: '.mce-btn', cancel: '', placeholder: 'mce-btn ui-state-highlight', start: function(event, ui) { self.$targetMenu.addClass('drop-area-highlight'); }, helper: function(event, el) { $copyHelper = el.clone().insertAfter(el); return el; }, stop: function() { $copyHelper && $copyHelper.remove(); self.$targetMenu.removeClass('drop-area-highlight'); } }); this.$sourceToolbar.sortable({ connectWith: this.$targetToolbar, items: '.mce-btn', cancel: '', placeholder: 'mce-btn ui-state-highlight', start: function(event, ui) { self.$targetToolbar.addClass('drop-area-highlight'); }, helper: function(event, el) { $copyHelper = el.clone().insertAfter(el); return el; }, stop: function() { $copyHelper && $copyHelper.remove(); self.$targetToolbar.removeClass('drop-area-highlight'); } }); $().add(this.$targetMenu).add(this.$targetToolbar).sortable({ items: '.mce-btn', cancel: '', placeholder: 'mce-btn ui-state-highlight', receive: function(event, ui) { $copyHelper = null; var $el = ui.item, $cont = $(this); self.appendInput($el, $cont.data('group'), $cont.data('set')) }, over: function (event, ui) { removeIntent = false; }, out: function (event, ui) { removeIntent = true; }, beforeStop: function (event, ui) { if(removeIntent){ ui.item.remove(); } } }); // Bind actions buttons this.$container.on('click', '.button-action', function(event){ var $btn = $(event.target), action = $btn.data('action'), options = $btn.data(); if (this[action]) { this[action].call(this, options); } else { throw new Error('Unsupported action ' + action); } }.bind(this)); }; /** * Render the toolbar/menubar * * @param {HTMLElement} container The toolbar container * @param {String} type The type toolbar or menu * @param {Array|null} value The value * @param {Boolean} withInput Whether append input * * @since 3.7.0 */ JoomlaTinyMCEBuilder.prototype.renderBar = function(container, type, value, withInput) { var $container = $(container), group = $container.data('group'), set = $container.data('set'), items = type === 'menu' ? this.options.menus : this.options.buttons, value = value ? value : ($container.data('value') || []), item, name, $btn; for ( var i = 0, l = value.length; i < l; i++ ) { name = value[i]; item = items[name]; if (!item) { continue; } $btn = this.createButton(name, item, type); $container.append($btn); // Enable tooltip if ($btn.tooltip) { $btn.tooltip({trigger: 'hover'}); } // Add input if (withInput) { this.appendInput($btn, group, set); } } }; /** * Create the element needed for renderBar() * @param {String} name * @param {Object} info * @param {String} type * * @return {jQuery} * * @since 3.7.0 */ JoomlaTinyMCEBuilder.prototype.createButton = function(name, info, type){ var $element = $('
', { 'class': 'mce-btn', 'data-name': name, 'data-toggle': 'tooltip', 'title': tinymce.translate(info.label) }); var $btn = $('