1/** 2 * Copyright © Magento, Inc. All rights reserved. 3 * See COPYING.txt for license details. 4 */ 5 6/** 7 * @api 8 */ 9define([ 10 'ko', 11 'jquery', 12 'uiComponent', 13 '../model/messageList', 14 'jquery-ui-modules/effect-blind' 15], function (ko, $, Component, globalMessages) { 16 'use strict'; 17 18 return Component.extend({ 19 defaults: { 20 template: 'Magento_Ui/messages', 21 selector: '[data-role=checkout-messages]', 22 isHidden: false, 23 hideTimeout: 5000, 24 hideSpeed: 500, 25 listens: { 26 isHidden: 'onHiddenChange' 27 } 28 }, 29 30 /** @inheritdoc */ 31 initialize: function (config, messageContainer) { 32 this._super() 33 .initObservable(); 34 35 this.messageContainer = messageContainer || config.messageContainer || globalMessages; 36 this._focusTimeoutId = null; 37 38 if (this.messageContainer && typeof this.messageContainer.getErrorMessages === 'function') { 39 var errorMessages = this.messageContainer.getErrorMessages(); 40 41 if (errorMessages && typeof errorMessages.subscribe === 'function') { 42 errorMessages.subscribe(function (messages) { 43 if (messages && messages.length) { 44 this.focusCheckoutMessages(); 45 } 46 }.bind(this)); 47 } 48 } 49 50 return this; 51 }, 52 53 /** @inheritdoc */ 54 initObservable: function () { 55 this._super() 56 .observe('isHidden'); 57 58 return this; 59 }, 60 61 /** 62 * Checks visibility. 63 * 64 * @return {Boolean} 65 */ 66 isVisible: function () { 67 return this.isHidden(this.messageContainer.hasMessages()); 68 }, 69 70 /** 71 * Remove all messages. 72 */ 73 removeAll: function () { 74 this.messageContainer.clear(); 75 }, 76 77 /** 78 * Move focus to checkout messages when errors are rendered. 79 */ 80 focusCheckoutMessages: function () { 81 var errors = this.messageContainer && typeof this.messageContainer.getErrorMessages === 'function' 82 ? this.messageContainer.getErrorMessages() 83 : []; 84 85 var errorCount = 0; 86 87 if (typeof errors === 'function') { 88 errors = errors(); 89 } 90 91 if (Array.isArray(errors)) { 92 errorCount = errors.length; 93 } 94 95 if (!errorCount) { 96 return; 97 } 98 99 if (this._focusTimeoutId) { 100 clearTimeout(this._focusTimeoutId); 101 } 102 103 this._focusTimeoutId = setTimeout(function () { 104 var $container = $(this.selector).first(); 105 106 if (!$container.length) { 107 return; 108 } 109 110 if (!$container.attr('tabindex')) { 111 $container.attr('tabindex', '-1'); 112 } 113 114 window.scrollTo({ 115 top: 0, 116 left: 0, 117 behavior: 'smooth' 118 }); 119 120 // Delay focus very slightly so scrolling starts first and the 121 // announcement lands on the now-visible message region. 122 setTimeout(function () { 123 $container.trigger('focus'); 124 }, 120); 125 }.bind(this), 0); 126 }, 127 128 /** 129 * @param {Boolean} isHidden 130 */ 131 onHiddenChange: function (isHidden) { 132 // Hide message block if needed 133 if (isHidden) { 134 setTimeout(function () { 135 $(this.selector).hide('slow'); 136 137 //commented because effect-blind.js(1.13.1) is having show & hide issue 138 // $(this.selector).hide('blind', {}, this.hideSpeed); 139 }.bind(this), this.hideTimeout); 140 } 141 } 142 }); 143});
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.