PageSourceSearch

https://westwatches.pl/themes/westwatchestheme/modules/cdproductco…/js/cdproductcomparisonplus_front.js?v=12

js westwatches.pl collected 2026-09-26 20:43:55 UTC 41,441 bytes, 1,313 lines download raw bytes

1/**
2 * NOTICE OF LICENSE
3 *
4 * ---------------------------------------------------
5 *
6 *  @author    : CD Presta <[email protected]>
7 *  @copyright : 2016-2020
8 *  @license   : Commercial License
9 *  @version   : 2.3.11
10 * ---------------------------------------------------
11 */
12function _classCallCheck(instance, Constructor) {
13  if (!(instance instanceof Constructor)) {
14    throw new TypeError("Cannot call a class as a function");
15  }
16}
17
18function _defineProperties(target, props) {
19  for (var i = 0; i < props.length; i++) {
20    var descriptor = props[i];
21    descriptor.enumerable = descriptor.enumerable || false;
22    descriptor.configurable = true;
23    if ("value" in descriptor) descriptor.writable = true;
24    Object.defineProperty(target, descriptor.key, descriptor);
25  }
26}
27
28function _createClass(Constructor, protoProps, staticProps) {
29  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
30  if (staticProps) _defineProperties(Constructor, staticProps);
31  return Constructor;
32}
33
34var Scrollbar = function () {
35  function Scrollbar() {
36    _classCallCheck(this, Scrollbar);
37
38    this._scrollbarWidth = this.getWidth();
39    this._fixedRightEls = [];
40  }
41
42  _createClass(Scrollbar, [{
43    key: "getWidth",
44    value: function getWidth() {
45      var docEl = document.documentElement;
46      var windowWidth = window.innerWidth || docEl.clientWidth || document.body.clientWidth;
47      var docWidth = Math.max(docEl.clientWidth, docEl.offsetWidth, docEl.scrollWidth);
48      return Math.abs(windowWidth - docWidth);
49    }
50  }, {
51    key: "hide",
52    value: function hide() {
53      var _this = this;
54
55      var actualPadding = document.body.style.paddingRight;
56      var calculatedPadding = parseFloat($(document.body).css("paddingRight"));
57      $(document.body).data({
58        overflow: document.body.style.overflow,
59        paddingRight: actualPadding
60      });
61      document.body.style.paddingRight = "".concat(calculatedPadding + this._scrollbarWidth, "px");
62      document.body.style.overflow = "hidden";
63
64      this._fixedRightEls.forEach(function (el) {
65        if (el) {
66          var actualMargin = el.style.marginRight;
67          var calculatedMargin = parseFloat($(el).css("marginRight"));
68          $(el).data("marginRight", actualMargin);
69          el.style.marginRight = "".concat(calculatedMargin + _this._scrollbarWidth, "px");
70        }
71      });
72    }
73  }, {
74    key: "show",
75    value: function show() {
76      var actualPadding = $(document.body).data("paddingRight");
77      document.body.style.paddingRight = actualPadding ? actualPadding : "";
78      document.body.style.overflow = $(document.body).data("overflow");
79      $(document.body).removeData(["overflow", "paddingRight"]);
80
81      this._fixedRightEls.forEach(function (el) {
82        if (el) {
83          var actualMargin = $(el).data("marginRight");
84          el.style.marginRight = actualMargin ? actualMargin : "";
85          $(el).removeData("marginRight");
86        }
87      });
88    }
89  }, {
90    key: "addFixedRightEl",
91    value: function addFixedRightEl(el) {
92      this._fixedRightEls.push(el);
93    }
94  }, {
95    key: "width",
96    get: function get() {
97      return this._scrollbarWidth;
98    }
99  }]);
100
101  return Scrollbar;
102}();
103var Scrollbar$1 = new Scrollbar();
104
105function removeElements(els) {
106  if (!els) {
107    return false;
108  }
109
110  els = els instanceof HTMLElement ? [els] : [].slice.call(els);
111  els.forEach(function (el) {
112    return el.parentNode.removeChild(el);
113  });
114}
115
116function supportsLocalStorage() {
117  try {
118    window.localStorage.setItem("supportCheck", "supportCheck");
119    window.localStorage.removeItem("supportCheck");
120    return true;
121  } catch (e) {
122    return false;
123  }
124}
125
126var supportsLocalStorage$1 = supportsLocalStorage();
127
128$(document).ready(function () {
129  var doc = document;
130  var tableDiffType = parseInt(window.cdpcpConfig.highlightType) || false;
131
132  // Curves taken from Google's Material design language
133  var animationEasings = {
134    _default: [0.4, 0.0, 0.2, 1],
135    _enterScreen: [0.0, 0.0, 0.2, 1],
136    _exitScreen: [0.4, 0.0, 0.6, 1]
137  };
138
139  // Some devices will wait extremely long amounts of time before
140  // triggering an AJAX error (i.e. if disconnected from network)
141  // Set a timeout for calls
142  var ajaxTimeout = 15000;
143
144  var isStickyFooterVisible;
145  var cdpcpEl;
146  var $cdpcp;
147  window.cdpcpButton = window.cdpcpButton.trim();
148
149  /*============================================================================
150  POLYFILLS
151  ============================================================================*/
152
153  // element.matches( selectorString )
154  if (!Element.prototype.matches) {
155    Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
156  }
157
158  // element.closest( selectors )
159  if (!Element.prototype.closest) {
160    Element.prototype.closest = function (s) {
161      var el = this;
162
163      do {
164        if (el.matches(s)) {
165          return el;
166        }
167
168        el = el.parentElement || el.parentNode;
169      } while (el !== null && el.nodeType === 1);
170
171      return null;
172    };
173  }
174
175  /*============================================================================
176  INITIALIZATION
177  ============================================================================*/
178
179  window.cdpcpInit = function () {
180    if (window.cdpcpConfig.stickyFooterEnabled) {
181      cdpcpEl = doc.getElementById("cdproductcomparisonplus");
182      $cdpcp = $(cdpcpEl);
183      var numStickyFooterItems = cdpcpEl ? cdpcpEl.getElementsByClassName("cdpcp__item").length : 0;
184      isStickyFooterVisible = Boolean(numStickyFooterItems);
185
186      if (isStickyFooterVisible) {
187        $(doc.body).addClass("cdpcp-show-sticky-footer");
188      }
189
190      if (supportsLocalStorage$1 && window.localStorage.getItem("cdpcpTrayCollapsed")) {
191        $cdpcp.addClass("cdpcp--collapsed");
192      }
193
194      if (isStickyFooterVisible) {
195        showStickyFooter();
196      }
197
198      Scrollbar$1.addFixedRightEl(cdpcpEl);
199      bindStickyFooterHandlers();
200    }
201
202    bindComparisonTableHandlers();
203    observeProductListButtons();
204    observeProductPageButton();
205    addProductListButtonsToEl(doc);
206    updateProductPageButton();
207  };
208
209  window.cdpcpInit();
210
211  /*============================================================================
212  EVENT HANDLERS AND BINDING FUNCTIONS
213  ============================================================================*/
214
215  prestashop.on("updateCart", function () {
216    var cartModalEls = doc.getElementsByClassName("cdpcp-cart-modal");
217
218    if (cartModalEls.length) {
219      $(cartModalEls).modal("hide");
220    }
221  }).on("cdpcpCartClick", function (idProduct) {
222    var data = {
223      action: "cdpcpCart",
224      id_product: idProduct
225    };
226    $.post(prestashop.urls.pages.product, data, null, "json").then(function (resp) {
227      $("body").append(resp.html);
228      var cdpcpCartModal = $(doc.getElementById("cdpcp-cart-modal-".concat(resp.product.id)));
229      cdpcpCartModal.modal("show").on("hidden.bs.modal", function () {
230        cdpcpCartModal.remove();
231      }).find("#quantity_wanted").TouchSpin({
232        verticalbuttons: true,
233        verticalupclass: "material-icons touchspin-up",
234        verticaldownclass: "material-icons touchspin-down",
235        buttondown_class: "btn btn-touchspin js-touchspin",
236        buttonup_class: "btn btn-touchspin js-touchspin",
237        min: 1,
238        max: 1000000
239      });
240    }).fail(function (resp) {
241      return prestashop.emit("handleError", {
242        eventType: "cdpcpCartClick",
243        resp: resp
244      });
245    });
246  });
247  $(doc)
248
249  // Taken from http://stackoverflow.com/a/24914782
250  // Fixes appearance when opening a popup compare and a quickview on top of it
251  .on("show.bs.modal", ".modal", function (e) {
252    var zIndex = 9999 + 10 * $(doc.getElementsByClassName("modal")).filter(":visible").length;
253    e.currentTarget.style.zIndex = zIndex;
254    setTimeout(function () {
255      $(doc.getElementsByClassName("modal-backdrop")).not(".modal-stack").css("z-index", zIndex - 1).addClass("modal-stack");
256    }, 0);
257
258    if ((" " + e.currentTarget.className + " ").indexOf(" quickview ") !== -1) {
259      updateQuickviewButton();
260    }
261  })
262
263  // Fixes the scenario when a stacked modal is closed and the remaining modal
264  // doesn't recieve scrolling focus
265  .on("hidden.bs.modal", ".modal", function () {
266    if ($(doc.getElementsByClassName("modal")).filter(":visible").length) {
267      $(doc.body).addClass("modal-open");
268    }
269  }).on("click", ".cdpcp-compare-btn", function (e) {
270    e.stopPropagation();
271    e.preventDefault();
272  }).on("click", ".cdpcp-compare-btn--remove", function (e) {
273    removeProduct(getButtonIdProduct(e.currentTarget));
274  }).on("click", ".cdpcp-compare-btn--add", function (e) {
275    addProduct(getButtonIdProduct(e.currentTarget));
276  }).on("click", ".cdpcp-table__quickview", function (e) {
277    var clickedEl = e.currentTarget;
278    e.preventDefault();
279    prestashop.emit('clickQuickView', {
280      dataset: {
281        action: "quickview",
282        idProduct: clickedEl.getAttribute("data-id-product"),
283        idProductAttribute: clickedEl.getAttribute("data-id-product-attribute")
284      }
285    });
286  }).on("click", ".cdpcp-table__add-cart", function (e) {
287    e.preventDefault();
288    prestashop.emit('cdpcpCartClick', e.currentTarget.getAttribute("data-id-product"));
289  }).on("click", ".cdpcp-table__delete", function (e) {
290    var idProduct = e.currentTarget.getAttribute("data-id-product");
291    var productCellEls = doc.getElementsByClassName("cdpcp-table__product-" + idProduct);
292    var innerCellEls = $(productCellEls).children(".cdpcp-table__cell-inner").get();
293    var animateFromWidth = productCellEls[0].offsetWidth;
294    removeProduct(idProduct);
295
296    if (doc.getElementsByClassName("cdpcp-table__header-cell--product").length === 1) {
297      var emptyTableMsgEl = doc.getElementById("cdpcp-empty-table-msg");
298
299      if (emptyTableMsgEl) {
300        $.Velocity(emptyTableMsgEl, "slideDown", {
301          duration: 400,
302          easing: animationEasings._default
303        });
304      }
305
306      $.Velocity(doc.getElementById("cdpcp-table-wrapper"), "slideUp", {
307        duration: 400,
308        easing: animationEasings._default,
309        complete: function complete() {
310          return removeProductFromUrl(idProduct);
311        }
312      });
313    } else {
314      $.Velocity(innerCellEls, {
315        opacity: [0, 1],
316        transformOriginX: ["50%", "50%"],
317        transformOriginY: ["50%", "50%"],
318        scaleX: [0.625, 1],
319        scaleY: [0.625, 1],
320        translateZ: 0
321      }, {
322        duration: 400,
323        easing: animationEasings._default,
324        complete: function complete() {
325          var animatedEls = [];
326
327          for (var i = innerCellEls.length - 1; i >= 0; i--) {
328            animatedEls.push(innerCellEls[i]);
329          }
330
331          for (var _i = productCellEls.length - 1; _i >= 0; _i--) {
332            animatedEls.push(productCellEls[_i]);
333          }
334
335          $.Velocity(animatedEls, {
336            padding: 0,
337            width: [0, animateFromWidth],
338            translateZ: 0
339          }, {
340            display: "none",
341            duration: 400,
342            easing: animationEasings._default,
343            complete: function complete() {
344              removeElements(productCellEls);
345              removeProductFromUrl(idProduct);
346            }
347          });
348        }
349      });
350    }
351  }).on("click", ".cdpcp-compare-now", function (e) {
352    var compareUrl = e.currentTarget.href ? e.currentTarget.href : e.currentTarget.getAttribute("data-src");
353
354    if (window.cdpcpConfig.popupCompareEnabled) {
355      e.preventDefault();
356      openComparePopup(compareUrl);
357      closeSlideout();
358    } else {
359      window.location = compareUrl;
360    }
361  });
362
363  function bindStickyFooterHandlers() {
364    window.addEventListener("scroll", function () {
365      if (cdpcpEl) {
366        $.Velocity(cdpcpEl, {
367          translateY: getStickyFooterOffset(),
368          translateZ: 0
369        }, 5);
370      }
371    });
372    $(doc).on("click", "#cdpcp-menu-button", function () {
373      openSlideout(doc.getElementById("cdpcp-menu-slideout"));
374    }).on("click", "#cdpcp-toggle-tray", function () {
375      closeSlideout(toggleStickyFooter);
376    }).on("click", ".cdpcp-item__image", function (e) {
377      var slideoutEl = $(e.currentTarget).closest(".cdpcp__item")[0].getElementsByClassName("cdpcp__slideout")[0];
378      openSlideout(slideoutEl);
379    }).on("click", "#cdpcp-backdrop, .cdpcp-slideout__close", function () {
380      closeSlideout();
381    }).on("click", ".cdpcp-slideout__remove", function (e) {
382      var clickedEl = e.currentTarget;
383      closeSlideout(function () {
384        return removeProduct(clickedEl.getAttribute("data-id-product"));
385      });
386    }).on("click", ".cdpcp-slideout__quick-view", function (e) {
387      e.preventDefault();
388      prestashop.emit('clickQuickView', {
389        dataset: {
390          action: "quickview",
391          idProduct: e.currentTarget.getAttribute("data-id-product"),
392          idProductAttribute: e.currentTarget.getAttribute("data-id-product-attribute")
393        }
394      });
395      closeSlideout();
396    }).on("click", ".cdpcp-remove-all", function () {
397      closeSlideout(ajaxRemoveAllProducts);
398    });
399  }
400
401  function addObserver(targetNode, fn) {
402    if (window.MutationObserver && targetNode && typeof fn === "function") {
403      var observer = new window.MutationObserver(fn);
404      observer.observe(targetNode, {
405        childList: true,
406        subtree: true
407      });
408    }
409  }
410
411  function observeProductPageButton() {
412    // Mutation observer allows for more dynamic observation of element content changing
413    if (window.MutationObserver) {
414      addObserver(doc.getElementById("add-to-cart-or-refresh"), updateProductPageButton);
415    } else {
416      $(doc).ajaxComplete(function (event, xhr, settings) {
417        if (settings && settings.data && settings.data.indexOf("action=refresh") !== -1) {
418          updateProductPageButton();
419        }
420      });
421    }
422  }
423
424  function observeProductListButtons() {
425    // Mutation observer allows for more dynamic observation of element content changing
426    if (window.MutationObserver) {
427      addObserver(doc, addProductListButtonsFromObserver);
428    } else {
429      prestashop.on("updateProductList", function () {
430        return addProductListButtonsToEl(doc);
431      });
432    }
433  }
434
435  function updateProductPageButton() {
436    if (prestashop.page.page_name !== "product") {
437      return;
438    }
439
440    var idProductEl = doc.getElementById("product_page_product_id");
441
442    if (!idProductEl) {
443      return;
444    }
445
446    var $button = $(".product-additional-info .cdpcp-compare-btn--no-js, .product-actions .cdpcp-compare-btn--no-js");
447
448    if ($button.length) {
449      updateButton($button, idProductEl.value);
450    } else {
451      $button = $("#product #main .cdpcp-compare-btn--no-js");
452
453      // Not a list button
454      if (!$button.closest(window.cdpcpConfig.listsButtonSelector).length) {
455        updateButton($button, idProductEl.value);
456      }
457    }
458  }
459
460  function updateQuickviewButton() {
461    var idProductEl = doc.querySelector(".modal #product_page_product_id");
462
463    if (idProductEl) {
464      updateButton($(".modal .cdpcp-compare-btn--no-js"), idProductEl.value);
465    }
466  }
467
468  function addProductListButtonsFromObserver(mutations) {
469    (mutations || []).forEach(function (mutation) {
470      mutation.addedNodes.forEach(function (node) {
471        if (node.nodeType === 1 && node.children.length && node.tagName !== "BUTTON") {
472          addProductListButtonsToEl(node);
473        }
474      });
475    });
476  }
477
478  function addProductListButtonsToEl(el) {
479    if (!window.cdpcpConfig.listsButtonSelector) {
480      return;
481    }
482
483    var elMatchesSelector = typeof el.matches === "function" && el.matches(window.cdpcpConfig.listsButtonSelector);
484    var productEls = elMatchesSelector ? [el] : el.querySelectorAll(window.cdpcpConfig.listsButtonSelector);
485
486    for (var i = productEls.length; i--;) {
487      var productEl = productEls[i];
488
489      if (productEl.getElementsByClassName("cdpcp-compare-btn--js").length) {
490        continue;
491      }
492
493      var $button = $(window.cdpcpButton);
494
495      if (window.cdpcpConfig.listsButtonPosition === "below") {
496        $button.appendTo(productEl).addClass("cdpcp-compare-btn--below-list");
497      } else {
498        $button.prependTo(productEl).addClass("cdpcp-compare-btn--above-list");
499      }
500
501      updateButton($button, getIdProductFromDom($button));
502    }
503  }
504
505  function getIdProductFromDom($el) {
506    var $idProductEl = $el.closest("[data-id-product]");
507
508    if ($idProductEl.length) {
509      return $idProductEl.attr("data-id-product");
510    }
511
512    return null;
513  }
514
515  function updateButton($button, idProduct) {
516    if (!$button.length || !idProduct) {
517      return;
518    }
519
520    idProduct = parseInt(idProduct);
521    var inComparison = window.cdpcpProductIds && window.cdpcpProductIds.indexOf(idProduct) !== -1;
522    var actionClass = inComparison ? "cdpcp-compare-btn--remove" : "cdpcp-compare-btn--add";
523    $button.attr("data-id-product", idProduct).removeClass("cdpcp-compare-btn--no-js").addClass("cdpcp-compare-btn--js cdpcp-compare-btn--".concat(idProduct, " ").concat(actionClass));
524  }
525
526  function getButtonIdProduct(btnEl) {
527    var btnAttr = btnEl.getAttribute("data-id-product");
528
529    if (btnAttr) {
530      return btnAttr;
531    }
532
533    var parentAttr = btnEl.parentNode.getAttribute("data-id-product");
534    return parentAttr;
535  }
536
537  function bindComparisonTableHandlers() {
538    if (doc.getElementById("cdpcp-table")) {
539      var highlightBtnEl = doc.getElementById("cdpcp-highlight-btn");
540      var printEl = doc.getElementById("cdpcp-print");
541
542      if (highlightBtnEl) {
543        highlightBtnEl.addEventListener("click", function () {
544          // Un-focus the element so it looks proper
545          highlightBtnEl.blur();
546
547          // Easy hasClass check
548          if ((" " + highlightBtnEl.className + " ").indexOf(" active ") !== -1) {
549            $(highlightBtnEl).removeClass("active");
550
551            if (tableDiffType === 1 || tableDiffType === 2) {
552              removeTableHighlighting();
553            } else if (tableDiffType === 3 || tableDiffType === 4) {
554              toggleTableRowVis("show");
555            }
556          } else {
557            $(highlightBtnEl).addClass("active");
558
559            if (tableDiffType === 1 || tableDiffType === 2) {
560              addTableHighlighting();
561            } else if (tableDiffType === 3 || tableDiffType === 4) {
562              toggleTableRowVis("hide");
563            }
564          }
565        });
566      }
567
568      if (printEl) {
569        printEl.addEventListener("click", function () {
570          var withinModal = $(doc.getElementsByClassName("cdpcp-compare-modal__dialog")).has(printEl).length;
571          var logoEl = doc.querySelector(".logo");
572          var titleEl = doc.querySelector(withinModal ? ".modal-title" : ".page-header h1");
573          var printHeader = "".concat(logoEl ? logoEl.outerHTML : "", "<br><br>").concat(titleEl ? titleEl.outerHTML : "");
574
575          // Un-focus the element so it looks proper
576          printEl.blur();
577          printEl.disabled = true;
578          $(doc.getElementById("cdpcp-table-wrapper")).print({
579            deferred: $.Deferred().done(function () {
580              return printEl.disabled = false;
581            }),
582            mediaPrint: true,
583            prepend: printHeader,
584            timeout: 1000,
585            title: titleEl ? titleEl.textContent : null
586          });
587        });
588      }
589    }
590  }
591
592  /*============================================================================
593  ADD AND REMOVE PRODUCT CONVENIENCE FUNCTIONS
594  ============================================================================*/
595
596  function addProduct(idProduct) {
597    idProduct = parseInt(idProduct);
598    var $compareBtns = $(doc.getElementsByClassName("cdpcp-compare-btn--" + idProduct));
599
600    // This product is already in the comparison list, fix display and exit early
601    if (window.cdpcpProductIds.indexOf(idProduct) !== -1) {
602      $compareBtns.removeClass("cdpcp-compare-btn--add").addClass("cdpcp-compare-btn--remove");
603      return;
604    }
605
606    $compareBtns.prop("disabled", true).addClass("cdpcp-compare-btn--loading");
607    ajaxAddProduct(idProduct, true).done(function (data) {
608      if (data && data.status === "Success") {
609        $compareBtns.removeClass("cdpcp-compare-btn--add").addClass("cdpcp-compare-btn--remove");
610      }
611    }).always(function () {
612      $compareBtns.prop("disabled", false).removeClass("cdpcp-compare-btn--loading");
613    });
614  }
615
616  function removeProduct(idProduct) {
617    idProduct = parseInt(idProduct);
618    var $compareBtns = $(doc.getElementsByClassName("cdpcp-compare-btn--" + idProduct));
619
620    // This product is not in the comparison list, fix display and exit early
621    if (window.cdpcpProductIds.indexOf(idProduct) === -1) {
622      hideStickyFooterProduct(idProduct, function () {
623        return removeStickyFooterProduct(idProduct);
624      });
625      $compareBtns.removeClass("cdpcp-compare-btn--remove").addClass("cdpcp-compare-btn--add");
626      return;
627    }
628
629    $compareBtns.prop("disabled", true).addClass("cdpcp-compare-btn--loading");
630
631    // Remove via ajax if using cookie
632    if (window.cdpcpUsingCookie !== false) {
633      ajaxRemoveProduct(idProduct, true).done(function (data) {
634        if (data && data.status === "Success") {
635          $compareBtns.removeClass("cdpcp-compare-btn--remove").addClass("cdpcp-compare-btn--add");
636        }
637      }).fail(function () {
638        hideStickyFooterProduct(idProduct, function () {
639          return removeStickyFooterProduct(idProduct);
640        });
641      }).always(function () {
642        $compareBtns.prop("disabled", false).removeClass("cdpcp-compare-btn--loading");
643      });
644    }
645  }
646
647  /*============================================================================
648  STICKY FOOTER FUNCTIONS
649  ============================================================================*/
650
651  function getStickyFooterOffset() {
652    if (isStickyFooterVisible) {
653      var overflowHeight = document.body.scrollHeight - document.body.offsetHeight;
654      var cdpcpHeight = cdpcpEl.offsetHeight;
655
656      if (overflowHeight > cdpcpHeight) {
657        var distanceFromBottom = document.body.scrollHeight - window.innerHeight - window.pageYOffset;
658
659        // Stay between el height and 0
660        return Math.min(cdpcpHeight, Math.max(0, cdpcpHeight - distanceFromBottom));
661      } else {
662        return 0;
663      }
664    }
665
666    return 0;
667  }
668
669  function toggleStickyFooter() {
670    var animateEl = doc.getElementById("cdpcp-items-wrapper");
671    var isCollapsed = $cdpcp.hasClass("cdpcp--collapsed");
672    $.Velocity(animateEl, {
673      // Go over 100% in case scrollbars flicker (i.e. fancybox)
674      // and in cases like IE where scrollbars are partially transparent
675      translateX: isCollapsed ? [0, "140%"] : ["140%", 0],
676      translateZ: 0
677    }, {
678      duration: 300,
679      easing: animationEasings[isCollapsed ? "enterScreen" : "exitScreen"],
680      visibility: "visible",
681      begin: function begin() {
682        if (isCollapsed) {
683          animateEl.style.visibility = "hidden";
684          $cdpcp.removeClass("cdpcp--collapsed");
685        }
686      },
687      complete: function complete() {
688        if (!isCollapsed) {
689          $cdpcp.addClass("cdpcp--collapsed");
690        }
691
692        // Remove inline styles set by velocity - prevents slideouts from
693        // messing up
694        animateEl.removeAttribute("style");
695      }
696    });
697
698    if (supportsLocalStorage$1) {
699      if (isCollapsed) {
700        // No longer collapsed
701        window.localStorage.removeItem("cdpcpTrayCollapsed");
702      } else {
703        // Now collapsed
704        window.localStorage.setItem("cdpcpTrayCollapsed", 1);
705      }
706    }
707  }
708
709  function showStickyFooter(cb) {
710    isStickyFooterVisible = true;
711    $(doc.body).addClass("cdpcp-show-sticky-footer");
712    $.Velocity(cdpcpEl, "stop");
713    $.Velocity(cdpcpEl, {
714      translateY: [getStickyFooterOffset(), "140%"],
715      translateZ: 0
716    }, {
717      display: "block",
718      duration: 300,
719      easing: animationEasings._enterScreen,
720      complete: function complete() {
721        cdpcpEl.style.transform = "";
722
723        if (typeof cb === "function") {
724          cb();
725        }
726      }
727    });
728  }
729
730  function hideStickyFooter() {
731    isStickyFooterVisible = false;
732    $.Velocity(cdpcpEl, "stop");
733    $.Velocity(cdpcpEl, {
734      translateY: ["140%", getStickyFooterOffset()],
735      translateZ: 0
736    }, {
737      display: "none",
738      duration: 300,
739      easing: animationEasings._exitScreen,
740      complete: function complete() {
741        cdpcpEl.style.transform = "";
742        $(doc.body).removeClass("cdpcp-show-sticky-footer");
743      }
744    });
745  }
746
747  function hideStickyFooterProduct(idProduct, cb) {
748    var compareProductEl = doc.getElementById("cdpcp-item-" + idProduct);
749    var animateFromWidth;
750
751    if (!compareProductEl) {
752      if (typeof cb === "function") {
753        cb();
754      }
755
756      return false;
757    }
758
759    animateFromWidth = compareProductEl.offsetWidth;
760    $.Velocity(compareProductEl, "stop");
761    $.Velocity(compareProductEl, {
762      opacity: [0, 1],
763      transformOriginX: ["50%", "50%"],
764      transformOriginY: ["50%", "50%"],
765      scaleX: [0.625, 1],
766      scaleY: [0.625, 1],
767      translateZ: 0
768    }, {
769      duration: 200,
770      easing: animationEasings._default
771    });
772    $.Velocity(compareProductEl, {
773      width: [0, animateFromWidth],
774      translateZ: 0
775    }, {
776      display: "none",
777      duration: 200,
778      easing: animationEasings._default,
779      complete: function complete() {
780        if (typeof cb === "function") {
781          cb();
782        }
783      }
784    });
785
786    if (isStickyFooterVisible && !window.cdpcpNumCompareProducts) {
787      hideStickyFooter();
788    }
789  }
790
791  function removeStickyFooterProduct(idProduct) {
792    removeElements(doc.getElementById("cdpcp-item-" + idProduct));
793  }
794
795  function removeAllStickyFooterProducts() {
796    if (cdpcpEl) {
797      removeElements(cdpcpEl.getElementsByClassName("cdpcp__item"));
798    }
799  }
800
801  function showStickyFooterProduct(idProduct) {
802    var compareProductEl = doc.getElementById("cdpcp-item-" + idProduct);
803    var animateToWidth;
804
805    if (!compareProductEl) {
806      return false;
807    }
808
809    // Can't easily get width without jQuery because the element
810    // isn't visible yet
811    animateToWidth = $(compareProductEl).width();
812    $.Velocity(compareProductEl, "stop");
813    $.Velocity(compareProductEl, {
814      width: [animateToWidth, 0],
815      translateZ: 0
816    }, {
817      display: "inline-block",
818      duration: 200,
819      easing: animationEasings._default
820    });
821    $.Velocity(compareProductEl, {
822      opacity: [1, 0],
823      transformOriginX: ["50%", "50%"],
824      transformOriginY: ["50%", "50%"],
825      scaleX: [1, 0.625],
826      scaleY: [1, 0.625],
827      translateZ: 0
828    }, {
829      duration: 200,
830      easing: animationEasings._default,
831      complete: function complete() {
832        // Remove inline styles set by velocity - prevents slideouts
833        // from messing up
834        compareProductEl.removeAttribute("style");
835      }
836    });
837
838    if (!isStickyFooterVisible) {
839      showStickyFooter();
840    }
841  }
842
843  /*============================================================================
844  SLIDEOUT FUNCTIONS
845  ============================================================================*/
846
847  function openSlideout(slideoutEl) {
848    var slideoutCloneEl = slideoutEl.cloneNode(true);
849    doc.body.appendChild(slideoutCloneEl);
850    $.Velocity(slideoutCloneEl, "slideDown", {
851      display: "block",
852      duration: 350,
853      easing: animationEasings._enterScreen,
854      begin: function begin() {
855        var backdropEl = doc.getElementById("cdpcp-backdrop");
856
857        if (backdropEl) {
858          $.Velocity(backdropEl, "fadeIn", 350);
859        }
860
861        Scrollbar$1.hide();
862      },
863      complete: function complete() {
864        $(slideoutCloneEl).addClass("cdpcp__slideout--open");
865      }
866    });
867  }
868
869  function closeSlideout(cb) {
870    var slideoutEl = doc.getElementsByClassName("cdpcp__slideout--open")[0] || null;
871    var backdropEl = doc.getElementById("cdpcp-backdrop");
872
873    if (backdropEl) {
874      $.Velocity(backdropEl, "fadeOut", 350);
875    }
876
877    if (slideoutEl) {
878      $.Velocity(slideoutEl, "slideUp", {
879        duration: 350,
880        easing: animationEasings._exitScreen,
881        complete: function complete() {
882          Scrollbar$1.show();
883          removeElements(slideoutEl);
884
885          if (typeof cb === "function") {
886            cb();
887          }
888        }
889      });
890    } else {
891      if (typeof cb === "function") {
892        cb();
893      }
894    }
895  }
896
897  /*============================================================================
898  TABLE HIGHLIGHTING FUNCTIONS
899  ============================================================================*/
900
901  function getRowsByDifferences() {
902    var featureTrEls = doc.getElementById("cdpcp-table").getElementsByClassName("cdpcp-table__feature-row");
903    var rowsWithDifferences = [];
904    var rowsWithoutDifferences = [];
905
906    for (var i = featureTrEls.length; i--;) {
907      var trEl = featureTrEls[i];
908      var tdEls = trEl.getElementsByTagName("td");
909
910      // Assume false by default, and we'll update to true if/when we find a difference
911      var rowHasDifferences = false;
912      var valueToCompare = null;
913
914      for (var j = tdEls.length; j--;) {
915        var tdEl = tdEls[j];
916        var tdText = (tdEl.textContent || tdEl.innerText).trim().replace(/[\s]+/g, " ");
917
918        if (valueToCompare) {
919          if (tdText !== valueToCompare) {
920            rowHasDifferences = true;
921
922            // We know the row has differences, no need to check further
923            break;
924          }
925        } else {
926          // Set the value that we want to compare subsequent tds to
927          valueToCompare = tdText;
928        }
929      }
930
931      if (rowHasDifferences) {
932        rowsWithDifferences.push(trEl);
933      } else {
934        rowsWithoutDifferences.push(trEl);
935      }
936    }
937
938    return {
939      _rowsWithDifferences: rowsWithDifferences,
940      _rowsWithoutDifferences: rowsWithoutDifferences
941    };
942  }
943
944  function addTableHighlighting() {
945    var rowsByDifferences = getRowsByDifferences();
946    var highlightEls;
947
948    if (tableDiffType === 1) {
949      highlightEls = rowsByDifferences._rowsWithoutDifferences;
950    } else if (tableDiffType === 2) {
951      highlightEls = rowsByDifferences._rowsWithDifferences;
952    }
953
954    if (highlightEls) {
955      $(highlightEls).addClass("cdpcp-highlight");
956    }
957  }
958
959  function removeTableHighlighting() {
960    $(doc.getElementById("cdpcp-table").getElementsByClassName("cdpcp-highlight")).removeClass("cdpcp-highlight");
961  }
962
963  function toggleTableRowVis(showOrHide) {
964    var showRows = showOrHide === "show";
965    var rowsByDifferences = getRowsByDifferences();
966    var highlightBtnEl = doc.getElementById("cdpcp-highlight-btn");
967    var rowsToHideEls;
968    var cellEls;
969    var innerCellEls;
970    var animatedEls = []; // Combination of cellEls and innerCellEls
971
972    if (tableDiffType === 3) {
973      rowsToHideEls = rowsByDifferences._rowsWithoutDifferences;
974    } else if (tableDiffType === 4) {
975      rowsToHideEls = rowsByDifferences._rowsWithDifferences;
976    }
977
978    cellEls = $(rowsToHideEls).children(".cdpcp-table__feature-cell").get();
979    innerCellEls = $(rowsToHideEls).find(".cdpcp-table__cell-inner").get();
980    animatedEls = cellEls.concat(innerCellEls);
981    highlightBtnEl.disabled = true;
982
983    if (showRows) {
984      $.Velocity(animatedEls, "reverse", {
985        display: "",
986        duration: 300,
987        easing: animationEasings._default,
988        complete: function complete() {
989          $.Velocity(innerCellEls, {
990            opacity: [1, 0],
991            transformOriginX: ["50%", "50%"],
992            transformOriginY: ["50%", "50%"],
993            scaleX: [1, 0.625],
994            scaleY: [1, 0.625],
995            translateZ: 0
996          }, {
997            duration: 300,
998            easing: animationEasings._default,
999            complete: function complete() {
1000              highlightBtnEl.disabled = null;
1001            }
1002          });
1003        }
1004      });
1005    } else {
1006      $.Velocity(innerCellEls, {
1007        opacity: [0, 1],
1008        transformOriginX: ["50%", "50%"],
1009        transformOriginY: ["50%", "50%"],
1010        scaleX: [0.625, 1],
1011        scaleY: [0.625, 1],
1012        translateZ: 0
1013      }, {
1014        duration: 300,
1015        easing: animationEasings._default,
1016        complete: function complete() {
1017          $.Velocity(animatedEls, {
1018            borderWidth: 0,
1019            padding: 0,
1020            height: 0,
1021            translateZ: 0
1022          }, {
1023            display: "none",
1024            duration: 300,
1025            easing: animationEasings._default,
1026            complete: function complete() {
1027              highlightBtnEl.disabled = null;
1028            }
1029          });
1030        }
1031      });
1032    }
1033  }
1034
1035  /*============================================================================
1036  AJAX FUNCTIONS
1037  ============================================================================*/
1038
1039  function ajaxAddProduct(idProduct, addVisually) {
1040    return $.ajax({
1041      cache: false, // Ensures we don't get a cached response
1042      url: prestashop.urls.pages.index,
1043      data: {
1044        action: "add",
1045        ajax: true,
1046        controller: "compare",
1047        fc: "module",
1048        id_product: idProduct,
1049        module: "cdproductcomparisonplus",
1050        token: window.cdpcpToken
1051      },
1052      dataType: "json",
1053      type: "GET",
1054      timeout: ajaxTimeout
1055    }).done(function (data) {
1056      if (data && data.status === "Success") {
1057        var productItemsEl = doc.getElementById("cdpcp-items");
1058        window.cdpcpProductIds.push(idProduct);
1059
1060        if (productItemsEl) {
1061          var temp = doc.createElement("div");
1062          var productEl;
1063          temp.innerHTML = data.response;
1064
1065          productEl = function getFirstElChild(el) {
1066            var firstChild = el.firstChild;
1067
1068            // Skip non-element node types
1069            while (firstChild !== null && firstChild.nodeType !== 1) {
1070              firstChild = firstChild.nextSibling;
1071            }
1072
1073            return firstChild;
1074          }(temp);
1075
1076          productItemsEl.insertBefore(productEl, productItemsEl.firstChild);
1077          productEl.style.display = "none";
1078          productEl.style.opacity = 0;
1079
1080          if (addVisually) {
1081            showStickyFooterProduct(idProduct);
1082          }
1083        }
1084
1085        updateAllCounts(window.cdpcpNumCompareProducts + 1);
1086      } else {
1087        displayErrorMessage(data.status === "Error" ? data.response : window.cdpcpAjaxErrorMsg);
1088      }
1089    }).fail(function (data) {
1090      displayErrorMessage(data.responseJSON && data.responseJSON.status === "Error" ? data.responseJSON.response : window.cdpcpAjaxErrorMsg);
1091    });
1092  }
1093
1094  function ajaxRemoveProduct(idProduct, removeVisually) {
1095    updateAllCounts(window.cdpcpNumCompareProducts - 1);
1096
1097    if (removeVisually) {
1098      hideStickyFooterProduct(idProduct, function () {
1099        return removeStickyFooterProduct(idProduct);
1100      });
1101    }
1102
1103    return $.ajax({
1104      cache: false, // Ensures we don't get a cached response
1105      url: prestashop.urls.pages.index,
1106      data: {
1107        action: "remove",
1108        ajax: true,
1109        controller: "compare",
1110        fc: "module",
1111        id_product: idProduct,
1112        module: "cdproductcomparisonplus",
1113        token: window.cdpcpToken
1114      },
1115      dataType: "json",
1116      type: "GET",
1117      timeout: ajaxTimeout
1118    }).done(function (data) {
1119      if (data && data.status === "Success") {
1120        window.cdpcpProductIds.splice(window.cdpcpProductIds.indexOf(idProduct), 1);
1121
1122        // Display error message and revert pre-emptive changes we fired
1123      } else {
1124        displayErrorMessage(data.status === "Error" ? data.response : window.cdpcpAjaxErrorMsg);
1125        updateAllCounts(window.cdpcpNumCompareProducts + 1);
1126
1127        // Something went wrong - reshow the product
1128        if (removeVisually) {
1129          addProduct(idProduct);
1130        }
1131      }
1132    }).fail(function (data) {
1133      displayErrorMessage(data.responseJSON && data.responseJSON.status === "Error" ? data.responseJSON.response : window.cdpcpAjaxErrorMsg);
1134      updateAllCounts(window.cdpcpNumCompareProducts + 1);
1135
1136      // Something went wrong - reshow the product
1137      if (removeVisually) {
1138        addProduct(idProduct);
1139      }
1140    });
1141  }
1142
1143  function ajaxRemoveAllProducts() {
1144    hideStickyFooter();
1145    return $.ajax({
1146      cache: false, // Ensures we don't get a cached response
1147      url: prestashop.urls.pages.index,
1148      data: {
1149        action: "removeall",
1150        ajax: true,
1151        controller: "compare",
1152        fc: "module",
1153        module: "cdproductcomparisonplus",
1154        token: window.cdpcpToken
1155      },
1156      dataType: "json",
1157      type: "GET",
1158      timeout: ajaxTimeout
1159    }).done(function (data) {
1160      if (data && data.status === "Success") {
1161        window.cdpcpProductIds = [];
1162        removeAllStickyFooterProducts();
1163        $(doc.getElementsByClassName("cdpcp-compare-btn--remove")).removeClass("cdpcp-compare-btn--remove").addClass("cdpcp-compare-btn--add");
1164        updateAllCounts(0);
1165      } else {
1166        displayErrorMessage(data.status === "Error" ? data.response : window.cdpcpAjaxErrorMsg);
1167        showStickyFooter();
1168      }
1169    }).fail(function (data) {
1170      displayErrorMessage(data.responseJSON && data.responseJSON.status === "Error" ? data.responseJSON.response : window.cdpcpAjaxErrorMsg);
1171      showStickyFooter();
1172    });
1173  }
1174
1175  /*============================================================================
1176  UTILITY FUNCTIONS
1177  ============================================================================*/
1178
1179  function getObjFromParamStr(paramStr) {
1180    var paramsObj = {};
1181    var splitStrSeg;
1182    paramStr = paramStr.replace(/^\?/, "").split("&");
1183
1184    for (var i = paramStr.length - 1; i >= 0; i--) {
1185      if (paramStr[i]) {
1186        splitStrSeg = paramStr[i].split("=");
1187        paramsObj[splitStrSeg[0]] = splitStrSeg[1];
1188      }
1189    }
1190
1191    return paramsObj;
1192  }
1193
1194  function getParamStrFromObj(paramObj) {
1195    var paramPairs = [];
1196
1197    for (var param in paramObj) {
1198      if (paramObj.hasOwnProperty(param)) {
1199        paramPairs.push("".concat(param, "=").concat(paramObj[param]));
1200      }
1201    }
1202
1203    return "?".concat(paramPairs.join("&"));
1204  }
1205
1206  function removeProductFromUrl(idProduct) {
1207    var urlParams = getObjFromParamStr(window.location.search);
1208    var productsParam = urlParams.products;
1209
1210    if (!productsParam) {
1211      return false;
1212    }
1213
1214    var productsArr = productsParam.split("-");
1215    var idProductIndex = productsArr.indexOf(idProduct);
1216    var newParamsStr = "";
1217
1218    if (idProductIndex !== -1) {
1219      productsArr.splice(idProductIndex, 1);
1220
1221      if (productsArr.length) {
1222        urlParams.products = productsArr.join("-");
1223      } else {
1224        // Manually set to 0 (i.e. ?products=0) so we don't switch
1225        // to a saved comparison if they deleted the last from a
1226        // url-based comparison. Avoids confusion.
1227        urlParams.products = "0";
1228      }
1229
1230      if (Object.keys(urlParams).length) {
1231        newParamsStr = getParamStrFromObj(urlParams);
1232      }
1233
1234      window.location = window.location.href.split("?")[0] + newParamsStr;
1235    }
1236  }
1237
1238  function updateAllCounts(numCompareProducts) {
1239    _updateCompareButtonCount(numCompareProducts);
1240
1241    _updateStickyFooterCount(numCompareProducts);
1242
1243    window.cdpcpNumCompareProducts = numCompareProducts;
1244  }
1245
1246  function displayErrorMessage(msg) {
1247    var msgDuration = 15000;
1248
1249    if (typeof $.growl === "function") {
1250      $.growl.error({
1251        message: msg,
1252        duration: msgDuration
1253      });
1254    } else {
1255      window.alert(msg);
1256    }
1257  }
1258
1259  function openComparePopup(fallbackUrl) {
1260    $.ajax({
1261      cache: false, // Ensures we don't get a cached response
1262      url: prestashop.urls.pages.index,
1263      data: {
1264        action: "getcomparetable",
1265        ajax: true,
1266        controller: "compare",
1267        fc: "module",
1268        module: "cdproductcomparisonplus"
1269      },
1270      dataType: "json",
1271      type: "GET"
1272    }).done(function (data) {
1273      if (data && data.response) {
1274        var productModal;
1275        $(doc.body).append(data.response);
1276        productModal = $(doc.getElementById("cdpcp-compare-modal"));
1277        productModal.modal("show").on("hidden.bs.modal", function () {
1278          return productModal.remove();
1279        });
1280        bindComparisonTableHandlers();
1281      } else {
1282        window.location = fallbackUrl;
1283      }
1284    }).fail(function () {
1285      window.location = fallbackUrl;
1286    });
1287  }
1288
1289  /*============================================================================
1290  INTERNAL FUNCTIONS
1291  ============================================================================*/
1292
1293  function _updateCompareButtonCount(numCompareProducts) {
1294    var compareCountEl = doc.getElementById("cdpcp-compare-now-count");
1295    var mainCompareNowEl = doc.getElementById("cdpcp-compare-now-main");
1296
1297    if (compareCountEl) {
1298      compareCountEl.innerHTML = numCompareProducts;
1299    }
1300
1301    if (mainCompareNowEl) {
1302      mainCompareNowEl.disabled = !numCompareProducts;
1303    }
1304  }
1305
1306  function _updateStickyFooterCount(numCompareProducts) {
1307    var menuNumberEl = doc.getElementById("cdpcp-menu-number");
1308
1309    if (menuNumberEl) {
1310      menuNumberEl.innerHTML = numCompareProducts;
1311    }
1312  }
1313});

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.