Chris@18: /** Chris@18: * DO NOT EDIT THIS FILE. Chris@18: * See the following change record for more information, Chris@18: * https://www.drupal.org/node/2815083 Chris@18: * @preserve Chris@18: **/ Chris@18: var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); Chris@18: Chris@18: function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } Chris@18: Chris@18: (function (Drupal) { Chris@18: Drupal.Message = function () { Chris@18: function _class() { Chris@18: var messageWrapper = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; Chris@18: Chris@18: _classCallCheck(this, _class); Chris@18: Chris@18: this.messageWrapper = messageWrapper; Chris@18: } Chris@18: Chris@18: _createClass(_class, [{ Chris@18: key: 'add', Chris@18: value: function add(message) { Chris@18: var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; Chris@18: Chris@18: if (!this.messageWrapper) { Chris@18: this.messageWrapper = Drupal.Message.defaultWrapper(); Chris@18: } Chris@18: if (!options.hasOwnProperty('type')) { Chris@18: options.type = 'status'; Chris@18: } Chris@18: Chris@18: if (typeof message !== 'string') { Chris@18: throw new Error('Message must be a string.'); Chris@18: } Chris@18: Chris@18: Drupal.Message.announce(message, options); Chris@18: Chris@18: options.id = options.id ? String(options.id) : options.type + '-' + Math.random().toFixed(15).replace('0.', ''); Chris@18: Chris@18: if (!Drupal.Message.getMessageTypeLabels().hasOwnProperty(options.type)) { Chris@18: throw new Error('The message type, ' + options.type + ', is not present in Drupal.Message.getMessageTypeLabels().'); Chris@18: } Chris@18: Chris@18: this.messageWrapper.appendChild(Drupal.theme('message', { text: message }, options)); Chris@18: Chris@18: return options.id; Chris@18: } Chris@18: }, { Chris@18: key: 'select', Chris@18: value: function select(id) { Chris@18: return this.messageWrapper.querySelector('[data-drupal-message-id^="' + id + '"]'); Chris@18: } Chris@18: }, { Chris@18: key: 'remove', Chris@18: value: function remove(id) { Chris@18: return this.messageWrapper.removeChild(this.select(id)); Chris@18: } Chris@18: }, { Chris@18: key: 'clear', Chris@18: value: function clear() { Chris@18: var _this = this; Chris@18: Chris@18: Array.prototype.forEach.call(this.messageWrapper.querySelectorAll('[data-drupal-message-id]'), function (message) { Chris@18: _this.messageWrapper.removeChild(message); Chris@18: }); Chris@18: } Chris@18: }], [{ Chris@18: key: 'defaultWrapper', Chris@18: value: function defaultWrapper() { Chris@18: var wrapper = document.querySelector('[data-drupal-messages]'); Chris@18: if (!wrapper) { Chris@18: wrapper = document.querySelector('[data-drupal-messages-fallback]'); Chris@18: wrapper.removeAttribute('data-drupal-messages-fallback'); Chris@18: wrapper.setAttribute('data-drupal-messages', ''); Chris@18: wrapper.removeAttribute('class'); Chris@18: } Chris@18: return wrapper.innerHTML === '' ? Drupal.Message.messageInternalWrapper(wrapper) : wrapper.firstElementChild; Chris@18: } Chris@18: }, { Chris@18: key: 'getMessageTypeLabels', Chris@18: value: function getMessageTypeLabels() { Chris@18: return { Chris@18: status: Drupal.t('Status message'), Chris@18: error: Drupal.t('Error message'), Chris@18: warning: Drupal.t('Warning message') Chris@18: }; Chris@18: } Chris@18: }, { Chris@18: key: 'announce', Chris@18: value: function announce(message, options) { Chris@18: if (!options.priority && (options.type === 'warning' || options.type === 'error')) { Chris@18: options.priority = 'assertive'; Chris@18: } Chris@18: Chris@18: if (options.announce !== '') { Chris@18: Drupal.announce(options.announce || message, options.priority); Chris@18: } Chris@18: } Chris@18: }, { Chris@18: key: 'messageInternalWrapper', Chris@18: value: function messageInternalWrapper(messageWrapper) { Chris@18: var innerWrapper = document.createElement('div'); Chris@18: innerWrapper.setAttribute('class', 'messages__wrapper'); Chris@18: messageWrapper.insertAdjacentElement('afterbegin', innerWrapper); Chris@18: return innerWrapper; Chris@18: } Chris@18: }]); Chris@18: Chris@18: return _class; Chris@18: }(); Chris@18: Chris@18: Drupal.theme.message = function (_ref, _ref2) { Chris@18: var text = _ref.text; Chris@18: var type = _ref2.type, Chris@18: id = _ref2.id; Chris@18: Chris@18: var messagesTypes = Drupal.Message.getMessageTypeLabels(); Chris@18: var messageWrapper = document.createElement('div'); Chris@18: Chris@18: messageWrapper.setAttribute('class', 'messages messages--' + type); Chris@18: messageWrapper.setAttribute('role', type === 'error' || type === 'warning' ? 'alert' : 'status'); Chris@18: messageWrapper.setAttribute('data-drupal-message-id', id); Chris@18: messageWrapper.setAttribute('data-drupal-message-type', type); Chris@18: Chris@18: messageWrapper.setAttribute('aria-label', messagesTypes[type]); Chris@18: Chris@18: messageWrapper.innerHTML = '' + text; Chris@18: Chris@18: return messageWrapper; Chris@18: }; Chris@18: })(Drupal);