PageSourceSearch

https://www.discountschoolsupply.com/_ui/responsive/common/js/acc.cartitem.js?v=S530

js discountschoolsupply.com collected 2026-09-25 18:18:10 UTC 8,865 bytes, 248 lines download raw bytes

1ACC.cartitem = {
2
3    _autoload: [
4        "bindCartItem"
5    ],
6
7    submitTriggered: false,
8
9    bindCartItem: function ()
10    {
11
12        $('.js-execute-entry-action-button').on("click", function (ev) {
13            ev.preventDefault();
14            var entryAction = $(this).data("entryAction");
15            var entryActionUrl =  $(this).data("entryActionUrl");
16            var entryProductCode =  $(this).data("entryProductCode");
17            var entryInitialQuantity =  $(this).data("entryInitialQuantity");
18            var actionEntryNumbers =  $(this).data("actionEntryNumbers");
19
20            /*if(entryAction == 'REMOVE')
21            {
22                ACC.track.trackRemoveFromCart(entryProductCode, entryInitialQuantity);
23            }*/
24
25            var cartEntryActionForm = $("#cartEntryActionForm");
26            var entryNumbers = actionEntryNumbers.toString().split(';');
27            entryNumbers.forEach(function(entryNumber) {
28                var entryNumbersInput = $("<input>").attr("type", "hidden").attr("name", "entryNumbers").val(entryNumber);
29                cartEntryActionForm.append($(entryNumbersInput));
30            });
31
32            cartEntryActionForm.attr('action', entryActionUrl).submit();
33        });
34
35        $('.js-update-entry-quantity-input')
36            .on("blur", function (e) {
37                ACC.cartitem.handleUpdateQuantity(this, e);
38            })
39            .on("keyup", function (e) {
40                return ACC.cartitem.handleKeyEvent(this, e);
41            })
42            .on("keydown", function (e) {
43                return ACC.cartitem.handleKeyEvent(this, e);
44            });
45
46            $('.js-update-quantity-cart')
47            .on("click", function (e) {
48                var id = $(this).data('id')
49                setTimeout(function() {
50                    ACC.cartitem.handleUpdateQuantity($("#"+id), e);
51                }, 1000);
52
53            })
54
55    },
56
57    handleKeyEvent: function (elementRef, event)
58    {
59        //console.log("key event (type|value): " + event.type + "|" + event.which);
60        if (event.which == 13 && !ACC.cartitem.submitTriggered) {
61            ACC.cartitem.submitTriggered = ACC.cartitem.handleUpdateQuantity(elementRef, event);
62            return false;
63        }
64        else {
65            // Ignore all key events once submit was triggered
66            if (ACC.cartitem.submitTriggered) {
67                return false;
68            }
69        }
70        return true;
71    },
72
73    handleUpdateQuantity: function (elementRef, event)
74    {
75        var form = $(elementRef).closest('form'),
76            productCode = form.find('input[name=productCode]').val(),
77            initialCartQuantity = form.find('input[name=initialQuantity]').val(),
78            newCartQuantity = form.find('input[name=quantity]').val();
79        if(initialCartQuantity != newCartQuantity) {
80            ACC.cartitem.updateCartAjax(form, newCartQuantity);
81            return true;
82        }
83        return false;
84    },
85
86    updateCartAjax: function (form, newQuantity)
87    {
88        var $row = form.closest('li.item__list--item');
89        $row.addClass('js-updating-qty');
90
91        $.ajax({
92            url: form.attr('action'),
93            type: 'POST',
94            data: form.serialize(),
95            dataType: 'html',      // server returns the redirected /cart page HTML
96            success: function (html) {
97                ACC.cartitem.refreshCartFromHtml(html);
98                ACC.cartitem.refreshMiniCart();
99                form.find('input[name=initialQuantity]').val(newQuantity);
100            },
101            error: function () {
102                // fallback to old behavior if the AJAX round-trip fails for any reason
103                form.submit();
104            },
105            complete: function () {
106                $row.removeClass('js-updating-qty');
107            }
108        });
109    },
110
111    // Parses the full /cart HTML response and swaps only the fragments that changed
112    refreshCartFromHtml: function (html)
113{
114    var $newDoc = $('<div>').html(html);
115
116    var $oldLists = $('.item__list.item__list__cart');
117    var $newLists = $newDoc.find('.item__list.item__list__cart');
118
119    if ($newLists.length === $oldLists.length) {
120        $oldLists.each(function (i) {
121            $(this).replaceWith($newLists.eq(i));
122        });
123    } else if ($newLists.length) {
124        var $container = $oldLists.first().parent();
125        if ($container.length) {
126            var $newContainer = $newDoc.find('.item__list.item__list__cart').first().parent();
127            $container.replaceWith($newContainer);
128        }
129    }
130
131    // Swap each group's header block ("N Drop-ship Items : $X", etc.) —
132    // same per-group repetition issue as above.
133    var $newGroupCounts = $newDoc.find('.product-count');
134    var $oldGroupCounts = $('.product-count');
135    if ($newGroupCounts.length && $newGroupCounts.length === $oldGroupCounts.length) {
136        $oldGroupCounts.each(function (i) {
137            $(this).replaceWith($newGroupCounts.eq(i));
138        });
139    } else if ($newGroupCounts.length) {
140        var $newGroupsWrapper = $newDoc.find('.product-count').first().closest('.item-groups, .cart
140-groups, .order-groups');
141        var $oldGroupsWrapper = $('.product-count').first().closest('.item-groups, .cart-groups, .order-groups');
142        if ($newGroupsWrapper.length && $oldGroupsWrapper.length) {
143            $oldGroupsWrapper.replaceWith($newGroupsWrapper);
144        }
145    }
146
147    // Swap the order summary block (subtotal, tax, shipping, total)
148    var $newSummary = $newDoc.find('.summary-items').first();
149    if ($newSummary.length) {
150        $('.summary-items').first().replaceWith($newSummary);
151    }
152
153    // Swap the item count in the summary title
154    var $newCount = $newDoc.find('.summary-title .count').first();
155    if ($newCount.length) {
156        $('.summary-title .count').first().replaceWith($newCount);
157    }
158
159    // Swap any flash/global messages so success/error text still shows
160    var $newMessages = $newDoc.find('.global-alerts, .alert-messages').first();
161    if ($newMessages.length) {
162        $('.global-alerts, .alert-messages').first().replaceWith($newMessages);
163    }
164
165    // Re-bind handlers on the newly inserted DOM nodes
166    ACC.cartitem.bindCartItem();
167},
168    refreshMiniCart: function ()
169    {
170        var $miniCartLink = $('#cartFlyoutDisplay.js-mini-cart-link');
171        var refreshUrl = $miniCartLink.data('mini-cart-refresh-url');
172
173        if (!refreshUrl) {
174            return;
175        }
176
177        $.ajax({
178            url: refreshUrl,
179            type: 'GET',
180            dataType: 'json',
181            success: function (data) {
182                if (!data) {
183                    return;
184                }
185
186                // Count badge
187                if (typeof data.miniCartCount !== 'undefined') {
188                    var countText = data.miniCartCount < 100 ? data.miniCartCount : "99+";
189                    $('.mini-cart-count .nav-items-total').text(countText);
190                }
191
192                // Price
193                if (typeof data.miniCartPrice !== 'undefined') {
194                    $('.mini-cart-price .cart-total-display').text(data.miniCartPrice);
195                }
196            }
197            // no error fallback — a stale mini-cart count for a moment isn't worth a reload
198        });
199    },
200
201    updateCartFromFlyout: function (entryNumber, quantity) {
202
203    var $cartForm = $('.js-update-entry-quantity-input')
204        .filter(function () {
205            var $form = $(this).closest('form');
206
207            return $form.find('input[name="entryNumber"]').val() == entryNumber;
208        })
209        .closest('form');
210
211    if (!$cartForm.length) {
212        return;
213    }
214
215    $cartForm.find('input[name="quantity"]').val(quantity);
216
217    ACC.cartitem.updateCartAjax($cartForm, quantity);
218},
219};
220
221$(document).ready(function() {
222    $('.js-cartItemDetailBtn').click(function(event) {
223        event.stopPropagation();
224        var thisDetailGroup =  $(this).parent('.js-cartItemDetailGroup');
225        $(thisDetailGroup).toggleClass('open'); //only in its parent
226        if ( $(thisDetailGroup).hasClass('open') )  {
227            //close all if not this parent
228            $('.js-cartItemDetailGroup').not( thisDetailGroup ).removeClass('open');
229            //change aria
230            $('.js-cartItemDetailBtn').attr('aria-expanded', 'true');
231
232        } else {
233            $('.js-cartItemDetailBtn').attr('aria-expanded', 'false');
234        }
235        $(document).click( function(){
236            $(thisDetailGroup).removeClass('open');
237        }); // closes when clicking outside this div
238    });
239
240    //enable comment for this item only
241    $('.js-entry-comment-button').click(function(event) {
242        event.preventDefault();
243        var linkID = $(this).attr('href');
244        $( linkID ).toggleClass('in');
245        $( thisDetailGroup ).removeClass('open');
246    });
247});
248

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.