PageSourceSearch

https://rabbiefremgoldberg.org/userfiles/modules/microweber/api/shop.js

js rabbiefremgoldberg.org collected 2026-10-02 04:15:15 UTC 9,521 bytes, 361 lines download raw bytes

1// JavaScript Document
2mw.require('forms.js');
3
4
5mw.cart = {
6
7    add_and_checkout: function (content_id, price, c) {
8        if (typeof(c) == 'undefined') {
9            var c = function () {
10                window.location.href = mw.settings.api_url + 'shop/redirect_to_checkout';
11            }
12        }
13        return mw.cart.add_item(content_id, price, c);
14    },
15
16    add_item: function (content_id, price, c) {
17        var data = {};
18        if (content_id == undefined) {
19            return;
20        }
21
22        data.content_id = content_id;
23
24        if (price != undefined && data != undefined) {
25            data.price = price;
26        }
27
28        $.post(mw.settings.api_url + 'update_cart', data,
29            function (data) {
30
31                mw.cart.after_modify(data);
32
33
34                if (typeof c === 'function') {
35                    c.call(data);
36                }
37                mw.trigger('mw.cart.add', [data]);
38            });
39    },
40
41    add: function (selector, price, c) {
42        var data = mw.form.serialize(selector);
43
44
45        var is_form_valid = true;
46        mw.$('[required],.required', selector).each(function () {
47
48            if (!this.validity.valid) {
49                is_form_valid = false
50
51                var is_form_valid_check_all_fields_tip = mw.tooltip({
52                    id: 'mw-cart-add-invalid-form-tooltip-show',
53                    content: 'This field is required',
54                    close_on_click_outside: true,
55                    group: 'mw-cart-add-invalid-tooltip',
56                    skin: 'warning',
57                    element: this
58                });
59
60
61                return false;
62            }
63        });
64
65        if (!is_form_valid) {
66            return;
67        }
68
69
70        if (price != undefined && data != undefined) {
71            data.price = price;
72        }
73        if (data.price == null) {
74            data.price = 0;
75        }
76        $.post(mw.settings.api_url + 'update_cart', data,
77            function (data) {
78
79                mw.cart.after_modify(data);
80
81                if (typeof c === 'function') {
82                    c.call(data);
83                }
84
85                mw.trigger('mw.cart.add', [data]);
86            });
87    },
88
89    remove: function ($id) {
90        var data = {}
91        data.id = $id;
92        $.post(mw.settings.api_url + 'remove_cart_item', data,
93            function (data) {
94                var parent = mw.$('.mw-cart-item-' + $id).parent();
95                mw.$('.mw-cart-item-' + $id).fadeOut(function () {
96                    mw.$(this).remove();
97                    if (parent.find(".mw-cart-item").length == 0) {
98
99                    }
100                });
101                mw.cart.after_modify();
102                mw.trigger('mw.cart.remove', [data]);
103            });
104    },
105
106
107    qty: function ($id, $qty) {
108        var data = {}
109        data.id = $id;
110        data.qty = $qty;
111        $.post(mw.settings.api_url + 'update_cart_item_qty', data,
112            function (data) {
113                mw.cart.after_modify(data);
114                mw.trigger('mw.cart.qty', [data]);
115            });
116
117    },
118
119    after_modify: function (data) {
120
121
122
123        mw.reload_module('shop/cart');
124        mw.reload_module('shop/shipping');
125        mw.reload_module('shop/payments');
126
127
128
129        if((typeof data == 'object') && typeof data.cart_items_quantity !== 'undefined'){
130            $('.js-shopping-cart-quantity').html(data.cart_items_quantity);
131        }
132
133
134        mw.trigger('mw.cart.after_modify', data);
135
136
137
138
139
140    },
141
142    checkout: function (selector, callback) {
143        var form = mw.$(selector);
144
145
146        var state = form.dataset("loading");
147        if (state == 'true') return false;
148        form.dataset("loading", 'true');
149        form.find('.mw-checkout-btn').attr('disabled', 'disabled');
150        form.find('.mw-checkout-btn').hide();
151        var obj = mw.form.serialize(selector);
152        $.ajax({
153            type: "POST",
154            url: mw.settings.api_url + 'checkout',
155            data: obj
156        })
157            .done(function (data) {
158                mw.trigger('checkoutDone', data);
159
160
161                var data2 = data;
162
163                if (data != undefined) {
164                    mw.$(selector + ' .mw-cart-data-btn').removeAttr('disabled');
165                    mw.$('[data-type="shop/cart"]').removeAttr('hide-cart');
166
167
168                    if (typeof(data2.error) != 'undefined') {
169                        mw.$(selector + ' .mw-cart-data-holder').show();
170                        mw.response(selector, data2);
171                    } else if (typeof(data2.success) != 'undefined') {
172
173
174                        if (typeof callback === 'function') {
175                            callback.call(data2.success);
176
177                        } else if (typeof window[callback] === 'function') {
178                            window[callback](selector, data2.success);
179                        } else {
180
181                            mw.$('[data-type="shop/cart"]').attr('hide-cart', 'completed');
182                            mw.reload_module('shop/cart');
183                            mw.$(selector + ' .mw-cart-data-holder').hide();
184                            mw.response(selector, data2);
185                        }
186
187
188                        mw.trigger('mw.cart.checkout.success', data2);
189
190
191                        if (typeof(data2.redirect) != 'undefined') {
192
193                            setTimeout(function () {
194                                window.location.href = data2.redirect;
195                            }, 10)
196
197                        }
198
199
200                    } else if (parseInt(data) > 0) {
201                        mw.$('[data-type="shop/checkout"]').attr('view', 'completed');
202                        mw.reload_module('shop/checkout');
203                    } else {
204                        if (obj.payment_gw != undefined) {
205                            var callback_func = obj.payment_gw + '_checkout';
206                            if (typeof window[callback_func] === 'function') {
207                                window[callback_func](data, selector);
208                            }
209                            var callback_func = 'checkout_callback';
210                            if (typeof window[callback_func] === 'function') {
211                                window[callback_func](data, selector);
212                            }
213                        }
214                    }
215
216                }
217                form.dataset("loading", 'false');
218                form.find('.mw-checkout-btn').removeAttr('disabled');
219                form.find('.mw-checkout-btn').show();
220                mw.trigger('mw.cart.checkout', [data]);
221            });
222    }
223}
224
225
226
227mw.cart.modal = {}
228
229mw.cart.modal.init = function (root_node) {
230
231
232    mw.cart.modal.bindStepButtons(root_node);
233
234
235    var inner_cart_module = $(root_node).find('[parent-module-id="js-ajax-cart-checkout-process"]')[0];
236    var inner_cart_module = $(root_node).find('[id="cart_checkout_js-ajax-cart-checkout-process"]')[0];
237
238    if(inner_cart_module ){
239       // mw.log(inner_cart_module.innerHTML);
240         var check  = $(document).find('[id="'+inner_cart_module.id+'"]').length
241
242
243        //mw.log(check);
244
245        mw.on.moduleReload(inner_cart_module.id, function () {
246            //alert('Module was reloaded')
247        });
248    }
249
250
251
252
253
254
255    //
256    // mw.on('mw.cart.after_modify', function () {
257    //
258    // });
259
260
261    // var inner_cart_module = $(root_node).find('[data-type="shop/cart"]');
262    // if(inner_cart_module.length > 0){
263    //     if(!inner_cart_module.hasClass('cart-modal-module-events-binded')){
264    //         var inner_cart_module_id = inner_cart_module.attr('id')
265    //
266    //         inner_cart_module.addClass('cart-modal-module-events-binded')
267    //
268    //
269    //
270    //         mw.on.moduleReload($('[data-type="shop/cart"]')[0], function () {
271    //             alert('Module was reloaded')
272    //         });
273    //
274    //     }
275    //
276    // }
277
278
279
280}
281
282mw.cart.modal.bindStepButtons = function (root_node) {
283
284    $( root_node).off( "click",'.js-show-step');
285    $( root_node).on( "click",'.js-show-step', function( event ) {
286
287
288
289
290        var has_error = false;
291        var step = mw.$(this).data('step');
292        var holder = mw.tools.firstParentWithClass(this, 'js-step-content');
293
294
295
296
297
298        if (step == 'checkout-complete') {
299            return;
300        }
301
302
303
304
305
306
307        mw.$('input,textarea,select', holder).each(function () {
308            if (!this.checkValidity()) {
309                mw.$(this).addClass('is-invalid');
310                // mw.$(this).addClass('error');
311                has_error = 1;
312            } else {
313                mw.$(this).removeClass('is-invalid');
314                // mw.$(this).removeClass('error');
315            }
316
317        });
318
319
320
321
322
323        if (step == 'payment-method'  || step == 'preview') {
324            if (has_error) {
325                step = 'delivery-address'
326            }
327        }
328
329
330
331
332        mw.$('.js-show-step').removeClass('active');
333
334        mw.$('[data-step]').removeClass('active');
335        mw.$('[data-step="' + step + '"]').addClass('active').parent().removeClass('muted');
336        mw.$(this).addClass('active');
337        step1 = '.js-' + step;
338        mw.$('.js-step-content').hide();
339        mw.$(step1).show();
340
341        if (!has_error) {
342
343        }
344
345        if (has_error) {
346            mw.notification.warning('Please fill the required fields');
347        }
348
349    });
350
351
352/*
353    mw.$('.js-show-step').off('click');
354    mw.$('.js-show-step').on('click', function () {
355
356
357
358    });*/
359
360
361}

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.