boost-pfs-filter.js

PHOTO EMBED

Tue Jan 11 2022 14:11:08 GMT+0000 (UTC)

Saved by @brentvanholder #javascript

// Override Settings
var boostPFSFilterConfig = {
  general: {
    limit: boostPFSConfig.custom.products_per_page,
    // Optional
    loadProductFirst: false,
  },
}

// Declare Templates
var boostPFSTemplate = {
  saleLabelHtml:
    '<div class="sale_banner">' + boostPFSConfig.label.sale + "</div>",
  newLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.newlabel + "</div>",
  partyLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.partylabel + "</div>",
  duurzaamLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.duurzaamlabel + "</div>",
  giftLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.giftlabel + "</div>",
  comingLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.cominglabel + "</div>",
  label1LabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.label1 + "</div>",
  label2LabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.label2 + "</div>",
  label3LabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.label3 + "</div>",
  preorderLabelHtml:
    '<div class="new_banner">' + boostPFSConfig.label.preorder + "</div>",
  reviewHtml:
    '<span class="shopify-product-reviews-badge" data-id="{{itemId}}"></span>',
  vendorHtml:
    '<div class="vendor"><span itemprop="brand">{{itemVendorLabel}}</span></div>',
  quickViewBtnHtml:
    '<span data-fancybox-href="#product-{{itemId}}" class="quick_shop ss-icon" data-gallery="product-{{itemId}}-gallery"><span class="icon-plus">Quick view</span></span>',
  newRowHtml: '<br class="clear product_clear" />',

  // Grid Template
  productGridItemHtml:
    '<div data-boost-pfs-theme-quickview="{{itemId}}" data-product-id="{{itemId}}" class="{{itemColumnNumberClass}} {{itemCollectionGroupThumbClass}} thumbnail {{itemCollectionGroupMobileClass}}" data-product-id="{{itemId}}" itemprop="itemListElement" itemscope itemtype="http://schema.org/Product">' +
    `<div class="ssw-faveiticon sswfaveicon{{itemId}}">
				<i data-product-id="{{itemId}}" data-count="0" class="ssw-icon-heart-o ssw-fave-icon ssw-wishlist-element ssw-not-synch"
					title="{{ 'socialshopwave.fave' | t }}"
					data-params='{"product_id":"{{itemId}}","event":"fave_button","page":"product_profile"}'></i>
				<span class="faves-count">...</span>
			</div>` +
    '<a href="{{itemUrl}}" itemprop="url">' +
    '<div class="relative product_image">' +
    "{{itemSaleLabel}}" +
    "{{discountPercentageLabel}}" +
    '<div class="product_container swap-' +
    boostPFSConfig.custom.collection_secondary_image +
    '">' +
    "{{itemImages}}" +
    "</div>" +
    "</div>" +
    '<div class="info">' +
    '<span class="title" itemprop="name">{{itemTitle}}</span>' +
    "{{itemVendor}}" +
    "{{itemReview}}" +
    "{{itemPrice}}" +
    "</div>" +
    '<div class="banner_holder">' +

    "{{itemNewLabel}}" +
    "{{itemPartyLabel}}" +
    "{{itemDuurzaamLabel}}" +
    "{{itemGiftLabel}}" +
    "{{itemComingLabel}}" +
    "{{itemLabel1Label}}" +
    "{{itemLabel2Label}}" +
    "{{itemLabel3Label}}" +
    "{{itemPreorderLabel}}" +
    "</div>" +
    "</a>" +
    "{{itemSwatches}}" +
    "</div>" +
    "{{itemNewRow}}",

  // Pagination Template
  previousHtml:
    '<span class="prev"><a href="{{itemUrl}}">« ' +
    boostPFSConfig.label.paginate_prev +
    "</a></span>",
  nextHtml:
    '<span class="next"><a href="{{itemUrl}}">' +
    boostPFSConfig.label.paginate_next +
    " »</a></span>",
  pageItemHtml:
    '<span class="page"><a href="{{itemUrl}}">{{itemTitle}}</a></span>',
  pageItemSelectedHtml: '<span class="page current">{{itemTitle}}</span>',
  pageItemRemainHtml: "<span>{{itemTitle}}</span>",
  paginateHtml: "{{previous}}{{pageItems}}{{next}}",

  // Sorting Template
  sortingHtml:
    '<select id="sort-by" class="boost-pfs-filter-top-sorting-select" data-default-sort="' +
    boostPFSConfig.general.default_sort_by +
    '">{{sortingItems}}</select>',
}

;(function () {
  BoostPFS.inject(this)

  // This seems to fix the loading issue of the button on iPhone 11. Utils seems to get overwritten somehow which makes some functions of Utils undefined === errors
  let _utils = Utils

  // Build Product Grid Item
  ProductGridItem.prototype.compileTemplate = function (data, index) {
    if (!data) data = this.data
    if (!index) index = this.index + 1

    /*** Prepare data ***/
    var images = data.images_info
    // Displaying price base on the policy of Shopify, have to multiple by 100
    var soldOut = !data.available // Check a product is out of stock
    var onSale = data.compare_at_price_min > data.price_min // Check a product is on sale
    var priceVaries = data.price_min != data.price_max // Check a product has many prices
    // Get First Variant (selected_or_first_available_variant)
    var firstVariant = data["variants"][0]
    if (_utils.getParam) {
      if (
        _utils.getParam("variant") !== null &&
        _utils.getParam("variant") != ""
      ) {
        var paramVariant = data.variants.filter(function (e) {
          return e.id == _utils.getParam("variant")
        })
        if (typeof paramVariant[0] !== "undefined")
          firstVariant = paramVariant[0]
      } else {
        for (var i = 0; i < data["variants"].length; i++) {
          if (data["variants"][i].available) {
            firstVariant = data["variants"][i]
            break
          }
        }
      }
    }

    /*** End Prepare data ***/

    var itemHtml = boostPFSTemplate.productGridItemHtml

    var onSaleClass = onSale ? "sale" : ""
    var soldOutClass = soldOut ? "out_of_stock" : "in_stock"

    var itemColumnNumberClass = ""
    var itemCollectionGroupThumbClass = buildItemCollectionGroupThumbClass(
      index,
      boostPFSConfig.custom.products_per_row
    )
    var itemCollectionGroupMobileClass = (index - 1) % 2 == 0 ? "even" : "odd"
    switch (boostPFSConfig.custom.products_per_row) {
      case 2:
        itemColumnNumberClass = boostPFSConfig.custom.show_sidebar
          ? "six columns"
          : "eight columns"
        break
      case 3:
        itemColumnNumberClass = boostPFSConfig.custom.show_sidebar
          ? "four columns"
          : "one-third column"
        break
      default:
        itemColumnNumberClass = boostPFSConfig.custom.show_sidebar
          ? "three columns"
          : "four columns"
        break
    }
    itemHtml = itemHtml.replace(
      /{{itemColumnNumberClass}}/g,
      itemColumnNumberClass
    )
    itemHtml = itemHtml.replace(
      /{{itemCollectionGroupThumbClass}}/g,
      itemCollectionGroupThumbClass
    )
    itemHtml = itemHtml.replace(
      /{{itemCollectionGroupMobileClass}}/g,
      itemCollectionGroupMobileClass
    )

    // Get image source
    var imageSrc =
      'data-src="' + _utils.getFeaturedImage(images, "2048x") + '" '
    imageSrc +=
      'data-srcset=" ' + _utils.getFeaturedImage(images, "2048x") + " 2048w,"
    imageSrc += _utils.getFeaturedImage(images, "1600x") + " 1600w,"
    imageSrc += _utils.getFeaturedImage(images, "1200x") + " 1200w,"
    imageSrc += _utils.getFeaturedImage(images, "1000x") + " 1000w,"
    imageSrc += _utils.getFeaturedImage(images, "800x") + " 800w,"
    imageSrc += _utils.getFeaturedImage(images, "600x") + " 600w,"
    imageSrc += _utils.getFeaturedImage(images, "400x") + ' 400w"'
    // Get Thumbnail url
    var thumbUrl = _utils.getFeaturedImage(images, "100x")
    // Get Flip image url
    var itemFlipImageUrl =
      images.length > 1
        ? _utils.optimizeImage(images[images.length - 1]["src"], "900x")
        : _utils.getFeaturedImage(images, "900x")

    // Add Thumbnail
    if (data.images_info.length > 0) {
      var product_set_width = data.images_info[0].width
    } else {
      var product_set_width = "900"
    }
    var align_height_value = ""
    if (boostPFSConfig.custom.align_height) {
      if (images.length > 0) {
        var collection_height = boostPFSConfig.custom.collection_height
        var product_aspect_ratio = images[0]["width"] / images[0]["height"]
        product_set_width = product_aspect_ratio * collection_height
        if (images[0]["width"] >= images[0]["height"]) {
          var align_height_value = "width: 100%; height: auto;"
        } else {
          var align_height_value = "width: 100%;"
        }
      }
    }
    var itemImagesHtml =
      '<div class="image__container" style="max-width: ' +
      product_set_width +
      'px;">'
    itemImagesHtml +=
      '<img  src="' +
      thumbUrl +
      '"' +
      'alt="{{itemTitle}}" ' +
      'class="lazyload lazyload--fade-in" ' +
      'style="' +
      align_height_value +
      " max-width: " +
      product_set_width +
      'px;" ' +
      'data-sizes="auto" ' +
      imageSrc +
      "/>"
    // Add Flip image
    if (boostPFSConfig.custom.collection_secondary_image) {
      itemImagesHtml += '<div class="image__container" style="max-width: '
      if (images.length > 1) {
        itemImagesHtml += images[1]["width"] + "px"
      } else {
        itemImagesHtml += product_set_width + "px"
      }
      itemImagesHtml += '">'
      itemImagesHtml +=
        '<img src="' +
        itemFlipImageUrl +
        '" class="secondary lazyload" alt="{{itemTitle}}" />'
      itemImagesHtml += "</div>"
    }
    itemImagesHtml += boostPFSConfig.custom.quick_shop_enable
      ? "{{itemQuickViewBtn}}"
      : ""
    itemImagesHtml += "</div>"
    itemHtml = itemHtml.replace(/{{itemImages}}/g, itemImagesHtml)

    // Add Labels
    // Sold Out label
    var itemSoldOutLabel = soldOut ? boostPFSTemplate.soldOutLabelHtml : ""
    itemHtml = itemHtml.replace(/{{itemSoldOutLabel}}/g, itemSoldOutLabel)
    // Sale label
    var itemSaleLabel =
      boostPFSConfig.custom.sale_banner_enabled && onSale
        ? boostPFSTemplate.saleLabelHtml
        : ""
    itemHtml = itemHtml.replace(/{{itemSaleLabel}}/g, itemSaleLabel)

    // Discount percentage label
    var discountPercentageLabel = data.percent_sale_min > 0 || data.tags.includes('hide-discount') ? '<span class="discount-label">' + Math.round(data.percent_sale_min / 5) * 5 + '%</span>' : ''

    itemHtml = itemHtml.replace(/{{discountPercentageLabel}}/g, discountPercentageLabel)

    // New, Coming soon, Pre order label
    var itemNewLabelHtml = "",
        itemPartyLabelHtml = "",
        itemDuurzaamLabelHtml = "",
        itemGiftLabelHtml = "",
        itemComingLabelHtml = "",
        itemLabel1LabelHtml = "",
        itemLabel2LabelHtml = "",
        itemLabel3LabelHtml= "",
        itemPreorderLabelHtml = "";
    if (data.collections) {
      itemNewLabelHtml = data.tags.includes("newlabel") ? boostPFSTemplate.newLabelHtml : ""
      itemPartyLabelHtml = data.tags.includes("partylabel") ? boostPFSTemplate.partyLabelHtml : ""
      itemDuurzaamLabelHtml = data.tags.includes("duurzaamlabel") ? boostPFSTemplate.duurzaamLabelHtml : ""
      itemGiftLabelHtml = data.tags.includes("giftlabel") ? boostPFSTemplate.giftLabelHtml : ""
      itemComingLabelHtml = data.tags.includes("cominglabel") ? boostPFSTemplate.comingLabelHtml : ""
      itemLabel1LabelHtml = data.tags.includes("label1") ? boostPFSTemplate.Label1LabelHtml : ""
      itemLabel2LabelHtml = data.tags.includes("label2") ? boostPFSTemplate.Label2LabelHtml : ""
      itemLabel3LabelHtml = data.tags.includes("label3") ? boostPFSTemplate.Label3LabelHtml : ""
      itemPreorderLabelHtml = data.tags.includes("pre_order") ? boostPFSTemplate.preorderLabelHtml : ""
    }
    itemHtml = itemHtml.replace(/{{itemNewLabel}}/g, itemNewLabelHtml)
    itemHtml = itemHtml.replace(/{{itemPartyLabel}}/g, itemPartyLabelHtml)
    itemHtml = itemHtml.replace(/{{itemDuurzaamLabel}}/g, itemDuurzaamLabelHtml)
    itemHtml = itemHtml.replace(/{{itemGiftLabel}}/g, itemGiftLabelHtml)
    itemHtml = itemHtml.replace(/{{itemComingLabel}}/g, itemComingLabelHtml)
    itemHtml = itemHtml.replace(/{{itemLabel1Label}}/g, itemLabel1LabelHtml)
    itemHtml = itemHtml.replace(/{{itemLabel2Label}}/g, itemLabel2LabelHtml)
    itemHtml = itemHtml.replace(/{{itemLabel3Label}}/g, itemLabel3LabelHtml)
    itemHtml = itemHtml.replace(/{{itemPreorderLabel}}/g, itemPreorderLabelHtml)

    // Add Quick view button
    var itemQuickViewBtnHtml = boostPFSConfig.custom.quick_shop_enable
      ? boostPFSTemplate.quickViewBtnHtml
      : ""
    itemHtml = itemHtml.replace(/{{itemQuickViewBtn}}/g, itemQuickViewBtnHtml)

    // Add Review badge
    var itemReviewHtml = boostPFSConfig.custom.review_enable
      ? boostPFSTemplate.reviewHtml
      : ""
    itemHtml = itemHtml.replace(/{{itemReview}}/g, itemReviewHtml)

    // Add Vendor
    var itemVendorHtml = boostPFSConfig.custom.vendor_enable
      ? boostPFSTemplate.vendorHtml
      : ""
    itemHtml = itemHtml.replace(/{{itemVendor}}/g, itemVendorHtml)

    // Add Price
    var itemPriceHtml = ""
    itemPriceHtml +=
      '<span class="price ' +
      onSaleClass +
      '" itemprop="offers" itemscope itemtype="http://schema.org/Offer">'
    itemPriceHtml +=
      '<meta itemprop="price" content="' +
      _utils.stripHtml(_utils.formatMoney(data.price_min)) +
      '" />'
    itemPriceHtml +=
      '<meta itemprop="priceCurrency" content="' +
      boostPFSConfig.shop.currency +
      '" />'
    itemPriceHtml +=
      '<meta itemprop="seller" content="' + boostPFSConfig.shop.name + '" />'
    itemPriceHtml +=
      '<meta itemprop="availability" content="' + soldOutClass + '" />'
    itemPriceHtml += '<meta itemprop="itemCondition" content="New" />'
    if (!soldOut) {
      if (priceVaries && data.price_min > 0) {
        itemPriceHtml +=
          "<small><em>" + boostPFSConfig.label.from_price + "</em></small> "
      }
      if (data.price_min > 0) {
        itemPriceHtml +=
          '<span class="money">' +
          _utils.formatMoney(data.price_min) +
          "</span>"
      } else {
        itemPriceHtml += boostPFSConfig.label.free_price
      }
    } else {
      itemPriceHtml +=
        '<span class="sold_out">' + boostPFSConfig.label.sold_out + "</span>"
    }
    if (onSale) {
      itemPriceHtml +=
        ' <span class="was_price"><span class="money">' +
        _utils.formatMoney(data.compare_at_price_max) +
        "</span></span>"
    }
    itemPriceHtml += "</span>"
    itemHtml = itemHtml.replace(/{{itemPrice}}/g, itemPriceHtml)

    // Add Color swatches
    var itemSwatchHtml = ""
    if (boostPFSConfig.custom.collection_swatches) {
      for (var k in data.options) {
        if (
          data["options"][k].indexOf("color") > -1 ||
          data["options"][k].indexOf("couleur") > -1
        ) {
          var selectedOption = data["options"][k]
          var values = []
          itemSwatchHtml += '<div class="collection_swatches">'
          for (var i = 0; i < data["variants"].length; i++) {
            var value = data["variants"][i]["option_" + selectedOption]
            if (values.indexOf(value) == -1) {
              values = values.join(",")
              values += "," + value
              values = values.split(",")
              var variantImage = boostPFSConfig.general.no_image_url
              var temp = data.options_with_values.filter(function (e) {
                return e.name == selectedOption
              })
              if (typeof temp[0] !== "undefined") {
                var optionValues = temp[0]["values"].filter(function (e) {
                  return e.title == value
                })
                if (typeof optionValues[0] !== "undefined") {
                  var imageIndex = optionValues[0]["image"]
                  if (typeof data["images"][imageIndex] !== "undefined") {
                    variantImage = data["images"][imageIndex]["src"]
                  }
                }
              }
              if (variantImage !== "") {
                itemSwatchHtml +=
                  '<a href="' +
                  _utils.buildProductItemUrl(data) +
                  "?variant=" +
                  data["variants"][i]["id"] +
                  '" class="swatch">'
                itemSwatchHtml +=
                  '<span data-image="' +
                  _utils.optimizeImage(variantImage, "1024x1024") +
                  '" style="background-color: ' +
                  value +
                  "; background-image: url(" +
                  boostPFSConfig.general.asset_url.replace(
                    "boost-pfs-filter.js",
                    value + "_50x.png"
                  ) +
                  ');"></span>'
                itemSwatchHtml += "</a>"
              }
            }
          }
          itemSwatchHtml += "</div>"
        }
      }
    }
    itemHtml = itemHtml.replace(/{{itemSwatches}}/g, itemSwatchHtml)

    // Add new row
    var itemNewRowHtml =
      index > 0 && index % boostPFSConfig.custom.products_per_row == 0
        ? boostPFSTemplate.newRowHtml
        : ""
    itemHtml = itemHtml.replace(/{{itemNewRow}}/g, itemNewRowHtml)

    // Add main attribute
    itemHtml = itemHtml.replace(/{{itemId}}/g, data.id)
    itemHtml = itemHtml.replace(/{{itemHandle}}/g, data.handle)
    itemHtml = itemHtml.replace(/{{itemTitle}}/g, data.title)
    itemHtml = itemHtml.replace(/{{itemVendorLabel}}/g, data.vendor)
    itemHtml = itemHtml.replace(
      /{{itemUrl}}/g,
      _utils.buildProductItemUrl(data)
    )

    return itemHtml
  }

  // Build advanced class
  function buildItemCollectionGroupThumbClass(index, productsPerRow) {
    var temp = index < productsPerRow ? index : index % productsPerRow
    if (temp == 0) {
      return "omega"
    } else if (temp == 1) {
      return "alpha"
    }
    return ""
  }

  // Build Pagination
  ProductPaginationDefault.prototype.compileTemplate = function (totalProduct) {
    if (!totalProduct) totalProduct = this.totalProduct

    // Get page info
    var currentPage = parseInt(Globals.queryParams.page)
    var totalPage = Math.ceil(totalProduct / Globals.queryParams.limit)

    if (
      Settings.getSettingValue("general.paginationType") == "default" &&
      totalPage > 1
    ) {
      var paginationHtml = boostPFSTemplate.paginateHtml

      // Build Previous
      var previousHtml = currentPage > 1 ? boostPFSTemplate.previousHtml : ""
      previousHtml = previousHtml.replace(
        /{{itemUrl}}/g,
        _utils.buildToolbarLink("page", currentPage, currentPage - 1)
      )
      paginationHtml = paginationHtml.replace(/{{previous}}/g, previousHtml)

      // Build Next
      var nextHtml = currentPage < totalPage ? boostPFSTemplate.nextHtml : ""
      nextHtml = nextHtml.replace(
        /{{itemUrl}}/g,
        _utils.buildToolbarLink("page", currentPage, currentPage + 1)
      )
      paginationHtml = paginationHtml.replace(/{{next}}/g, nextHtml)

      // Create page items array
      var beforeCurrentPageArr = []
      for (
        var iBefore = currentPage - 1;
        iBefore > currentPage - 3 && iBefore > 0;
        iBefore--
      ) {
        beforeCurrentPageArr.unshift(iBefore)
      }
      if (currentPage - 4 > 0) {
        beforeCurrentPageArr.unshift("...")
      }
      if (currentPage - 4 >= 0) {
        beforeCurrentPageArr.unshift(1)
      }
      beforeCurrentPageArr.push(currentPage)

      var afterCurrentPageArr = []
      for (
        var iAfter = currentPage + 1;
        iAfter < currentPage + 3 && iAfter <= totalPage;
        iAfter++
      ) {
        afterCurrentPageArr.push(iAfter)
      }
      if (currentPage + 3 < totalPage) {
        afterCurrentPageArr.push("...")
      }
      if (currentPage + 3 <= totalPage) {
        afterCurrentPageArr.push(totalPage)
      }

      // Build page items
      var pageItemsHtml = ""
      var pageArr = beforeCurrentPageArr.concat(afterCurrentPageArr)
      for (var iPage = 0; iPage < pageArr.length; iPage++) {
        if (pageArr[iPage] == "...") {
          pageItemsHtml += boostPFSTemplate.pageItemRemainHtml
        } else {
          pageItemsHtml +=
            pageArr[iPage] == currentPage
              ? boostPFSTemplate.pageItemSelectedHtml
              : boostPFSTemplate.pageItemHtml
        }
        pageItemsHtml = pageItemsHtml.replace(/{{itemTitle}}/g, pageArr[iPage])
        pageItemsHtml = pageItemsHtml.replace(
          /{{itemUrl}}/g,
          _utils.buildToolbarLink("page", currentPage, pageArr[iPage])
        )
      }
      paginationHtml = paginationHtml.replace(/{{pageItems}}/g, pageItemsHtml)
      return paginationHtml
    }
    return ""
  }

  ProductPaginationLoadMore.prototype.compileTotalTemplate = function () {
    /**
     * If enable the Load previous feature and the evnet type is page:
     * => Get the next loading page is from session storage OR get the next loading page from query param
     */
    // console.log(_utils.isLoadPreviousPagePaginationType())
    if (
      _utils.isLoadPreviousPagePaginationType() &&
      this.parent.eventType == "page"
    ) {
      this.nextPage = parseInt(
        window.sessionStorage.getItem(
          this.settings.sessionStorageCurrentNextPage
        )
      )
    } else {
      this.nextPage = Globals.queryParams.page
    }
    // Set from index
    var from = (this.nextPage - 1) * Globals.queryParams.limit + 1
    if (jQ(Selector.products + " > column").length) {
      from -=
        jQ(Selector.products + " > column").length - Globals.queryParams.limit
    }
    // Set to index
    var product_index = (this.nextPage - 1) * Globals.queryParams.limit + 1
    var to = product_index + this.data.products.length - 1

    return this.getTemplate("total")
      .replace(/{{progressLable}}/g, Labels.loadMoreTotal)
      .replace(/{{ from }}/g, from)
      .replace(/{{ to }}/g, to)
      .replace(/{{ total }}/g, this.totalProduct)
      .replace(/{{class.productLoadMore}}/g, Class.productLoadMore)
  }

  // Build Sorting
  ProductSorting.prototype.compileTemplate = function () {
    var html = ""
    if (boostPFSTemplate.hasOwnProperty("sortingHtml")) {
      var sortingArr = _utils.getSortingList()
      if (sortingArr) {
        // Build content
        var sortingItemsHtml = ""
        for (var k in sortingArr) {
          sortingItemsHtml +=
            '<option value="' + k + '">' + sortingArr[k] + "</option>"
        }
        var html = boostPFSTemplate.sortingHtml.replace(
          /{{sortingItems}}/g,
          sortingItemsHtml
        )
      }
    }
    return html
  }

  // Build Breadcrumb
  Breadcrumb.prototype.compileTemplate = function (colData, apiData) {
    if (!colData) colData = this.colData
    if (!apiData) apiData = this.apiData

    if (
      typeof colData !== "undefined" &&
      colData.hasOwnProperty("collection")
    ) {
      var colInfo = colData.collection

      var breadcrumbHtml =
        '<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="' +
        boostPFSConfig.shop.url +
        '" title="' +
        boostPFSConfig.shop.name +
        '" itemprop="item"><span itemprop="name">' +
        boostPFSConfig.label.breadcrumb_home +
        "</span></a></span>"
      breadcrumbHtml += ' &nbsp;<span class="icon-arrow-right"></span>'
      breadcrumbHtml +=
        ' <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="/collections/' +
        colInfo.handle +
        '" title="{{currentCollectionTitle}}" itemprop="item"><span itemprop="name">{{currentCollectionTitle}}</span></a></span>'
      // Build Tags
      var currentTagsHtml = ""
      if (Array.isArray(boostPFSConfig.general.current_tags)) {
        var current_tags = boostPFSConfig.general.current_tags
        for (var k in current_tags) {
          var tag = current_tags[k]
          currentTagsHtml += ' &nbsp;<span class="icon-arrow-right"></span>'
          currentTagsHtml +=
            ' <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="/collections/{{currentCollectionLink}}" title="' +
            tag +
            '" itemprop="item"><span itemprop="name">' +
            tag +
            "</span></a></span>"
        }
      }
      breadcrumbHtml += currentTagsHtml
      // Build Collection Info
      breadcrumbHtml = breadcrumbHtml
        .replace(/{{currentCollectionLink}}/g, "/collections/" + colInfo.handle)
        .replace(/{{currentCollectionTitle}}/g, colInfo.title)
      // Top Pagination
      // var currentPage = parseInt(Globals.queryParams.page);
      // var totalPage = Math.ceil(apiData.total_product / Globals.queryParams.limit);
      // var topPaginationHtml = ' &nbsp;<span class="icon-arrow-right"></span> ' + (boostPFSConfig.label.breadcrumb_page).replace(/{{ current_page }}/g, Globals.queryParams.page).replace(/{{ pages }}/g, totalPage)
      // breadcrumbHtml += topPaginationHtml;
      breadcrumbHtml +=
        ' <span class="boost-pfs-filter-breadcrumb-page"></span>'

      return breadcrumbHtml
    }
  }

  // Add additional feature for product list, used commonly in customizing product list
  ProductList.prototype.afterRender = function (data) {
    if (!data) data = this.data
    buildTheme()

    if (!_utils.isMobile() && boostPFSConfig.custom.quick_shop_enable) {
      // Build content for Quick view
      ProductList.prototype.buildExtrasProductListByAjax(
        data,
        "boost-pfs-quickview",
        function (results) {
          results.forEach(function (result, index) {
            // Append the custom html to product item
            jQ('[data-boost-pfs-theme-quickview="' + result.id + '"]').append(
              result.quickview_html
            )
            buildTheme()
          })
        }
      )
    }

    buildCurrentPageInBreadcrumb()
  }

  // Build additional elements
  FilterResult.prototype.afterRender = function (data) {
    if (!data) data = this.data

    // Add Wrapper for Product list
    if (jQ(".boost-pfs-filter-products").children().hasClass("products")) {
      jQ(".boost-pfs-filter-products").children().children().unwrap()
    }

    buildCurrentPageInBreadcrumb()
  }

  function buildTheme() {
    collection.init()
    Shopify.PaymentButton.init()
    if (
      boostPFSConfig.custom.show_multiple_currencies &&
      window.convertCurrencies &&
      typeof convertCurrencies == "function"
    ) {
      convertCurrencies()
    }
  }

  function buildCurrentPageInBreadcrumb() {
    // Build Breadcrumb
    var totalPage = Math.ceil(
      Globals.collectionCount / Globals.queryParams.limit
    )
    var topPaginationHtml =
      '&nbsp;<span class="icon-arrow-right"></span> ' +
      boostPFSConfig.label.breadcrumb_page
        .replace(/{{ current_page }}/g, Globals.queryParams.page)
        .replace(/{{ pages }}/g, totalPage)
    jQ(".boost-pfs-filter-breadcrumb-page").html(topPaginationHtml)
  }
})()

/* Begin patch boost-010 run 2 */
Filter.prototype.beforeInit=function(){var t=this.isBadUrl();t&&(this.isInit=!0,window.location.href=window.location.pathname)},Filter.prototype.isBadUrl=function(){try{var t=decodeURIComponent(window.location.search).split("&"),e=!1;if(t.length>0)for(var n=0;n<t.length;n++){var i=t[n],r=(i.match(/</g)||[]).length,a=(i.match(/>/g)||[]).length,o=(i.match(/alert\(/g)||[]).length,h=(i.match(/execCommand/g)||[]).length;if(r>0&&a>0||r>1||a>1||o||h){e=!0;break}}return e}catch(l){return!0}};
/* End patch boost-010 run 2 */
content_copyCOPY