From 3bd4df649370e80cf19bd6aa1c362297e1875b54 Mon Sep 17 00:00:00 2001 From: dGrammatiko Date: Thu, 31 Jan 2019 13:51:52 +0100 Subject: [PATCH] [4.0] Housekeeping (#23600) --- build/media/legacy/js/bootstrap-init.js | 29 ++++- build/media_src/mod_menu/js/admin-menu.es6.js | 16 +++ build/media_src/system/js/core.es6.js | 112 +++--------------- build/media_src/system/js/searchtools.es6.js | 45 ++++++- 4 files changed, 103 insertions(+), 99 deletions(-) diff --git a/build/media/legacy/js/bootstrap-init.js b/build/media/legacy/js/bootstrap-init.js index 1ad13fbd4164a..2369ef877624a 100644 --- a/build/media/legacy/js/bootstrap-init.js +++ b/build/media/legacy/js/bootstrap-init.js @@ -1,7 +1,32 @@ +Joomla = window.Joomla || {}; -;(function() { +(function(Joomla) { "use strict"; + /** + * Method to invoke a click on button inside an iframe + * + * @param {object} options Object with the css selector for the parent element of an iframe + * and the selector of the button in the iframe that will be clicked + * { iframeSelector: '', buttonSelector: '' } + * @returns {boolean} + * + * @since 4.0 + */ + Joomla.iframeButtonClick = function(options) { + if (!options.iframeSelector || !options.buttonSelector) { + throw new Error('Selector is missing'); + } + + var iframe = document.querySelector(options.iframeSelector + ' iframe'); + if (iframe) { + var button = iframe.contentWindow.document.querySelector(options.buttonSelector); + if (button) { + button.click(); + } + } + }; + jQuery(document).ready(function($) { // Initialize some variables @@ -186,4 +211,4 @@ }); } }); -})(); \ No newline at end of file +})(Joomla); diff --git a/build/media_src/mod_menu/js/admin-menu.es6.js b/build/media_src/mod_menu/js/admin-menu.es6.js index c92adfe819a49..f81941c0ad120 100644 --- a/build/media_src/mod_menu/js/admin-menu.es6.js +++ b/build/media_src/mod_menu/js/admin-menu.es6.js @@ -5,6 +5,22 @@ ((Joomla, document) => { 'use strict'; + /** + * Check if HTML5 localStorage enabled on the browser + * + * @since 4.0.0 + */ + Joomla.localStorageEnabled = () => { + const test = 'joomla-cms'; + try { + localStorage.setItem(test, test); + localStorage.removeItem(test); + return true; + } catch (e) { + return false; + } + }; + // eslint-disable-next-line no-new new window.MetisMenu('#menu'); diff --git a/build/media_src/system/js/core.es6.js b/build/media_src/system/js/core.es6.js index cce34636699af..cea404d47f96a 100644 --- a/build/media_src/system/js/core.es6.js +++ b/build/media_src/system/js/core.es6.js @@ -4,8 +4,10 @@ */ // eslint-disable max-len -// Patch Custom Events -// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent +/** + * Patch Custom Events + * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent + */ (() => { if (typeof window.CustomEvent === 'function') { return false; @@ -193,8 +195,8 @@ window.Joomla.Modal = window.Joomla.Modal || { * * @type {{}} * - * Allows you to call Joomla.JText._() to get a translated JavaScript string - * pushed in with JText::script() in Joomla. + * Allows you to call Joomla.Text._() to get a translated JavaScript string + * pushed in with Text::script() in Joomla. */ Joomla.Text = { strings: {}, @@ -226,10 +228,10 @@ window.Joomla.Modal = window.Joomla.Modal || { }, /** - * Load new strings in to Joomla.JText + * Load new strings in to Joomla.Text * * @param {Object} object Object with new strings - * @returns {Joomla.JText} + * @returns {Joomla.Text} */ load: (object) => { [].slice.call(Object.keys(object)).forEach((key) => { @@ -473,13 +475,13 @@ window.Joomla.Modal = window.Joomla.Modal || { } // Title - title = Joomla.JText._(type); + title = Joomla.Text._(type); // Skip titles with untranslated strings if (typeof title !== 'undefined') { titleWrapper = document.createElement('h4'); titleWrapper.className = 'alert-heading'; - titleWrapper.innerHTML = Joomla.JText._(type) ? Joomla.JText._(type) : type; + titleWrapper.innerHTML = Joomla.Text._(type) ? Joomla.Text._(type) : type; messagesBox.appendChild(titleWrapper); } @@ -502,7 +504,6 @@ window.Joomla.Modal = window.Joomla.Modal || { }); }; - /** * Remove messages * @@ -571,20 +572,20 @@ window.Joomla.Modal = window.Joomla.Modal || { encodedJson = buf.join(''); - msg.error = [Joomla.JText._('JLIB_JS_AJAX_ERROR_PARSE').replace('%s', encodedJson)]; + msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_PARSE').replace('%s', encodedJson)]; } else if (textStatus === 'nocontent') { - msg.error = [Joomla.JText._('JLIB_JS_AJAX_ERROR_NO_CONTENT')]; + msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_NO_CONTENT')]; } else if (textStatus === 'timeout') { - msg.error = [Joomla.JText._('JLIB_JS_AJAX_ERROR_TIMEOUT')]; + msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_TIMEOUT')]; } else if (textStatus === 'abort') { - msg.error = [Joomla.JText._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT')]; + msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT')]; } else if (xhr.responseJSON && xhr.responseJSON.message) { // For vanilla XHR - msg.error = [`${Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} ${xhr.responseJSON.message}`]; + msg.error = [`${Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} ${xhr.responseJSON.message}`]; } else if (xhr.statusText) { - msg.error = [`${Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} ${xhr.statusText}`]; + msg.error = [`${Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} ${xhr.statusText}`]; } else { - msg.error = [Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)]; + msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)]; } return msg; @@ -909,22 +910,6 @@ window.Joomla.Modal = window.Joomla.Modal || { return xhr; }; - /** - * Check if HTML5 localStorage enabled on the browser - * - * @since 4.0.0 - */ - Joomla.localStorageEnabled = () => { - const test = 'joomla-cms'; - try { - localStorage.setItem(test, test); - localStorage.removeItem(test); - return true; - } catch (e) { - return false; - } - }; - /** * Loads any needed polyfill for web components and async load any web components * @@ -1139,69 +1124,6 @@ window.Joomla.Modal = window.Joomla.Modal || { } } }; - - /** - * Method that resets the filter inputs and submits the relative form - * - * @param {HTMLElement} The element that initiates the call - * @returns {void} - * @since 4.0 - */ - Joomla.resetFilters = (element) => { - const { form } = element; - - if (!form) { - throw new Error('Element must be inside a form!'); - } - - const elementsArray = [].slice.call(form.elements); - - if (elementsArray.length) { - const newElementsArray = []; - elementsArray.forEach((elem) => { - // Skip the token, the task, the boxchecked and the calling element - if (elem.getAttribute('name') === 'task' - || elem.getAttribute('name') === 'boxchecked' - || (elem.value === '1' && /^[0-9A-F]{32}$/i.test(elem.name)) - || elem === element) { - return; - } - - newElementsArray.push(elem); - }); - - // Reset all filters - newElementsArray.forEach((elem) => { - elem.value = ''; - }); - - form.submit(); - } - }; - - /* - * Method to invoke a click on button inside an iframe - * - * @param {object} options Object with the css selector for the parent element of an iframe - * and the selector of the button in the iframe that will be clicked - * @returns {boolean} - * @since 4.0 - */ - Joomla.iframeButtonClick = (options = { iframeSelector: '', buttonSelector: '' }) => { - if (!options.iframeSelector || !options.buttonSelector) { - throw new Error('Selector is missing'); - } - - const iframe = document.querySelector(`${options.iframeSelector} > iframe`); - if (iframe) { - const button = iframe.contentWindow.document.querySelector(options.buttonSelector); - if (button) { - button.click(); - } - } - - return false; - }; })(Joomla, document); /** diff --git a/build/media_src/system/js/searchtools.es6.js b/build/media_src/system/js/searchtools.es6.js index 26bfc21702cbe..72595f57cf1ca 100644 --- a/build/media_src/system/js/searchtools.es6.js +++ b/build/media_src/system/js/searchtools.es6.js @@ -1,6 +1,47 @@ -(() => { +Joomla = window.Joomla || {}; + +((Joomla) => { 'use strict'; + /** + * Method that resets the filter inputs and submits the relative form + * + * @param {HTMLElement} element The element that initiates the call + * @returns {void} + * @since 4.0 + */ + Joomla.resetFilters = (element) => { + const { form } = element; + + if (!form) { + throw new Error('Element must be inside a form!'); + } + + const elementsArray = [].slice.call(form.elements); + + if (elementsArray.length) { + const newElementsArray = []; + elementsArray.forEach((elem) => { + // Skip the token, the task, the boxchecked and the calling element + if (elem.getAttribute('name') === 'task' + || elem.getAttribute('name') === 'boxchecked' + || (elem.value === '1' && /^[0-9A-F]{32}$/i.test(elem.name)) + || elem === element) { + return; + } + + newElementsArray.push(elem); + }); + + // Reset all filters + newElementsArray.forEach((elem) => { + elem.value = ''; + }); + + form.submit(); + } + }; + class Searchtools { constructor(elem, options) { const defaults = { @@ -486,4 +527,4 @@ // Execute on DOM Loaded Event document.addEventListener('DOMContentLoaded', onBoot); -})(); +})(Joomla);