Guest User

Untitled

a guest
Mar 5th, 2021
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var onSale = false;
  2. var soldOut = false;
  3. var priceVaries = false;
  4. var images = [];
  5. var firstVariant = {};
  6.  
  7. // Override Settings
  8. var bcSfFilterSettings = {
  9.     general: {
  10.         limit: bcSfFilterConfig.custom.products_per_page,
  11.         /* Optional */
  12.         loadProductFirst: true
  13.     }
  14. };
  15.  
  16.  
  17. // Declare Templates
  18. var bcSfFilterTemplate = {
  19.     'soldOutClass': ' sold-out',
  20.     'saleClass': ' on-sale',
  21.     'soldOutLabelHtml': '<span class="soldout bc-sf-filter-label">' + bcSfFilterConfig.label_basic.sold_out + '</span>',
  22.     'saleLabelHtml': '<span class="sale bc-sf-filter-label">' + bcSfFilterConfig.label_basic.sale + '</span>',
  23.     'tagLabelHtml': '<span class="tag bc-sf-filter-label {{labelTag}}" >{{labelTag}}</span>',
  24.     'vendorHtml': '<p class="bc-sf-filter-product-item-vendor">{{itemVendorLabel}}</p>',
  25.  
  26.     // Grid Template
  27.     'productGridItemHtml': '<div class="bc-sf-filter-product-item {{gridWidthClass}}{{soldOutClass}}{{saleClass}}">' +
  28.                                 '<div class="bc-sf-filter-product-item-inner">' +
  29.                                     '<a href="{{itemUrl}}" class="bc-sf-filter-product-item-link">' +
  30.                                     '{{itemNewBadge}}'+
  31.                                     '{{itemWishIcon}}' +
  32.                                         '<div class="bc-sf-filter-product-item-image">{{itemImages}}</div>' +
  33.                                         '<div class="bc-sf-filter-product-item-label">{{itemLabels}}{{itemTagLabels}}</div>' +
  34.                                         '<div class="bc-sf-filter-product-bottom">' +
  35.                                             '<p class="bc-sf-filter-product-item-title">{{itemTitle}}</p>' +
  36.                                             '{{itemVendor}}' +
  37.                                             '{{itemPrice}}' +
  38.                                         '</div>' +
  39.                                     '</a>' +
  40.                                 '</div>' +
  41.                             '</div>',
  42.  
  43.     // Pagination Template
  44.     'previousActiveHtml': '<li><a href="{{itemUrl}}">&larr;</a></li>',
  45.     'previousDisabledHtml': '<li class="disabled"><span>&larr;</span></li>',
  46.     'nextActiveHtml': '<li><a href="{{itemUrl}}">&rarr;</a></li>',
  47.     'nextDisabledHtml': '<li class="disabled"><span>&rarr;</span></li>',
  48.     'pageItemHtml': '<li><a href="{{itemUrl}}">{{itemTitle}}</a></li>',
  49.     'pageItemSelectedHtml': '<li><span class="active">{{itemTitle}}</span></li>',
  50.     'pageItemRemainHtml': '<li><span>{{itemTitle}}</span></li>',
  51.     'paginateHtml': '<ul>{{previous}}{{pageItems}}{{next}}</ul>',
  52.  
  53.     // Sorting Template
  54.     'sortingHtml': '<label>' + bcSfFilterConfig.label.sorting + '</label><select class="bc-sf-filter-filter-dropdown">{{sortingItems}}</select>',
  55.  
  56.     // Show Limit Template
  57.     'showLimitHtml': '<label>' + bcSfFilterConfig.label.show_limit + '</label><select class="bc-sf-filter-filter-dropdown">{{showLimitItems}}</select>',
  58.  
  59.     // Breadcrumb Template
  60.     'breadcrumbHtml': '<a href="/">' + bcSfFilterConfig.label.breadcrumb_home + '</a> {{breadcrumbDivider}} {{breadcrumbItems}}',
  61.     'breadcrumbDivider': '<span class="divider">/</span>',
  62.     'breadcrumbItemLink': '<a href="{{itemLink}}">{{itemTitle}}</a>',
  63.     'breadcrumbItemSelected': '<span>{{itemTitle}}</span>',
  64. };
  65.  
  66. /************************** CUSTOMIZE DATA BEFORE BUILDING PRODUCT ITEM **************************/
  67.  
  68. function prepareShopifyData(data) {
  69.      // Displaying price base on the policy of Shopify, have to multiple by 100
  70.     soldOut = !data.available; // Check a product is out of stock
  71.     onSale = data.compare_at_price_min > data.price_min; // Check a product is on sale
  72.     priceVaries = data.price_min != data.price_max; // Check a product has many prices
  73.     // Convert images to array
  74.     images = data.images_info;
  75.     // Get First Variant (selected_or_first_available_variant)
  76.     var firstVariant = data['variants'][0];
  77.     if (getParam('variant') !== null && getParam('variant') != '') {
  78.         var paramVariant = data.variants.filter(function(e) { return e.id == getParam('variant'); });
  79.         if (typeof paramVariant[0] !== 'undefined') firstVariant = paramVariant[0];
  80.     } else {
  81.         for (var i = 0; i < data['variants'].length; i++) {
  82.             if (data['variants'][i].available) {
  83.                 firstVariant = data['variants'][i];
  84.                 break;
  85.             }
  86.         }
  87.     }
  88.     return data;
  89. }
  90.  
  91. /************************** END CUSTOMIZE DATA BEFORE BUILDING PRODUCT ITEM **************************/
  92.  
  93.  
  94. /************************** BUILD PRODUCT LIST **************************/
  95.  
  96. // Build Product Grid Item
  97. BCSfFilter.prototype.buildProductGridItem = function(data, index) {
  98.     // Get Template
  99.     var itemHtml = bcSfFilterTemplate.productGridItemHtml;
  100.  
  101.     // Customize API data to get the Shopify data
  102.     data = prepareShopifyData(data);
  103.  
  104.     // Add Custom class
  105.     var soldOutClass = soldOut ? bcSfFilterTemplate.soldOutClass : '';
  106.     var saleClass = onSale ? bcSfFilterTemplate.saleClass : '';
  107.     itemHtml = itemHtml.replace(/{{soldOutClass}}/g, soldOutClass);
  108.     itemHtml = itemHtml.replace(/{{saleClass}}/g, saleClass);
  109.  
  110.     // Add Grid Width class
  111.     itemHtml = itemHtml.replace(/{{gridWidthClass}}/g, buildGridWidthClass(data));
  112.  
  113.     // Add Label
  114.     itemHtml = itemHtml.replace(/{{itemLabels}}/g, buildLabels(data));
  115.  
  116.     // Add TAG Label
  117.     itemHtml = itemHtml.replace(/{{itemTagLabels}}/g, buildTagLabels(data));
  118.  
  119.     // Add Images
  120.     itemHtml = itemHtml.replace(/{{itemImages}}/g, buildImages(data));
  121.  
  122.     // Add New Badge
  123.     itemHtml = itemHtml.replace(/{{itemNewBadge}}/g, buildNewBadge(data));
  124.  
  125.     // Add WishIcon
  126.     itemHtml = itemHtml.replace(/{{itemWishIcon}}/g, buildWishIcon(data));
  127.  
  128.     // Add Price
  129.     itemHtml = itemHtml.replace(/{{itemPrice}}/g, buildPrice(data));
  130.  
  131.     // Add Vendor
  132.     itemHtml = itemHtml.replace(/{{itemVendor}}/g, buildVendor(data));
  133.  
  134.     // Add main attribute (Always put at the end of this function)
  135.     itemHtml = itemHtml.replace(/{{itemId}}/g, data.id);
  136.     itemHtml = itemHtml.replace(/{{itemTitle}}/g, data.title);
  137.     itemHtml = itemHtml.replace(/{{itemHandle}}/g, data.handle);
  138.     itemHtml = itemHtml.replace(/{{itemVendorLabel}}/g, data.vendor);
  139.     itemHtml = itemHtml.replace(/{{itemUrl}}/g, this.buildProductItemUrl(data));
  140.  
  141.     return itemHtml;
  142. };
  143.  
  144. // Build Product List Item
  145. BCSfFilter.prototype.buildProductListItem = function(data) {};
  146.  
  147. /************************** END BUILD PRODUCT LIST **************************/
  148.  
  149. /************************** BUILD PRODUCT ITEM ELEMENTS **************************/
  150.  
  151. function buildGridWidthClass() {
  152.     var gridWidthClass = '';
  153.     // On PC
  154.     switch (bcSfFilterConfig.custom.products_per_row) {
  155.         case 2: gridWidthClass = 'bc-sf-filter-grid-width-2'; break;
  156.         case 3: gridWidthClass = 'bc-sf-filter-grid-width-3'; break;
  157.         case 5: gridWidthClass = 'bc-sf-filter-grid-width-5'; break;
  158.         default: gridWidthClass = 'bc-sf-filter-grid-width-4'; break;
  159.     }
  160.     // On Mobile
  161.     switch (bcSfFilterConfig.custom.products_per_row_mobile) {
  162.         case 1: gridWidthClass += ' bc-sf-filter-grid-width-mb-1'; break;
  163.         case 3: gridWidthClass += ' bc-sf-filter-grid-width-mb-3'; break;
  164.         default:  gridWidthClass += ' bc-sf-filter-grid-width-mb-2'; break;
  165.     }
  166.     return gridWidthClass;
  167. }
  168. function buildImages(data) {
  169.     var html = '';
  170.     // Build Main Image
  171.     var thumbUrl = images.length > 0 ? bcsffilter.optimizeImage(images[0]['src']) : bcSfFilterConfig.general.no_image_url;
  172.     html += '<img src="' + thumbUrl + '" class="bc-sf-filter-product-item-main-image" />';
  173.     // Build Image Swap
  174.     if(bcSfFilterConfig.custom.active_image_swap){
  175.         var flipImageUrl = images.length > 1 ? bcsffilter.optimizeImage(images[1]['src']) : thumbUrl;
  176.         html += '<img src="' + flipImageUrl + '" class="bc-sf-filter-product-item-flip-image" />';
  177.     }
  178.  
  179.     return html;
  180. }
  181.  
  182. function buildNewBadge(data) {
  183.     var html = '';
  184.  
  185.     if (bcSfFilterConfig.custom.show_new_badge) {
  186.         if (data.tags) {
  187.             for (i = 0; i < data.tags.length; i++) {
  188.                 tag = data.tags[i];                
  189.                 if (tag == "GREY") {
  190.                     html += '<div class="bc-sf-filter-product-item-label"><span class="new_label">NEW</span></div>';
  191.                 }
  192.             }
  193.         }      
  194.     }
  195.  
  196.     return html;
  197. }
  198.  
  199. function buildWishIcon(data) {
  200.     var html = '';
  201.  
  202.     if (bcSfFilterConfig.custom.show_wish_icon) {        
  203.         html += '<div class="bc-sf-filter-product-item-wish"><button class="swym-button swym-add-to-wishlist-view-product product_{{product.id}}" data-swaction="addToWishlist" data-product-id="{{product.id | json}}"></button>x</div>';
  204.     }
  205.    
  206.     return html;
  207. }
  208.  
  209.  
  210. function buildVendor(data) {
  211.     var html = '';
  212.     if (bcSfFilterConfig.custom.show_vendor) {
  213.         html = bcSfFilterTemplate.vendorHtml;
  214.     }
  215.     return html;
  216. }
  217. function buildPrice(data) {
  218.     var html = '';
  219.      var percentage = Math.floor((data.compare_at_price_max - data.price_min) / data.compare_at_price_max * 100);
  220.     if (bcSfFilterConfig.custom.show_price) {
  221.         html = '<p class="bc-sf-filter-product-item-price">';
  222.         if (onSale) {
  223.             html += '<span class="disclaimer">' + percentage + '% OFF</span> - ';
  224.             html += '<s class="disclaimer">' + bcsffilter.formatMoney(data.compare_at_price_min) + '</s> - ';
  225.             html += '<span class="bc-sf-filter-product-item-sale-price">' + bcsffilter.formatMoney(data.price_min) + '</span>';
  226.         } else {
  227.             if (priceVaries) {
  228.                 html += (bcSfFilterConfig.label_basic.from) + ' ';
  229.             }
  230.             html += '<span class="bc-sf-filter-product-item-regular-price">' + bcsffilter.formatMoney(data.price_min) + '</span>';
  231.         }
  232.         html += '</p>';
  233.     }
  234.     return html;
  235. }
  236. function buildLabels(data) {
  237.     // Build Sold out label
  238.     var soldOutLabel = '';
  239.     if (bcSfFilterConfig.custom.show_sold_out_label && soldOut) {
  240.         soldOutLabel = bcSfFilterTemplate.soldOutLabelHtml.replace(/{{style}}/g, '');
  241.     }
  242.     // Build Sale label
  243.     var saleLabel = '';
  244.     if (bcSfFilterConfig.custom.show_sale_label && onSale && !soldOut) {
  245.         saleLabel = bcSfFilterTemplate.saleLabelHtml.replace(/{{style}}/g, '');
  246.     }
  247.     // Build Labels
  248.     var html = soldOutLabel + saleLabel;
  249.     return html
  250. }
  251.  
  252. // BUILD LABEL PRODUCT WITH TAGS
  253. function buildTagLabels(data) {
  254.     showall = false;
  255.  
  256.     if (showall) {
  257.         var tagLabel = '';
  258.         if (data.tags) {
  259.             for (i = 0; i < data.tags.length; i++) {
  260.                 tag = data.tags[i];
  261.                 if(tag.includes("pfs:label")){
  262.                     preTagLabel = bcSfFilterTemplate.tagLabelHtml.replace(/{{labelTag}}/g, tag.split('pfs:label-')[1]);
  263.                     tagLabel += preTagLabel;
  264.                 }
  265.             }
  266.         }
  267.     } else {
  268.         var tagLabel = '';
  269.         if (data.tags) {
  270.             for (i = data.tags.length - 1; i >= 0; i--) {
  271.                 tag = data.tags[i];
  272.                 if (tag.includes("pfs:label")) {
  273.                     preTagLabel = bcSfFilterTemplate.tagLabelHtml.replace(/{{labelTag}}/g, tag.split('pfs:label-')[1]);
  274.                     tagLabel += preTagLabel;
  275.                     break;
  276.                 }
  277.             }
  278.         }
  279.     }
  280.   return tagLabel;
  281. }
  282.  
  283. /************************** END BUILD PRODUCT ITEM ELEMENTS **************************/
  284.  
  285. /************************** BUILD TOOLBAR **************************/
  286.  
  287. // Build Pagination
  288. BCSfFilter.prototype.buildPagination = function(totalProduct) {
  289.     // Get page info
  290.     var currentPage = parseInt(this.queryParams.page);
  291.     var totalPage = Math.ceil(totalProduct / this.queryParams.limit);
  292.  
  293.     // If it has only one page, clear Pagination
  294.     if (totalPage == 1) {
  295.         jQ(this.selector.pagination).html('');
  296.         return false;
  297.     }
  298.  
  299.     if (this.getSettingValue('general.paginationType') == 'default') {
  300.         var paginationHtml = bcSfFilterTemplate.paginateHtml;
  301.  
  302.         // Build Previous
  303.         var previousHtml = (currentPage > 1) ? bcSfFilterTemplate.previousActiveHtml : bcSfFilterTemplate.previousDisabledHtml;
  304.         previousHtml = previousHtml.replace(/{{itemUrl}}/g, this.buildToolbarLink('page', currentPage, currentPage - 1));
  305.         paginationHtml = paginationHtml.replace(/{{previous}}/g, previousHtml);
  306.  
  307.         // Build Next
  308.         var nextHtml = (currentPage < totalPage) ? bcSfFilterTemplate.nextActiveHtml :  bcSfFilterTemplate.nextDisabledHtml;
  309.         nextHtml = nextHtml.replace(/{{itemUrl}}/g, this.buildToolbarLink('page', currentPage, currentPage + 1));
  310.         paginationHtml = paginationHtml.replace(/{{next}}/g, nextHtml);
  311.  
  312.         // Create page items array
  313.         var beforeCurrentPageArr = [];
  314.         for (var iBefore = currentPage - 1; iBefore > currentPage - 3 && iBefore > 0; iBefore--) {
  315.             beforeCurrentPageArr.unshift(iBefore);
  316.         }
  317.         if (currentPage - 4 > 0) {
  318.             beforeCurrentPageArr.unshift('...');
  319.         }
  320.         if (currentPage - 4 >= 0) {
  321.             beforeCurrentPageArr.unshift(1);
  322.         }
  323.         beforeCurrentPageArr.push(currentPage);
  324.  
  325.         var afterCurrentPageArr = [];
  326.         for (var iAfter = currentPage + 1; iAfter < currentPage + 3 && iAfter <= totalPage; iAfter++) {
  327.             afterCurrentPageArr.push(iAfter);
  328.         }
  329.         if (currentPage + 3 < totalPage) {
  330.             afterCurrentPageArr.push('...');
  331.         }
  332.         if (currentPage + 3 <= totalPage) {
  333.             afterCurrentPageArr.push(totalPage);
  334.         }
  335.  
  336.         // Build page items
  337.         var pageItemsHtml = '';
  338.         var pageArr = beforeCurrentPageArr.concat(afterCurrentPageArr);
  339.         for (var iPage = 0; iPage < pageArr.length; iPage++) {
  340.             if (pageArr[iPage] == '...') {
  341.                 pageItemsHtml += bcSfFilterTemplate.pageItemRemainHtml;
  342.             } else {
  343.                 pageItemsHtml += (pageArr[iPage] == currentPage) ? bcSfFilterTemplate.pageItemSelectedHtml : bcSfFilterTemplate.pageItemHtml;
  344.             }
  345.             pageItemsHtml = pageItemsHtml.replace(/{{itemTitle}}/g, pageArr[iPage]);
  346.             pageItemsHtml = pageItemsHtml.replace(/{{itemUrl}}/g, this.buildToolbarLink('page', currentPage, pageArr[iPage]));
  347.         }
  348.         paginationHtml = paginationHtml.replace(/{{pageItems}}/g, pageItemsHtml);
  349.  
  350.         jQ(this.selector.pagination).html(paginationHtml);
  351.     }
  352. };
  353.  
  354. // Build Sorting
  355. BCSfFilter.prototype.buildFilterSorting = function() {
  356.     if (bcSfFilterConfig.custom.show_sorting && bcSfFilterTemplate.hasOwnProperty('sortingHtml')) {
  357.         jQ(this.selector.topSorting).html('');
  358.  
  359.         var sortingArr = this.getSortingList();
  360.         if (sortingArr) {
  361.             // Build content
  362.             var sortingItemsHtml = '';
  363.             for (var k in sortingArr) {
  364.                 sortingItemsHtml += '<option value="' + k +'">' + sortingArr[k] + '</option>';
  365.             }
  366.             var html = bcSfFilterTemplate.sortingHtml.replace(/{{sortingItems}}/g, sortingItemsHtml);
  367.             jQ(this.selector.topSorting).html(html);
  368.             // Set current value
  369.             jQ(this.selector.topSorting + ' select').val(this.queryParams.sort);
  370.         }
  371.     }
  372. };
  373.  
  374. // Build Show Limit
  375. BCSfFilter.prototype.buildFilterShowLimit = function() {
  376.     if (bcSfFilterConfig.custom.show_limit && bcSfFilterTemplate.hasOwnProperty('showLimitHtml')) {
  377.         jQ(this.selector.topShowLimit).html('');
  378.  
  379.         var numberList = this.getSettingValue('general.showLimitList');
  380.         if (numberList != '') {
  381.             // Build content
  382.             var showLimitItemsHtml = '';
  383.             var arr = numberList.split(',');
  384.             for (var k = 0; k < arr.length; k++) {
  385.                 showLimitItemsHtml += '<option value="' + arr[k].trim() +'">' + arr[k].trim() + '</option>';
  386.             }
  387.             var html = bcSfFilterTemplate.showLimitHtml.replace(/{{showLimitItems}}/g, showLimitItemsHtml);
  388.             jQ(this.selector.topShowLimit).html(html);
  389.             // Set value
  390.             jQ(this.selector.topShowLimit + ' select').val(this.queryParams.limit);
  391.         }
  392.     }
  393. };
  394.  
  395. // Build Breadcrumb
  396. BCSfFilter.prototype.buildBreadcrumb = function(colData, apiData) {
  397.     if (bcSfFilterTemplate.hasOwnProperty('breadcrumbHtml')) {
  398.         var breadcrumbItemsHtml = '';
  399.         if (typeof colData !== 'undefined' && colData.hasOwnProperty('collection')) {
  400.             var colInfo = colData.collection;
  401.             if (typeof this.collectionTags !== 'undefined' && this.collectionTags !== null) {
  402.                 breadcrumbItemsHtml += bcSfFilterTemplate.breadcrumbItemLink.replace(/{{itemLink}}/g, '/collections/' + colInfo.handle).replace(/{{itemTitle}}/g, colInfo.title);
  403.                 breadcrumbItemsHtml += " {{breadcrumbDivider}} ";
  404.                 breadcrumbItemsHtml += bcSfFilterTemplate.breadcrumbItemSelected.replace(/{{itemTitle}}/g, this.collectionTags[0]);
  405.             } else {
  406.                 breadcrumbItemsHtml += bcSfFilterTemplate.breadcrumbItemSelected.replace(/{{itemTitle}}/g, colInfo.title);
  407.             }
  408.         } else {
  409.             breadcrumbItemsHtml += bcSfFilterTemplate.breadcrumbItemSelected.replace(/{{itemTitle}}/g, this.getSettingValue('label.defaultCollectionHeader'));
  410.         }
  411.         var html = bcSfFilterTemplate.breadcrumbHtml.replace(/{{breadcrumbItems}}/g, breadcrumbItemsHtml)
  412.         html = html.replace(/{{breadcrumbDivider}}/g, bcSfFilterTemplate.breadcrumbDivider);
  413.         jQ(this.selector.breadcrumb).html(html);
  414.     }
  415. };
  416.  
  417. /************************** END BUILD TOOLBAR **************************/
  418.  
  419. function matchHeightImage() {
  420.     jQ('.bc-sf-filter-product-item-main-image').load(function(){
  421.         var imageContainer = jQ(this).parent();
  422.         imageContainer.css('width', '100%').css('height', $(this).height());
  423.     }).each(function() {
  424.         if(this.complete) jQ(this).load();
  425.     });
  426. }
  427.  
  428. // Build Image Swap
  429. function buildImageSwap() {
  430.     jQ('.bc-sf-filter-product-item-image').each(function() {
  431.         jQ(this).children('img').css({
  432.             'position': 'absolute',
  433.             'top': 0,
  434.             'left': 0,
  435.             'width': '100%'
  436.         })
  437.     });
  438.     jQ('.bc-sf-filter-product-item-main-image').hover(function() {
  439.         jQ(this).css('opacity', 0);
  440.         jQ(this).siblings().show();
  441.     }, function() {
  442.         jQ(this).css('opacity', 1);
  443.         jQ(this).siblings().hide();
  444.     });
  445. }
  446.  
  447. // Add additional feature for product list, used commonly in customizing product list
  448. BCSfFilter.prototype.buildExtrasProductList = function(data, eventType) {};
  449.  
  450. // Build additional elements
  451. BCSfFilter.prototype.buildAdditionalElements = function(data, eventType) {
  452.   this.buildRobotsMetaTag();
  453.           /* Start Initialize BC QuickView */
  454.           if (typeof(bcQuickView) !== 'undefined') {
  455.             if(typeof(bcQuickViewParams) !== 'undefined') {
  456.               bcQuickView.init(bcQuickViewParams);
  457.             } else {
  458.               bcQuickView.init();
  459.             }
  460.           }
  461.           /* End Initialize BC QuickView */
  462.     matchHeightImage();
  463.     jQ(window).resize(function() {
  464.         matchHeightImage();
  465.     })
  466.  
  467.     // Build Image Swap
  468.     if (bcSfFilterConfig.custom.active_image_swap) buildImageSwap();
  469. };
  470.  
  471.     // Build Default layout
  472. function buildDefaultLink(a,b){var c=window.location.href.split("?")[0];return c+="?"+a+"="+b}BCSfFilter.prototype.buildDefaultElements=function(a){if(bcSfFilterConfig.general.hasOwnProperty("collection_count")&&jQ("#bc-sf-filter-bottom-pagination").length>0){var b=bcSfFilterConfig.general.collection_count,c=parseInt(this.queryParams.page),d=Math.ceil(b/this.queryParams.limit);if(1==d)return jQ(this.selector.pagination).html(""),!1;if("default"==this.getSettingValue("general.paginationType")){var e=bcSfFilterTemplate.paginateHtml,f="";f=c>1?bcSfFilterTemplate.hasOwnProperty("previousActiveHtml")?bcSfFilterTemplate.previousActiveHtml:bcSfFilterTemplate.previousHtml:bcSfFilterTemplate.hasOwnProperty("previousDisabledHtml")?bcSfFilterTemplate.previousDisabledHtml:"",f=f.replace(/{{itemUrl}}/g,buildDefaultLink("page",c-1)),e=e.replace(/{{previous}}/g,f);var g="";g=c<d?bcSfFilterTemplate.hasOwnProperty("nextActiveHtml")?bcSfFilterTemplate.nextActiveHtml:bcSfFilterTemplate.nextHtml:bcSfFilterTemplate.hasOwnProperty("nextDisabledHtml")?bcSfFilterTemplate.nextDisabledHtml:"",g=g.replace(/{{itemUrl}}/g,buildDefaultLink("page",c+1)),e=e.replace(/{{next}}/g,g);for(var h=[],i=c-1;i>c-3&&i>0;i--)h.unshift(i);c-4>0&&h.unshift("..."),c-4>=0&&h.unshift(1),h.push(c);for(var j=[],k=c+1;k<c+3&&k<=d;k++)j.push(k);c+3<d&&j.push("..."),c+3<=d&&j.push(d);for(var l="",m=h.concat(j),n=0;n<m.length;n++)"..."==m[n]?l+=bcSfFilterTemplate.pageItemRemainHtml:l+=m[n]==c?bcSfFilterTemplate.pageItemSelectedHtml:bcSfFilterTemplate.pageItemHtml,l=l.replace(/{{itemTitle}}/g,m[n]),l=l.replace(/{{itemUrl}}/g,buildDefaultLink("page",m[n]));e=e.replace(/{{pageItems}}/g,l),jQ(this.selector.pagination).html(e)}}if(bcSfFilterTemplate.hasOwnProperty("sortingHtml")&&jQ(this.selector.topSorting).length>0){jQ(this.selector.topSorting).html("");var o=this.getSortingList();if(o){var p="";for(var q in o)p+='<option value="'+q+'">'+o[q]+"</option>";var r=bcSfFilterTemplate.sortingHtml.replace(/{{sortingItems}}/g,p);jQ(this.selector.topSorting).html(r);var s=void 0!==this.queryParams.sort_by?this.queryParams.sort_by:this.defaultSorting;jQ(this.selector.topSorting+" select").val(s),jQ(this.selector.topSorting+" select").change(function(a){window.location.href=buildDefaultLink("sort_by",jQ(this).val())})}}};
  473.  
  474.     // Customize data to suit the data of Shopify API
  475. BCSfFilter.prototype.prepareProductData=function(data){for(var k=0;k<data.length;k++){data[k]['images']=data[k]['images_info'];if(data[k]['images'].length>0){data[k]['featured_image']=data[k]['images'][0]}else{data[k]['featured_image']={src:bcSfFilterConfig.general.no_image_url,width:'',height:'',aspect_ratio:0}}data[k]['url']='/products/'+data[k].handle;var optionsArr=[];for(var i=0;i<data[k]['options_with_values'].length;i++){optionsArr.push(data[k]['options_with_values'][i]['name'])}data[k]['options']=optionsArr;data[k]['price_min']*=100,data[k]['price_max']*=100,data[k]['compare_at_price_min']*=100,data[k]['compare_at_price_max']*=100;data[k]['price']=data[k]['price_min'];data[k]['compare_at_price']=data[k]['compare_at_price_min'];data[k]['price_varies']=data[k]['price_min']!=data[k]['price_max'];var firstVariant=data[k]['variants'][0];if(getParam('variant')!==null&&getParam('variant')!=''){var paramVariant=data.variants.filter(function(e){return e.id==getParam('variant')});if(typeof paramVariant[0]!=='undefined')firstVariant=paramVariant[0]}else{for(var i=0;i<data[k]['variants'].length;i++){if(data[k]['variants'][i].available){firstVariant=data[k]['variants'][i];break}}}data[k]['selected_or_first_available_variant']=firstVariant;for(var i=0;i<data[k]['variants'].length;i++){var variantOptionArr=[];var count=1;var variant=data[k]['variants'][i];var variantOptions=variant['merged_options'];if(Array.isArray(variantOptions)){for(var j=0;j<variantOptions.length;j++){var temp=variantOptions[j].split(':');data[k]['variants'][i]['option'+(parseInt(j)+1)]=temp[1];data[k]['variants'][i]['option_'+temp[0]]=temp[1];variantOptionArr.push(temp[1])}data[k]['variants'][i]['options']=variantOptionArr}data[k]['variants'][i]['compare_at_price']=parseFloat(data[k]['variants'][i]['compare_at_price'])*100;data[k]['variants'][i]['price']=parseFloat(data[k]['variants'][i]['price'])*100}data[k]['description']=data[k]['content']=data[k]['body_html']}return data};
  476.  
  477. /* boost-start-2.4.2 */
  478. /* If you upgrade the lib to the version >= 2.4.2, please comment the functions below out */
  479. BCSfFilter.prototype.buildRobotsMetaTag = function(data) { var self = this; var metaContent = 'meta[content="noindex,nofollow"]'; if (self.checkIfPFParamsPartOfAURL() === true && jQ('head').find( metaContent).length === 0) { var m = document.createElement('meta'); m.name = 'robots'; m.content = 'noindex,nofollow'; document.head.appendChild(m); } }; BCSfFilter.prototype.checkIfPFParamsPartOfAURL = function() { var self = this; if (window.location.search.length > 0 && window.location.search.indexOf('pf_') > 0) { return true; } return false; };
  480. /* boost-end-2.4.2 */
  481.  
  482. // Fix image url issue of swatch option
  483. function getFilePath(fileName, ext, version) {
  484.     var self = bcsffilter;
  485.     var ext = typeof ext !== 'undefined' ? ext : 'png';
  486.     var version = typeof version !== 'undefined' ? version : '1';
  487.     var prIndex = self.fileUrl.lastIndexOf('?');
  488.     if (prIndex > 0) {
  489.         var filePath = self.fileUrl.substring(0, prIndex);
  490.     } else {
  491.         var filePath = self.fileUrl;
  492.     }
  493.     filePath += fileName + '.' + ext + '?v=' + version;
  494.     return filePath;
  495. }
  496.  
  497. // Build Default layout
  498. BCSfFilter.prototype.buildDefaultElements=function(){var isiOS=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,isSafari=/Safari/.test(navigator.userAgent),isBackButton=window.performance&&window.performance.navigation&&2==window.performance.navigation.type;if(!(isiOS&&isSafari&&isBackButton)){var self=this,url=window.location.href.split("?")[0],searchQuery=self.isSearchPage()&&self.queryParams.hasOwnProperty("q")?"&q="+self.queryParams.q:"";window.location.replace(url+"?view=bc-original"+searchQuery)}};
  499.  
  500.  
  501. BCSfFilter.prototype.getFilterData=function(eventType,errorCount){function BCSend(eventType,errorCount){var self=bcsffilter;var errorCount=typeof errorCount!=="undefined"?errorCount:0;self.showLoading();if(typeof self.buildPlaceholderProductList=="function"){self.buildPlaceholderProductList(eventType)}self.beforeGetFilterData(eventType);self.prepareRequestParams(eventType);self.queryParams["callback"]="BCSfFilterCallback";self.queryParams["event_type"]=eventType;var url=self.isSearchPage()?self.getApiUrl("search"):self.getApiUrl("filter");var script=document.createElement("script");script.type="text/javascript";var timestamp=(new Date).getTime();script.src=url+"?t="+timestamp+"&"+jQ.param(self.queryParams);script.id="bc-sf-filter-script";script.async=true;var resendAPITimer,resendAPIDuration;resendAPIDuration=2e3;script.addEventListener("error",function(e){if(typeof document.getElementById(script.id).remove=="function"){document.getElementById(script.id).remove()}else{document.getElementById(script.id).outerHTML=""}if(errorCount<3){errorCount++;if(resendAPITimer){clearTimeout(resendAPITimer)}resendAPITimer=setTimeout(self.getFilterData("resend",errorCount),resendAPIDuration)}else{self.buildDefaultElements(eventType)}});document.getElementsByTagName("head")[0].appendChild(script);script.onload=function(){if(typeof document.getElementById(script.id).remove=="function"){document.getElementById(script.id).remove()}else{document.getElementById(script.id).outerHTML=""}}}this.requestFilter(BCSend,eventType,errorCount)};BCSfFilter.prototype.requestFilter=function(sendFunc,eventType,errorCount){sendFunc(eventType,errorCount)};
  502.  
  503.  
  504. /* start-boost-2.4.8 */
  505. BCSfFilter.prototype.buildFilterOptionItem=function(html,iLabel,iValue,fOType,fOId,fOLabel,fODisplayType,fOSelectType,fOItemValue,fOData){var keepValuesStatic=fOData.hasOwnProperty("keepValuesStatic")?fOData.keepValuesStatic:false;if(fOType=="review_ratings"&&this.getSettingValue("general.ratingSelectionStyle")=="text"){var title=this.getReviewRatingsLabel(fOItemValue.from)}else{var title=this.customizeFilterOptionLabel(iLabel,fOData.prefix,fOType)}if(keepValuesStatic===true)var productNumber=null;else var productNumber=fOItemValue.hasOwnProperty("doc_count")?fOItemValue.doc_count:0;html=html.replace(/{{itemLabel}}/g,this.buildFilterOptionLabel(iLabel,productNumber,fOData));html=html.replace(/{{itemLink}}/g,this.buildFilterOptionLink(fOId,iValue,fOType,fODisplayType,fOSelectType,keepValuesStatic));html=html.replace(/{{itemValue}}/g,encodeURIParamValue(iValue));html=html.replace(/{{itemTitle}}/g,title);html=html.replace(/{{itemFunc}}/g,"onInteractWithFilterOptionValue(event, this, '"+fOType+"', '"+fODisplayType+"', '"+fOSelectType+"', '"+keepValuesStatic+"')");html=this.checkFilterOptionSelected(fOId,iValue,fOType,fODisplayType)?html.replace(/{{itemSelected}}/g,"selected"):html.replace(/{{itemSelected}}/g,"");var htmlElement=jQ(html);htmlElement.children().attr({"data-id":fOId,"data-value":encodeURIParamValue(iValue),"data-parent-label":fOLabel,"data-title":title,"data-count":productNumber});if(fOType!="collection"){htmlElement.children().attr("rel","nofollow")}if(fOType=="collection")htmlElement.children().attr("data-collection-scope",fOItemValue.key);return jQ(htmlElement)[0].outerHTML};
  506. /* end-boost-2.4.8 */
  507.  
  508. /* Begin patch boost-010 run 2 */
  509. BCSfFilter.prototype.initFilter=function(){return this.isBadUrl()?void(window.location.href=window.location.pathname):(this.updateApiParams(!1),void this.getFilterData("init"))},BCSfFilter.prototype.isBadUrl=function(){try{var t=decodeURIComponent(window.location.search).split("&"),e=!1;if(t.length>0)for(var i=0;i<t.length;i++){var n=t[i],a=(n.match(/</g)||[]).length,r=(n.match(/>/g)||[]).length,o=(n.match(/alert\(/g)||[]).length,h=(n.match(/execCommand/g)||[]).length;if(a>0&&r>0||a>1||r>1||o||h){e=!0;break}}return e}catch(l){return!0}};
  510. /* End patch boost-010 run 2 */
  511.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×