1/** 2 * @file message.js 3 * 4 * JS File for status messages. 5 */ 6(function (Drupal, drupalSettings, once) { 7 8 /** 9 * @Behavior 10 */ 11 Drupal.behaviors.exploreMessageAutoClose = { 12 messagesSelector: '[data-drupal-message-type]', 13 onceName: 'message-autoclose', 14 attach(context) { 15 // Close messages after X seconds. 16 once(this.onceName, context.querySelectorAll(this.messagesSelector), context).forEach(function (message) { 17 const autoCloseDelay = parseInt(drupalSettings.explore.messageAutoClose ?? 4); 18 if (!autoCloseDelay || autoCloseDelay == 0) { 19 return; 20 } 21 const messageType = message.getAttribute('data-drupal-message-type'); 22 const isDismissable = messageType != 'error'; 23 24 // Keep errors on screen for admin users. 25 if (!isDismissable) { 26 return; 27 } 28 29 setTimeout(function() { 30 message.remove(); 31 }, autoCloseDelay * 1000); 32 }); 33 }, 34 detach: function detach(context, settings, trigger) { 35 if (trigger === "unload") { 36 once.remove(this.onceName, context.querySelectorAll(this.messagesSelector)); 37 } 38 }, 39 }; 40 41 /** 42 * Modifies the page title to indicate a form error. 43 * This is done in JS because Drupal errors catching using PHP is not 44 * allways relevant in hook_preprocess_html. 45 * 46 * @Behavior 47 */ 48 Drupal.behaviors.exploreMessageHeadTitle = { 49 messagesSelector: '[data-drupal-message-type="error"]', 50 onceName: 'message-head-title', 51 errorPrefix: `${Drupal.t('Error')} - `, 52 attach(context) { 53 // No need to execute that in AJAX contexts. 54 // Drupal is already adding aria-live=polite to inline messages. 55 if (context !== document) return; 56 57 const [errorElement] = once(this.onceName, context.querySelector(this.messagesSelector)); 58 if (errorElement && !document.title.startsWith(this.errorPrefix)) { 59 document.title = this.errorPrefix + document.title; 60 } 61 }, 62 detach: function detach(context, settings, trigger) { 63 if (trigger === "unload") { 64 once.remove(this.onceName, context.querySelectorAll(this.messagesSelector)); 65 } 66 }, 67 }; 68 69})(Drupal, drupalSettings, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.