PageSourceSearch

https://www.scalabad.no/scripts/productlistbuy.js

js scalabad.no collected 2026-10-08 01:16:15 UTC 7,964 bytes, 179 lines download raw bytes

1
2mcWeb.productlistbuy = new (function ($) {
3    'use strict';
4    var obj = this;
5    obj.productlist;
6
7    
8    this.vm = function (product) {
9        obj.productlist = product;
10
11        var self = this;
12        self.service = obj.productlist.service;
13       
14        self.isNordeaFinancingCheckout = false;
15        self.buyAll = function (sender, selector, allowRedirect) {
16
17            var plids = [];
18            var quantitys = [];
19            var all = $(selector);
20
21            var items = 0;
22            for (var i = 0; i < all.length; i++) {
23                var el = all[i];
24                var qua = (parseFloat(el.value));
25                if (qua != isNaN && qua > 0) {
26                    plids.push($(el).data('plid'));
27                    quantitys.push(qua);
28                    $(el).val(0);
29                }
30            }
31
32            if (plids.length < 1)
33                return;
34
35            var data = {
36                Plids: plids,
37                Amount: quantitys,
38                isCheckout: false,
39                sender: 'productlist-buy2016.js - buyAll'
40            };
41
42            action(data, allowRedirect);
43        };
44       
45        self.disableBuyButton= false;
46        self.posInfo = { left: null, top: null };
47
48        self.buyNordea = function (sender, plid, quantity) {
49            self.isNordeaFinancingCheckout = true;
50            self.buy(sender, plid, quantity);
51        }
52
53        self.buy = function (sender, plid, quantity) {
54
55            try {
56
57                if (self.disableBuyButton)
58                    return;                
59
60                self.disableBuyButton = true;
61                self.posInfo.left = Math.round($(sender).offset().left) - $(document).scrollLeft();
62                self.posInfo.top = Math.round($(sender).offset().top) - $(document).scrollTop();
63                setTimeout(function() {
64                        self.disableBuyButton = false;
65                    },
66                    480);
67
68                quantity = String(quantity).replace(',', '.');
69                quantity = (quantity == null) ? 1 : parseFloat(quantity);
70                quantity = (isNaN(quantity) || quantity < 0) ? 1 : quantity;
71
72                if (quantity <= 0)
73                    return;
74
75                var data = {
76                    plid: plid,
77                    isConfig: false,
78                    quantity: quantity,
79                    isCheckout: false,
80                    sender: 'productlist-buy2016.js - buy'
81                };
82
83                action(data);
84
85
86            } catch (e) {
87                alert("Exception: " + e);
88            }
89        };
90
91        var action = function (json, allowRedirect) {
92            try {
93                var apiMethod = "AddToCart";
94                if (self.isNordeaFinancingCheckout)
95                    apiMethod = "AddToCartWithNordeaFinancing";
96
97                PubSub.publish(mcWeb.cartsmall.events.onShowNewItemInCart);
98                self.service.GetAction(apiMethod, json).then(function (result) {
99                    if (result != null && result.Success == true) {
100                        PubSub.publish(mcWeb.cartsmall.events.onShowNewItemInCartText, { status: true, msg: result.PopupText });
101                        PubSub.publish(mcWeb.cartsmall.events.onUpdateCart);
102                        PubSub.publish(mcWeb.events.freeShippingTxt.onUpdateFreeShipping);
103
104                        if (jQuery('.body-checkout').length > 0) {
105
106
107                            if (mcWeb.customerRegistration !== undefined && mcWeb.customerRegistration !== null && mcWeb.customerRegistration.instances['checkout-registration'] !== null && mcWeb.customerRegistration.instances['checkout-registration'] !== undefined) {
108                                var registrationVM = mcWeb.customerRegistration.instances['checkout-registration'].registrationVM;
109                                if (registrationVM.usingPorterbuddy() && porterbuddy !== undefined && porterbuddy.refresh !== undefined) {
110                                    //This variable should have been injected by Porterbuddy, if the Porterbuddy module is active.
111
112                                    porterbuddy.refresh();
113                                }
114                            }
115                            PubSub.publish(mcWeb.events.freeShippingTxt.onUpdateFreeShipping);
116                            PubSub.publish(mcWeb.cart.events.onChangedCart, null);
117                            PubSub.publish(mcWeb.cart.events.onChangedQuantityCart, null);
118                        }
119
120                        if (jQuery("body.pagetype-Cart").length > 0) {//only when on the cart page                            
121                            PubSub.publish(mcWeb.cart.events.onChangedCart, null);
122                        }
123
124                        if (result.Redirect != null) { //&& result.Redirect != "[AJAXREFRESH]" && result.Redirect != "[REFRESH]") {
125
126                            if (result.Redirect == 'mcWeb.SkiAssembly') {
127                                setTimeout(function () {
128                                    getLibrary("skiassembly").then(() => {
129                                        mcWeb.SkiAssembly.load();
130                                    });
131                                }, 500);
132                            }
132 else if (result.Redirect == 'mcWeb.SkiAttributeAssembly') {
133                                setTimeout(function () {
134                                    getLibrary("skiattributeassembly").then(() => {
135                                        mcWeb.SkiAttributeAssembly.load();
136                                    });
137                                }, 500);
138                            }
139                            else if (allowRedirect === true && result.Redirect.length > 0) {
140                                document.location.href = result.Redirect;
141                            }
142
143                            //OLD design - REMOVE this code when demonstre 1 is deleted
144                            if (result.Redirect === "[REFRESH]" && $('.WebCartSmall').length > 0) {
145                                location.reload(true);
146                            }
147                            else if(result.MustRefreshPrices){
148                                if(mcWeb.ajaxRenderEngine == undefined){
149                                    location.reload(true);
150                                }
151                                else{
152                                    PubSub.publish(mcWeb.ajaxRenderEngine.events.onPriceRefreshRequested,null);
153                                }
154                                
155                            }
156                            //END - OLD design - REMOVE this code when demonstre 1 is deleted
157
158                        }
159                        else if (result.MessageToPublish !== null) {
160                            PubSub.publish(result.MessageToPublish, result.MessageToPublishData);
161                        }
162                    } else {
163                        if(result.ShowNewOrderbookPopup){
164                            mcWeb.orderbookManager.showAddNewOrderbookDate(self.posInfo);
165                            PubSub.publish(mcWeb.cartsmall.events.onHideNewItemInCart);
166                        }
167                        else{
168                            PubSub.publish(mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: ((result == null) ? '' : result.PopupText) });
169                        }
170                    }
171                    self.isNordeaFinancingCheckout = false;
172                });
173            } catch (e) {
174                PubSub.publish(mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: 'Error: ' + e });
175                alert("Exception: " + e);
176            }
177        };
178    };
179})(jQuery);

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.