PageSourceSearch

https://www.screeningeagle.com/js/cart.min.js

js screeningeagle.com collected 2026-10-02 02:44:53 UTC 10,020 bytes, 293 lines download raw bytes

1/* 
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 * 
6 * Methoden
7 * .addItem(productId, amount = 1)
8 * .updateItem(productId, amount)
9 * .removeItem(productId)
10 * .removeAll()
11 */
12
13
14function Cart() {
15    this.addUrl = "/cart/add-to-cart";
16    this.updateUrl = "/cart/update-item-amount";
17    this.removeUrl = "/cart/remove-from-cart";
18    this.clearUrl = "/cart/clear-cart";
19    this.previewUrl = "/cart/preview";
20    this.itemCountUrl = "/cart/cart-item-count";
21    this.getAccessoriesUrl = "/{_locale}/products/{id}/get-accessories";
22    this.titleRemoveFromCart = "Remove from cart";
23    this.bodyRemoveFromCart = "Are you sure to remove <b>##productName##</b> from the cart!";
24    
25    this.btnCancelLabel = "Cancel";
26    this.btnRemoveLabel = "Remove";
27    this.btnCloseLabel = "Close";
28    
29    this.titleAccessories = "Accessories";
30    this.titleRemoveAllFromCart = "Remove all from cart";
31    this.bodyRemoveAllFromCart = "Are you sure to remove all products from the cart!";
32    this.btnRemoveAllLabel = "Remove all";
33    this.itemCount = 0;
34}
35
36Cart.prototype.alert = function (message, status) {
37    var messagetype = "success";
38    if ("Error" === status) {
39        messagetype = "danger";
40    }
41    try {
42    $.showNotification({
43        body: message,
44        type: messagetype,
45        duration: 3000
46    });
47    } catch (err) {
48        console.log(err);
49    }
50};
51
52Cart.prototype.setItemCount = function (count) {
53    this.itemCount = count;
54    var itemCount = (count > 0) ? count : '';
55    $('span#cartItemCount').html(itemCount);
56};
57
58
59Cart.prototype.getItemCount = function () {
60    var currentCart = this;
61    $.get(this.itemCountUrl, function (response) {
62        if (response.data.status === "OK") {
63            currentCart.setItemCount(response.data.itemCount);
64        }
65    });
66};
67
68Cart.prototype.addItem = function (id, amount) {
69
70    var queryString = "";
71    if ( 'number' === typeof id ) {
72        if ('undefined' !== typeof amount ) {
73            if ( 'number' !== typeof amount) {
74                amount = 1;
75                console.log("amount isn't a number");
76            }
77        } else {
78            amount = 1;
79        }
80        
81        if (0 === $("#product" + id).length) {
82            queryString = "?id=" + id + "&amount=" + amount;
83            if ($("#cart-container").length) {
84                queryString = queryString + "&row=true";
85            }
86            var currentCart = this;
87            $.get(this.addUrl + queryString, function (response) {
88                if ("OK" === response.data.status ) {
89                    currentCart.setItemCount(response.data.itemCount);
90                }
91                currentCart.alert(response.data.message, response.data.status);
92                currentCart.getPreview();
93                if ($("#cart-container").length) {
94                    if ('' != response.data.row) {
95
96                        $(response.data.row).insertAfter($("#cart-container").find('.cart-row').last());
97
98                        currentCart.setSubTotal();
99                    }
100                }
101            });
102        } else {
103            // Product exist in the cart, add one item more ???
104            this.updateQuantity(id, "+");
105        }
106    } else {
107        console.log("Id isn't a number");
108    }
109};
110
111Cart.prototype.updateItem = function (id, amount) {
112    var minAmount = parseInt($('#quantity' + id).attr('min'));
113    var maxAmount = parseInt($('#quantity' + id).attr('max'));
114    var queryString = "";
115    if (typeof id === 'number') {
116        if (typeof amount !== 'undefined') {
117            if (typeof parseInt(amount) !== 'number') {
118                console.log("amount isn't a number");
119                amount = 1;
120            }
121        } else {
122            amount = 1;
123        }
124
125        $('#btnQuantityUp' + id).removeClass('deactive');
126        $('#btnQuantityDown' + id).removeClass('deactive');
127        if (amount <= minAmount) {
128            amount = minAmount;
129            $('#quantity' + id).val(amount);
130            $('#btnQuantityDown' + id).addClass('deactive');
131        } else if (amount >= maxAmount) {
132            amount = maxAmount;
133            $('#quantity' + id).val(amount);
134            $('#btnQuantityUp' + id).addClass('deactive');
135        }
136
137        queryString = "?id=" + id + "&amount=" + amount;
138        var currentCart = this;
139        $.get(this.updateUrl + queryString, function (response) {
140            if (response.data.status === "OK") {
141                console.log(response);
142            }
143        });
144    } else {
145        console.log("Id isn't a number");
146    }
147};
148
149Cart.prototype.removeItem = function (id) {
150    var queryString = "";
151    if (typeof id === 'number') {
152        queryString = "?id=" + id;
153        var currentCart = this;
154        $('#ModalConfirmDialogTitle').html(this.titleRemoveFromCart);
155        $('#ModalBody').html(this.bodyRemoveFromCart.replace('##productName##', $('#prdPreviewName' + id).html()));
156        $('#ModalCancelBtn').html(this.btnCancelLabel);
157        $('#ModalConfirmBtn').html(this.btnRemoveLabel);
158        $('#ModalConfirmBtn').click(function (event) {
159            $.get(currentCart.removeUrl + queryString, function (response) {
160                if (response.data.status === "OK") {
161                    currentCart.setItemCount(response.data.itemCount);
162                }
163                currentCart.alert(response.data.message, response.data.status);
164                currentCart.getPreview();
165                if (($("#cart-container").length) && (0 === currentCart.itemCount)) {
166                    location.reload();
167                } else {
168                    $('#product' + id).remove();
169                    currentCart.setSubTotal();
170                }
171            });
172            $('#ModalConfirmDialog').modal('hide');
173        });
174        $('#ModalConfirmDialog').modal('show');
175    } else {
176        console.log("Id isn't a number");
177    }
178};
179
180Cart.prototype.removeAll = function () {
181    var currentCart = this;
182    $('#ModalConfirmDialogTitle').html(this.titleRemoveAllFromCart);
183    $('#ModalBody').html(this.bodyRemoveAllFromCart);
184    $('#ModalCancelBtn').html(this.btnCancelLabel);
185    $('#ModalConfirmBtn').html(this.btnRemoveAllLabel);
186    $('#ModalConfirmBtn').click(function (event) {
187        $.get(currentCart.clearUrl, function (response) {
188            if (response.data.status === "OK") {
189                currentCart.setItemCount(0);
190            }
191            currentCart.alert(response.data.message, response.data.status);
192            currentCart.getPreview();
193            if ($("#cart-container").length) {
194                location.reload(true);
195            }
196        });
197        $('#ModalConfirmDialog').modal('hide');
198    });
199    $('#ModalConfirmDialog').modal();
200};
201
202Cart.prototype.getPreview = function () {
203    var currentCart = this;
204    $.get(this.previewUrl, function (response) {
205        $('.cart-dropdown-list-container').html(window.sanitizeHtml(response));
206        if (currentCart.itemCount > 0) {
207            $('.cart-dropdown-bottom-toolbar').show();
208        } else {
209            $('.cart-dropdown-bottom-toolbar').hide();
210        }
211        if (currentCart.itemCount > 1) {
212            $('.cart-dropdown-top-toolbar').show();
213        } else {
214            $('.cart-dropdown-top-toolbar').hide();
215        }
216    });
217};
218
219Cart.prototype.updatePrice = function (id, amount, price) {
220    var total = price * amount;
221    $('#quantityPrice' + id).val(total);
222    $('#price' + id).html(formatter.format(total));
223    this.setSubTotal();
224};
225
226Cart.prototype.setSubTotal = function () {
227    var subtotal = 0;
228    $("input[id^=quantityPrice").each(function (index) {
229        var number = Number(parseFloat($(this).val().replace(/[^0-9.-]+/g, "")));
230        subtotal = subtotal + number;
231    });
232    if (subtotal > 0) {
233        $('#cartTotalPrice').html(formatter.format(subtotal));
234        $('#cart-footer').show();
235    } else {
236        $('#cart-footer').hide();
237    }
238};
239
240Cart.prototype.updateQuantity = function (id, type) {
241    var amount = parseInt($('#quantity' + id).val());
242    var minAmount = parseInt($('#quantity' + id).attr('min'));
243    var maxAmount = parseInt($('#quantity' + id).attr('max'));
244    if ((("-" === type) && (amount <= minAmount)) || (("+" === type) && (amount >= maxAmount))) {
245        return;
246    }
247   
248    if ("+" === type) {
249        amount = amount + 1;
250    } else if ("-" === type) {
251        amount = amount - 1;
252    }
253    $('#quantity' + id).val(amount);
254    $('#quantity' + id).trigger("change");
255};
256
257Cart.prototype.goBack = function () {
258    window.history.back();
259};
260
261Cart.prototype.getAccessories = function (id) {
262    var currentCart = this;
263    var url = this.getAccessoriesUrl.replace('{id}', id);
264    console.log({url});
265    $.get(url, function (response) {
266  
267        $('#ModalConfirmDialogTitle').html(currentCart.titleAccessories);
268        $('#ModalConfirmDialog .modal-dialog').addClass('modal-lg');
269        $('#ModalConfirmDialog .modal-dialog').addClass('modal-dialog-scrollable');
270        $('#ModalBody').html(window.sanitizeHtml(response));
271        $('#ModalCancelBtn').html(currentCart.btnCloseLabel);
272        $('#ModalConfirmBtn').hide();
273        var myModal = new bootstrap.Modal(document.getElementById("ModalConfirmDialog"), {});
274     
275        myModal.show();
276     
277        
278    });
279}
280
281function toogleCartProductDescription(obj){
282    $(obj).siblings().toggle(); 
283    $(obj).children('i').toggleClass('fa-chevron-circle-down').toggleClass('fa-chevron-circle-up');
284}
285
286$(document).ready(function () {
287    cart.getPreview();
288});
289
290var cart = new Cart();
291cart.getItemCount();
292
293

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.