PageSourceSearch

https://9c.pl/modules/montonio/views/js/sdk/montonio-load-queue.js

js 9c.pl collected 2026-10-05 23:19:08 UTC 5,945 bytes, 190 lines download raw bytes

1// Define the global queue array if it doesn't already exist
2window.montonioLoadQueue = window.montonioLoadQueue || [];
3
4// Define the subscriber function that will consume the queue
5function MontonioLoadQueueSubscriber() {
6    var queue = window.montonioLoadQueue;
7    var running = false;
8    var stop = false;
9    var autoRun = false;
10
11    // Clear the queue
12    this.clear = function () {
13        queue.length = 0;
14    };
15
16    // Get the queue
17    this.contents = function () {
18        return queue;
19    };
20
21    // Set the queue
22    this.setQueue = function (val) {
23        queue.length = 0;
24        Array.prototype.push.apply(queue, val);
25    };
26
27    // Run the next item in the queue
28    this.next = function () {
29        running = true;
30        if (queue.length < 1 || stop) {
31            running = false;
32            return;
33        }
34
35        var nextItem = queue.shift();
36        nextItem();
37        if (queue.length > 0) {
38            this.next();
39        } else {
40            running = false;
41        }
42    };
43
44    // Start consuming the queue if autoRun is true
45    this.init = function (autoRunFlag) {
46        autoRun = autoRunFlag;
47        if (autoRun && !running) {
48            this.next();
49        }
50    };
51
52    // Set autoRun flag
53    this.setAutoRun = function (flag) {
54        autoRun = flag;
55    };
56
57    // Stop or start the queue processing
58    this.setStop = function (flag) {
59        stop = flag;
60    };
61
62    // Automatically start consuming the queue if it has items
63    if (queue.length > 0 && !running && autoRun) {
64        this.next();
65    }
66
67    // Use MutationObserver to detect changes in the queue
68    var observer = new MutationObserver(function (mutations) {
69        if (!running && autoRun && queue.length > 0) {
70            this.next();
71        }
72    }.bind(this));
73
74    observer.observe(document.documentElement, {
75        childList: true,
76        subtree: true,
77        attributes: true
78    });
79
80    // Automatically start consuming the queue if it has items
81    if (queue.length > 0 && !running && autoRun) {
82        this.next();
83    }
84}
85
86// Set window.onMontonioLoaded to the initialization function
87window.onMontonioLoaded = function() {
88    window.montonioLoadQueueSubscriber = new MontonioLoadQueueSubscriber();
89    window.montonioLoadQueueSubscriber.init(true);
90};
91
92function montonioToggleSpinnerOverlay(shouldShow) {
93    if (shouldShow) {
94        var overlay = document.createElement('div');
95        overlay.id = 'montonio-spinner-overlay';
96
97        // Create a spinner
98        var spinner = document.createElement('div');
99        spinner.id = 'montonio-spinner';
100        overlay.appendChild(spinner);
101
102        // Add the overlay to the body
103        document.body.appendChild(overlay);
104    } else {
105        var overlay = document.getElementById('montonio-spinner-overlay');
106        overlay.remove();
107
108        // for supercheckout
109        const superCheckoutProgressBar = document.getElementById('supercheckout_order_progress_bar');
110        if (superCheckoutProgressBar) {
111            superCheckoutProgressBar.style.display = 'none';
112            document.getElementById('submission_progress_overlay').style.display = 'none';
113        }
114
115        resetPlaceOrderButton();
116    }
117}
118
119function resetPlaceOrderButton() {
120    var button = document.querySelector('#payment-confirmation button');
121    button.removeAttribute('disabled');
122    button.classList.remove('disabled');
123
124    // for supercheckout
125    var superCheckputButton = document.querySelector('#supercheckout_confirm_order');
126    if(superCheckputButton) {
127        superCheckputButton.removeAttribute('disabled');
128    }
129}
130
131// Function to add the class to the parent of the montonio input
132function addClassToParentOfMontonioInputs() {
133    var montonioInputs = document.querySelectorAll('input[data-module-name="montonio"]');
134
135    for (var i = 0; i < montonioInputs.length; i++) {
136        if (montonioInputs[i].parentNode) {
137            montonioInputs[i].parentNode.classList.add('montonio-payment-method');
138        }
139    }
140}
141
142// Debounce function to limit how often addClassToParentOfMontonioInputs is called
143function montonioDebounce(func, delay) {
144    var timeout;
145    return function() {
146        var context = this, args = arguments;
147        clearTimeout(timeout);
148        timeout = setTimeout(function() {
149            func.apply(context, args);
150        }, delay);
151    };
152}
153
154// Debounced version of the addClassToParentOfMontonioInputs function
155var debouncedAddClassToParentOfMontonioInputs = montonioDebounce(addClassToParentOfMontonioInputs, 100);
156
157// Create a MutationObserver to watch for any changes in the DOM
158var montonioSupercheckoutObserver = new MutationObserver(function(mutations) {
159    var relevantMutation = false;
160
161    for (var i = 0; i < mutations.length; i++) {
162        var mutation = mutations[i];
163
164        // If nodes are added or attributes changed, we consider it a relevant mutation
165        if (mutation.addedNodes && mutation.addedNodes.length > 0) {
166            relevantMutation = true;
167            break;
168        }
169        if (mutation.type === 'attributes' && mutation.target.tagName === 'INPUT' && mutation.target.getAttribute('data-module-name') === 'montonio') {
170            relevantMutation = true;
171            break;
172        }
173    }
174
175    // Call the debounced function only if there was a relevant mutation
176    if (relevantMutation) {
177        debouncedAddClassToParentOfMontonioInputs();
178    }
179});
180
181document.addEventListener('DOMContentLoaded', function() {
182    // Run the function initially for any existing montonio inputs
183    addClassToParentOfMontonioInputs();
184  
185    // Configuration for the observer (we want to observe the child list and attribute changes)
186    var montonioSupercheckoutObserverConfig = { childList: true, subtree: true, attributes: true };
187    
188    // Start observing the document for changes
189    montonioSupercheckoutObserver.observe(document.body, montonioSupercheckoutObserverConfig);
190});

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.