3

Tried that the messages hide one by one depending on the time of creation so far I have this but it does not work very well in some moments it does not wait for the 15s and in others it erases them all together

I need this for all messages

vendor/magento/module-ui/view/frontend/web/js/view/messages.js

I will do the override is just a test

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */
define([
    'ko',
    'jquery',
    'uiComponent',
    '../model/messageList'
], function (ko, $, Component, globalMessages) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Magento_Ui/messages',
        //    selector: '[data-role=checkout-messages]',
            // isHidden: false,
            // listens: {
            //     isHidden: 'onHiddenChange'
            // }
        },

        /** @inheritdoc */
        initialize: function (config, messageContainer) {
            this._super()
                .initObservable();

            this.messageContainer = messageContainer || config.messageContainer || globalMessages;

            this.initAutoHidden();
            return this;
        },

        // /** @inheritdoc */
        // initObservable: function () {
        //     this._super()
        //         .observe('isHidden');
        //
        //     return this;
        // },

        /**
         * Checks visibility.
         *
         * @return {Boolean}
         */
        isVisible: function () {
            return this.messageContainer.hasMessages();
        },

        /**
         * Remove all messages.
         */
        removeAll: function () {
            this.messageContainer.clear();
        },

        /**
         * init auto hidden all messages
         */
        initAutoHidden: function () {
            setInterval(function () {

                var date = new Date();
                var now = date.getTime();
            //.fixed
                $('div.message:not(.error):visible').each(function () {
                    var message = $(this);
                    if (message.attr('time-created')) {
                        var timeCreated = parseInt(message.attr('time-created'));
                        if (now - timeCreated > 15000) {
                            //message.removeAttr('time-created');
                            message.hide('blind', function() {
                                message.remove();
                            }, 500);

                        }
                    } else {
                        message.attr('time-created', now);
                    }
                });
            }, 1000);
         }
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.