- md5
- ff22f1260c84164761f4fd348e7f5c00
- sha1
- 50b6aa73003958ba594e53a82e6346425f5a5049
- sha256
- b2a2a7bee9cf765278869266a962ae979552ac3c3dbd0fd8fc22cbe710f21442
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
/**
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Joomla! Message related functions
*
* @since 4.0.0
*/
((window, Joomla) => {
'use strict';
/**
* Render messages send via JSON
* Used by some javascripts such as validate.js
*
* @param {object} messages JavaScript object containing the messages to render.
* Example:
* const messages = {
* "message": ["This will be a green message", "So will this"],
* "error": ["This will be a red message", "So will this"],
* "info": ["This will be a blue message", "So will this"],
* "notice": ["This will be same as info message", "So will this"],
* "warning": ["This will be a orange message", "So will this"],
* "my_custom_type": ["This will be same as info message", "So will this"]
* };
* @param {string} selector The selector of the container where the message will be rendered
* @param {bool} keepOld If we shall discard old messages
* @param {int} timeout The milliseconds before the message self destruct
* @return void
*/
Joomla.renderMessages = (messages, selector, keepOld, timeout) => {
let messageContainer;
let typeMessages;
let messagesBox;
let title;
let titleWrapper;
let messageWrapper;
let alertClass;
if (typeof selector === 'undefined' || (selector && selector === '#system-message-container')) {
messageContainer = document.getElementById('system-message-container');
} else {
messageContainer = document.querySelector(selector);
}
if (typeof keepOld === 'undefined' || (keepOld && keepOld === false)) {
Joomla.removeMessages(messageContainer);
}
[].slice.call(Object.keys(messages)).forEach((type) => {
// Array of messages of this type
typeMessages = messages[type];
messagesBox = document.createElement('joomla-alert');
if (['notice', 'message', 'error', 'warning'].indexOf(type) > -1) {
alertClass = (type === 'notice') ? 'info' : type;
alertClass = (type === 'message') ? 'success' : alertClass;
alertClass = (type === 'error') ? 'danger' : alertClass;
alertClass = (type === 'warning') ? 'warning' : alertClass;
} else {
alertClass = 'info';
}
messagesBox.setAttribute('type', alertClass);
messagesBox.setAttribute('dismiss', 'true');
if (timeout && parseInt(timeout, 10) > 0) {
messagesBox.setAttribute('autodismiss', timeout);
}
// Title
title = Joomla.Text._(type);
// Skip titles with untranslated strings
if (typeof title !== 'undefined') {
titleWrapper = document.createElement('div');
titleWrapper.className = 'alert-heading';
titleWrapper.innerHTML = `<span class="${type}"></span><span class="sr-only">${Joomla.Text._(type) ? Joomla.Text._(type) : type}</span>`;
messagesBox.appendChild(titleWrapper);
}
// Add messages to the message box
messageWrapper = document.createElement('div');
messageWrapper.className = 'alert-wrapper';
typeMessages.forEach((typeMessage) => {
messageWrapper.innerHTML += `<div class="alert-message">${typeMessage}</div>`;
});
messagesBox.appendChild(messageWrapper);
messageContainer.appendChild(messagesBox);
});
};
/**
* Remove messages
*
* @param {element} container The element of the container of the message
* to be removed
*
* @return {void}
*/
Joomla.removeMessages = (container) => {
let messageContainer;
if (container) {
messageContainer = container;
} else {
messageContainer = document.getElementById('system-message-container');
}
const alerts = [].slice.call(messageContainer.querySelectorAll('joomla-alert'));
if (alerts.length) {
alerts.forEach((alert) => {
alert.close();
});
}
};
/**
* Treat AJAX errors.
* Used by some javascripts such as sendtestmail.js and permissions.js
*
* @param {object} xhr XHR object.
* @param {string} textStatus Type of error that occurred.
* @param {string} error Textual portion of the HTTP status.
*
* @return {object} JavaScript object containing the system error message.
*
* @since 3.6.0
*/
Joomla.ajaxErrorsMessages = (xhr, textStatus) => {
const msg = {};
if (textStatus === 'parsererror') {
// For jQuery jqXHR
const buf = [];
// Html entity encode.
let encodedJson = xhr.responseText.trim();
// eslint-disable-next-line no-plusplus
for (let i = encodedJson.length - 1; i >= 0; i--) {
buf.unshift(['&#', encodedJson[i].charCodeAt(), ';'].join(''));
}
encodedJson = buf.join('');
msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_PARSE').replace('%s', encodedJson)];
} else if (textStatus === 'nocontent') {
msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_NO_CONTENT')];
} else if (textStatus === 'timeout') {
msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_TIMEOUT')];
} else if (textStatus === 'abort') {
msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT')];
} else if (xhr.responseJSON && xhr.responseJSON.message) {
// For vanilla XHR
msg.error = [`${Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} <em>${xhr.responseJSON.message}</em>`];
} else if (xhr.statusText) {
msg.error = [`${Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)} <em>${xhr.statusText}</em>`];
} else {
msg.error = [Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)];
}
return msg;
};
})(window, Joomla);
No other release has this exact content. See every version of this file.