mivaecommerce / Elements

Elements is the base developer framework and methodology used for creating our ReadyThemes as well as custom websites.
http://elements.mivareadythemes.com/
MIT License
3 stars 1 forks source link

Internet Explorer 11 lacks support for NodeList.forEach() #11

Closed influxweb closed 6 years ago

influxweb commented 6 years ago

In researching a separate issue posted on the Miva forums, it was discovered there was an issue with Internet Explorer 11 when iterating over a NodeList. To correct this issue, in core/js/scripts.js, replace the site: function () { with the following code:

    site: function () {
        /**
         * Load the `polyfills.js` file and initialise functions.
         * NOTE: This may be removed in future versions of the framework as
         * browser compatibility and support changes.
         */
        if (!window.CSS || !window.CSS.supports('(--foo: red)')) {
            $.loadScript(theme_path + 'core/js/polyfills.js', function () {
                sessionStorage.setItem('outdated', true);
                cssCapabilities.init();
            });
        }

        /**
         * Load the `mini-modal.js` file and initialize functions.
         * This is the default set of modal/light box functionality supplied with the framework.
         */
        $.loadScript(theme_path + 'core/js/mini-modal.js', function () {
            var targets = document.querySelectorAll('[data-mini-modal]');

            for (var i = 0; i < targets.length; i += 1) {
                var modal = minimodal(targets[i], {
                    // If you are using, and have, a Google Maps API Key, enter it here.
                    googleMapsAPIKey: ''
                });

                modal.init();
            }
        });

        /**
         * Although NodeList is not an Array, it is possible to iterate on it using forEach().
         * It can also be converted to an Array using Array.from().
         * However some older browsers have not yet implemented NodeList.forEach() nor Array.from().
         * But those limitations can be circumvented by using Array.prototype.forEach().
         * This polyfill adds compatibility to browsers which do not support NodeList.forEach(). [IE11]
         */
        if (window.NodeList && !NodeList.prototype.forEach) {
            NodeList.prototype.forEach = function (callback, thisArg) {
                thisArg = thisArg || window;
                for (var i = 0; i < this.length; i++) {
                    callback.call(thisArg, this[i], i, this);
                }
            };
        }

    },

This update will be part of the 1.0.2 maintenance release.