/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/web/mage/loader_old.js
220 строк
6 KB
Alexandra Zota
Merge branch '2.4-develop' of github.com:magento-commerce/magento2ce into ACP2E-4019
23 ноя 2025, 15:58
23 ноя 2025, 15:58
eb82b93
Код
Авторство
О чём код?
/** * Copyright 2014 Adobe * All Rights Reserved. */ define([ 'jquery', 'mage/template', 'jquery-ui-modules/widget', 'mage/translate' ], function ($, mageTemplate) { 'use strict'; $.widget('mage.loader', { loaderStarted: 0, spinner: $(undefined), options: { icon: '', texts: { loaderText: $.mage.__('Please wait...'), imgAlt: $.mage.__('Loading...') }, template: '<div class="loading-mask" data-role="loader">' + '<div class="popup popup-loading">' + '<div class="popup-inner">' + '<% if (data.icon) { %>' + '<img ' + '<% if (data.texts.imgAlt) { %>alt="<%- data.texts.imgAlt %>"<% } %> ' + 'src="<%- data.icon %>"><% } %>' + '<% if (data.texts.loaderText) { %><%- data.texts.loaderText %><% } %>' + '</div>' + '</div>' + '</div>' }, /** * Loader creation * @protected */ _create: function () { this._bind(); }, /** * Bind on ajax events * @protected */ _bind: function () { this._on({ 'processStop': 'hide', 'processStart': 'show', 'show.loader': 'show', 'hide.loader': 'hide', 'contentUpdated.loader': '_contentUpdated' }); }, /** * Verify loader present after content updated * * This will be cleaned up by the task MAGETWO-11070 * * @param {jQuery.Event} e * @private */ _contentUpdated: function (e) { this.show(e); }, /** * Show loader */ show: function (e, ctx) { this._render(); this.loaderStarted++; this.spinner.show(); if (ctx) { this.spinner .css({ width: ctx.outerWidth(), height: ctx.outerHeight(), position: 'absolute' }) .position({ my: 'top left', at: 'top left', of: ctx }); } return false; }, /** * Hide loader */ hide: function () { if (this.loaderStarted > 0) { this.loaderStarted--; if (this.loaderStarted === 0) { this.spinner.hide(); } } return false; }, /** * Render loader * @protected */ _render: function () { var tmpl; if (this.spinner.length === 0) { tmpl = mageTemplate(this.options.template, { data: this.options }); this.spinner = $(tmpl); } this.element.prepend(this.spinner); }, /** * Destroy loader */ _destroy: function () { this.spinner.remove(); } }); /** * This widget takes care of registering the needed loader listeners on the body */ $.widget('mage.loaderAjax', { options: { defaultContainer: '[data-container=body]' }, /** * @private */ _create: function () { this._bind(); // There should only be one instance of this widget, and it should be attached // to the body only. Having it on the page twice will trigger multiple processStarts. if (window.console && !this.element.is(this.options.defaultContainer) && $.mage.isDevMode(undefined)) { console.warn('This widget is intended to be attached to the body, not below.'); } }, /** * @private */ _bind: function () { $(document).on({ 'ajaxSend': this._onAjaxSend.bind(this), 'ajaxComplete': this._onAjaxComplete.bind(this) }); }, /** * @param {Object} loaderContext * @return {*} * @private */ _getJqueryObj: function (loaderContext) { var ctx; // Check to see if context is jQuery object or not. if (loaderContext) { if (loaderContext.jquery) { ctx = loaderContext; } else { ctx = $(loaderContext); } } else { ctx = $('[data-container="body"]'); } return ctx; }, /** * @param {jQuery.Event} e * @param {Object} jqxhr * @param {Object} settings * @private */ _onAjaxSend: function (e, jqxhr, settings) { var ctx; if (settings && settings.showLoader) { ctx = this._getJqueryObj(settings.loaderContext); ctx.trigger('processStart'); } }, /** * @param {jQuery.Event} e * @param {Object} jqxhr * @param {Object} settings * @private */ _onAjaxComplete: function (e, jqxhr, settings) { if (settings && settings.showLoader && !settings.dontHide) { this._getJqueryObj(settings.loaderContext).trigger('processStop'); } } }); return { loader: $.mage.loader, loaderAjax: $.mage.loaderAjax }; });