Skip to content

Commit

Permalink
TinyMCE xtd-button close (again, really) and drop jquery (#12324)
Browse files Browse the repository at this point in the history
* drop jquery, fix jModalClose()

* classList polyfill not needed here

* window.width (seriously?), merge options

* use Joomla.extend()

* my bad

* IE<9
  • Loading branch information
Dimitri Grammatikogianni authored and wilsonge committed Oct 8, 2016
1 parent 97b083e commit 7a29a1a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 46 deletions.
1 change: 0 additions & 1 deletion media/editors/tinymce/js/tinymce-init.min.js

This file was deleted.

11 changes: 6 additions & 5 deletions media/editors/tinymce/plugins/jdragdrop/plugin.js
Expand Up @@ -19,12 +19,13 @@ tinymce.PluginManager.add('jdragdrop', function(editor) {

xhr.upload.onprogress = function(e) {
var percentComplete = (e.loaded / e.total) * 100;
jQuery('.bar').width(percentComplete + '%');
document.querySelector('.bar').style.width = percentComplete + '%';
};

removeProgessBar = function(){
setTimeout(function(){
jQuery('#jloader').remove();
document.querySelector('#jloader').outerHTML = "";
delete document.querySelector('#jloader');
editor.contentAreaContainer.style.borderWidth = '';
}, 200);
};
Expand Down Expand Up @@ -92,13 +93,13 @@ tinymce.PluginManager.add('jdragdrop', function(editor) {
// Only images allowed
if (f.name.toLowerCase().match(/\.(jpg|jpeg|png|gif)$/)) {

// Display a spining Joomla! logo
jQuery('.mce-toolbar-grp').append(
// Display a progress bar
document.querySelector('.mce-toolbar-grp').innerHTML +=
'<div id=\"jloader\">' +
' <div class=\"progress progress-success progress-striped active\" style=\"width:100%;height:30px;\">' +
' <div class=\"bar\" style=\"width: 0%\"></div>' +
' </div>' +
'</div>');
'</div>';
editor.contentAreaContainer.style.borderWidth = '';

// Upload the file(s)
Expand Down
2 changes: 1 addition & 1 deletion media/editors/tinymce/plugins/jdragdrop/plugin.min.js

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

39 changes: 18 additions & 21 deletions media/system/js/tiny-close.js
Expand Up @@ -11,28 +11,25 @@
* @since 3.5.1
* @version 1.0
*/
document.onreadystatechange = function () {
if (document.readyState == "interactive" && typeof tinyMCE != 'undefined' && tinyMCE)
document.addEventListener('DOMContentLoaded', function () {
if (typeof window.jModalClose_no_tinyMCE === 'undefined')
{
if (typeof window.jModalClose_no_tinyMCE === 'undefined')
{
window.jModalClose_no_tinyMCE = typeof(jModalClose) == 'function' ? jModalClose : false;

jModalClose = function () {
if (window.jModalClose_no_tinyMCE) window.jModalClose_no_tinyMCE.apply(this, arguments);
tinyMCE.activeEditor.windowManager.close();
};
}
window.jModalClose_no_tinyMCE = typeof(jModalClose) == 'function' ? jModalClose : false;

if (typeof window.SqueezeBoxClose_no_tinyMCE === 'undefined')
{
if (typeof(SqueezeBox) == 'undefined') SqueezeBox = {};
window.SqueezeBoxClose_no_tinyMCE = typeof(SqueezeBox.close) == 'function' ? SqueezeBox.close : false;
jModalClose = function () {
if (window.jModalClose_no_tinyMCE) window.jModalClose_no_tinyMCE.apply(this, arguments);
tinyMCE.activeEditor.windowManager.close();
};
}

if (typeof window.SqueezeBoxClose_no_tinyMCE === 'undefined')
{
if (typeof(SqueezeBox) == 'undefined') SqueezeBox = {};
window.SqueezeBoxClose_no_tinyMCE = typeof(SqueezeBox.close) == 'function' ? SqueezeBox.close : false;

SqueezeBox.close = function () {
if (window.SqueezeBoxClose_no_tinyMCE) window.SqueezeBoxClose_no_tinyMCE.apply(this, arguments);
tinyMCE.activeEditor.windowManager.close();
};
}
SqueezeBox.close = function () {
if (window.SqueezeBoxClose_no_tinyMCE) window.SqueezeBoxClose_no_tinyMCE.apply(this, arguments);
tinyMCE.activeEditor.windowManager.close();
};
}
};
});
2 changes: 1 addition & 1 deletion media/system/js/tiny-close.min.js

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

Expand Up @@ -3,15 +3,15 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

;(function(tinyMCE, Joomla, $, window, document){
;(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.getSize = window.getSize || function(){return {x: window.innerWidth, y: window.innerHeight};};

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

var JoomlaTinyMCE = {

Expand All @@ -21,12 +21,12 @@
* @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');
$editors = target.querySelectorAll('.joomla-editor-tinymce');

for(var i = 0, l = $editors.length; i < l; i++) {
this.setupEditor($editors[i], pluginOptions);
Expand All @@ -40,15 +40,15 @@
* @param {Object} pluginOptions
*
* @since __DEPLOY_VERSION__
*/
*/
setupEditor: function ( element, pluginOptions ) {
var name = element ? $(element).attr('name').replace(/\[\]|\]/g, '').split('[').pop() : 'default', // Get Editor name
var name = element ? element.getAttribute('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);
options = Joomla.extend({}, options);

if (element) {
// We already have the Target, so reset the selector and assign given element as target
Expand All @@ -68,13 +68,15 @@
Joomla.JoomlaTinyMCE = JoomlaTinyMCE;

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

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

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

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

5 changes: 2 additions & 3 deletions plugins/editors/tinymce/tinymce.php
Expand Up @@ -46,10 +46,9 @@ class PlgEditorTinymce extends JPlugin
*/
public function onInit()
{
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', $this->_basePath . '/tinymce.min.js', false, false, false, false, false);
JHtml::_('script', 'editors/tinymce/tinymce-init.min.js', false, true);

return;
JHtml::_('script', 'system/tinymce-init.min.js', false, true);
}

/**
Expand Down

0 comments on commit 7a29a1a

Please sign in to comment.