Advertisement
krzxsiek

Ultimate Product Catalog v4.4.42 (fix)

Apr 6th, 2021
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Filtering_Running = "No";
  2.  
  3. jQuery(document).ready(function(){
  4.     jQuery('.ewd-upcp-filtering-toggle').on('click', function() {
  5.         if(jQuery('.ewd-upcp-filtering-toggle').hasClass('ewd-upcp-filtering-toggle-downcaret')){
  6.             jQuery('.ewd-upcp-filtering-toggle').removeClass('ewd-upcp-filtering-toggle-downcaret');
  7.             jQuery('.ewd-upcp-filtering-toggle').addClass('ewd-upcp-filtering-toggle-upcaret');
  8.             jQuery('.prod-cat-sidebar').removeClass('prod-cat-sidebar-hidden');
  9.         }
  10.         else{
  11.             jQuery('.ewd-upcp-filtering-toggle').addClass('ewd-upcp-filtering-toggle-downcaret');
  12.             jQuery('.ewd-upcp-filtering-toggle').removeClass('ewd-upcp-filtering-toggle-upcaret');
  13.             jQuery('.prod-cat-sidebar').addClass('prod-cat-sidebar-hidden');
  14.         }
  15.     });
  16.  
  17.     var thumbContainerWidth = 0,thumbContainerHeight = 0,thumbHolderWidth = 0,thumbImageWidth = 0,thumbImageHeight = 0,numberOfImages = 0;
  18.     var thumbnailHolderContainer,thumbnailControls;
  19.  
  20.     jQuery(".jquery-prod-cat-value").on('change', function() {
  21.         var CatValues = [];
  22.         jQuery('.jquery-prod-cat-value').each(function() {if (jQuery(this).prop('checked')) {CatValues.push(jQuery(this).val());}});
  23.         jQuery('#upcp-selected-categories').val(CatValues);
  24.         UPCP_Dynamic_Disabling(CatValues);
  25.     });
  26.     jQuery(".upcp-jquery-cat-dropdown").on('change', function() {
  27.         var CatValues = [];
  28.         if (jQuery(this).val() != 'All') {CatValues.push(jQuery(this).val());}
  29.         jQuery('#upcp-selected-categories').val(CatValues);
  30.         UPCP_Dynamic_Disabling(CatValues);
  31.     });
  32.     jQuery(".jquery-prod-sub-cat-value").on('change', function() {
  33.         var SubCatValues = [];
  34.         jQuery('.jquery-prod-sub-cat-value').each(function() {if (jQuery(this).prop('checked')) {SubCatValues.push(jQuery(this).val());}});
  35.         jQuery('#upcp-selected-subcategories').val(SubCatValues);
  36.     });
  37.     jQuery(".jquery-prod-tag-value").on('change', function() {
  38.         var TagValues = [];
  39.         jQuery('.jquery-prod-tag-value').each(function() {if (jQuery(this).prop('checked')) {TagValues.push(jQuery(this).val());}});
  40.         jQuery('#upcp-selected-tags').val(TagValues);
  41.     });
  42.     jQuery(".jquery-prod-name-text").on('keyup', function() {
  43.         var prod_name = jQuery(this).val();
  44.         jQuery('#upcp-selected-prod-name').val(prod_name);
  45.     });
  46.  
  47.     screenshotThumbHolderWidth();
  48.     jQuery('.upcp-catalogue-link').on('mouseenter', function() {
  49.       jQuery(this).children('.upcp-prod-desc-custom-fields').fadeIn(400);
  50.     }).on('mouseleave', function(){
  51.       jQuery(this).children('.upcp-prod-desc-custom-fields').fadeOut(400);
  52.     });
  53.     jQuery('.upcp-minimal-img-div').on('mouseenter', function() {
  54.       jQuery(this).children('.upcp-prod-desc-custom-fields').fadeIn(400);
  55.     }).on('mouseleave', function(){
  56.       jQuery(this).children('.upcp-prod-desc-custom-fields').fadeOut(400);
  57.     });
  58.  
  59.     var heights = jQuery('.upcp-minimal-product-listing').map(function ()
  60.     {
  61.         return jQuery(this).height();
  62.     }).get(),
  63.     maxWidgetHeight = Math.max.apply(null, heights);
  64.  
  65.     jQuery('.upcp-minimal-product-listing').each(function (index, value) {
  66.     jQuery(this).height(maxWidgetHeight);
  67.     });
  68.  
  69.     jQuery('.upcp-tab-slide').on('click', function(event) {
  70.         jQuery('.upcp-tabbed-tab').each(function() {jQuery(this).addClass('upcp-Hide-Item');});
  71.         jQuery('.upcp-tabbed-layout-tab').each(function() {jQuery(this).addClass('upcp-tab-layout-tab-unclicked');});
  72.         var TabClass = jQuery(this).data('class');
  73.         jQuery('.'+TabClass).removeClass('upcp-Hide-Item');
  74.         jQuery('.'+TabClass+'-menu').removeClass('upcp-tab-layout-tab-unclicked');
  75.         event.preventDefault;
  76.     });
  77.  
  78.     jQuery('.upcp-tabbed-button-left').on('click', function() {
  79.         jQuery('.upcp-scroll-list li:first').before(jQuery('.upcp-scroll-list li:last'));
  80.         jQuery('.upcp-scroll-list').animate({left:'-=117px'}, 0);
  81.         jQuery('.upcp-scroll-list').animate({left:'+=117px'}, 600);
  82.     });
  83.     jQuery('.upcp-tabbed-button-right').on('click', function() {
  84.         jQuery('.upcp-scroll-list').animate({left:'-=117px'}, 600, function() {
  85.             jQuery('.upcp-scroll-list li:last').after(jQuery('.upcp-scroll-list li:first'));
  86.             jQuery('.upcp-scroll-list').animate({left:'+=117px'}, 0);
  87.         });
  88.     });
  89.  
  90.     jQuery('.upcp-filtering-clear-all').on('click', function() {clearAllFilteringSelections();});
  91.  
  92.     jQuery('#upcp-name-search').on('keyup', function() {jQuery('.upcp-filtering-clear-all').removeClass('upcp-Hide-Item');});
  93.     jQuery('.jquery-prod-cat-value, .jquery-prod-sub-cat-value, .jquery-prod-tag-value, .jquery-prod-cf-value').on('change', function() {jQuery('.upcp-filtering-clear-all').removeClass('upcp-Hide-Item');});
  94.     jQuery('.upcp-jquery-cat-dropdown, .upcp-jquery-subcat-dropdown, .upcp-jquery-tags-dropdown, .jquery-prod-cf-select').on('change', function() {jQuery('.upcp-filtering-clear-all').removeClass('upcp-Hide-Item');});
  95.    
  96.  
  97.     jQuery(window).on('resize', function() {adjustCatalogueHeight();});
  98.  
  99.     UPCP_Infinite_Scroll();
  100.     addClickHandlers();
  101.     addLightboxHandlers();
  102.     addProductcomparisonClickHandlers();
  103.     UPCP_Setup_Price_Slider();
  104.     adjustCatalogueHeight();
  105.     adjustThumbnailHeights();
  106.     addInquiryAndCartHandlers();
  107. });
  108.  
  109. function UPCP_Dynamic_Disabling(CatValues) {
  110.     if (CatValues.length === 0) {jQuery('.jquery-prod-sub-cat-value').prop('disabled', false);}
  111.     else {
  112.         jQuery('.jquery-prod-sub-cat-value').prop('disabled', true);
  113.         jQuery('.jquery-prod-sub-cat-value').each(function() {
  114.             if (jQuery.inArray(jQuery(this).data('parent') + "", CatValues) !== -1) {jQuery(this).prop('disabled', false);}
  115.             else {jQuery(this).parent().removeClass('highlightBlack');}
  116.         });
  117.         jQuery('.jquery-prod-sub-cat-value').each(function() {
  118.             if (jQuery(this).prop('disabled')) {jQuery(this).prop('checked', false);}
  119.         });
  120.         UPCP_Ajax_Filter();
  121.     }
  122. }
  123.  
  124. function UPCP_Infinite_Scroll() {
  125.     if (jQuery('.prod-cat-inner').hasClass('upcp-infinite-scroll')) {
  126.         jQuery(window).scroll(function(){
  127.             var InfinitePos = jQuery('.upcp-infinite-scroll-content-area').position();
  128.             if (InfinitePos != undefined && jQuery('#upcp-max-page').html() != parseInt(jQuery('#upcp-current-page').html())) {
  129.                 if  ((jQuery(window).height() + jQuery(window).scrollTop() > InfinitePos.top) && Filtering_Running == "No"){
  130.                     jQuery('#upcp-current-page').html(Math.min(jQuery('#upcp-max-page').html(), parseInt(jQuery('#upcp-current-page').html())+1));
  131.                     Filtering_Running = "Yes";
  132.                     var AddResults = "Yes";
  133.                     UPCP_Ajax_Filter(AddResults);
  134.                 }
  135.             }
  136.         });
  137.     }
  138. }
  139.  
  140. function addLightboxHandlers() {
  141.     jQuery('.prod-cat-item.upcp-lightbox-mode').on('click', function(event) {
  142.         var Item_ID = jQuery(this).data('itemid');
  143.         var Product_Item = jQuery('#prod-cat-list-item-'+Item_ID);
  144.  
  145.         if (jQuery(event.target).hasClass('upcp-list-title')) {return;}
  146.  
  147.         jQuery('#upcp-lightbox-div').css('display', 'inline');
  148.         jQuery('#upcp-lightbox-close-div').css('display', 'block');
  149.         jQuery('#upcp-lightbox-background-div').css('display', 'inline');
  150.         jQuery('#upcp-lightbox-div-img').attr('src', jQuery(Product_Item).find('.prod-cat-thumb-image').attr('src'));
  151.         jQuery('#upcp-lightbox-title-div').html(jQuery(Product_Item).find('.prod-cat-title').html());
  152.         jQuery('#upcp-lightbox-price-div').html(jQuery(Product_Item).find('.prod-cat-price').html());
  153.         jQuery('#upcp-lightbox-description-div').html(jQuery(Product_Item).find('.prod-cat-desc').html());
  154.         jQuery('#upcp-lightbox-link-container-div a').attr('href', jQuery(Product_Item).find('.upcp-catalogue-link').attr('href'));
  155.     });
  156.  
  157.     jQuery('#upcp-lightbox-background-div').on('click.closeLightboxMode', function() {
  158.         jQuery('#upcp-lightbox-div').css('display', 'none');
  159.         jQuery('#upcp-lightbox-background-div').css('display', 'none');
  160.         jQuery('#upcp-lightbox-close-div').css('display', 'none');
  161.     });
  162.     jQuery('#upcp-lightbox-close-div').on('click.closeLightboxMode', function() {
  163.         jQuery('#upcp-lightbox-div').css('display', 'none');
  164.         jQuery('#upcp-lightbox-background-div').css('display', 'none');
  165.         jQuery('#upcp-lightbox-close-div').css('display', 'none');
  166.     });
  167. }
  168.  
  169. function screenshotThumbHolderWidth(){
  170.     var screenshotImage = jQuery('.prod-cat-addt-details-thumbs-div img:first-child');
  171.     var thumbnailHolderContainer = jQuery('.game-thumbnail-holder');
  172.  
  173.     thumbImageWidth = screenshotImage.width();
  174.     thumbImageHeight = screenshotImage.height();
  175.     numberOfImages = jQuery('.prod-cat-addt-details-thumb').length;
  176.     thumbContainerWidth = (thumbImageWidth+20)*numberOfImages;
  177.     thumbnailHolderContainerW = thumbnailHolderContainer.width();
  178.     thumbnailControls = jQuery('.thumbnail-control');
  179.     //jQuery('.prod-cat-addt-details-thumbs-div').css({width:thumbContainerWidth,height:thumbImageHeight+20,position:"absolute",top:0,left:0});
  180.     //jQuery(thumbnailHolderContainer).css({minHeight:thumbImageHeight+20,width:thumbContainerWidth});
  181.  
  182.     if(thumbContainerWidth > thumbnailHolderContainerW){
  183.         thumbnailControls.show();
  184.         var tnScrollerW = jQuery(".thumbnail-scroller").width();
  185.         var tnHolderDiv = jQuery(".prod-cat-addt-details-thumbs-div").width();
  186.         var tnScrollLimit = -tnHolderDiv + tnScrollerW + thumbImageWidth;
  187.         jQuery('.thumbnail-nav-left').on('click', function() {
  188.             var tnContainerPos = thumbnailHolderContainer.position();
  189.             var tnContainerXPos = tnContainerPos.left;
  190.             if(tnContainerXPos >= tnScrollLimit){
  191.                 var scrollThumbnails = tnContainerXPos - (thumbImageWidth+20);
  192.                 jQuery(thumbnailHolderContainer).animate({left:scrollThumbnails});
  193.                 jQuery('.thumbnail-nav-right').show();
  194.             }else if(tnContainerXPos <= tnScrollLimit){
  195.                 jQuery(this).hide();
  196.             };
  197.         });
  198.         jQuery('.thumbnail-nav-right').on('click', function() {
  199.             var tnContainerPos = thumbnailHolderContainer.position();
  200.             var tnContainerXPos = tnContainerPos.left;
  201.             if(tnContainerXPos != 0){
  202.                 var scrollThumbnails = tnContainerXPos + (thumbImageWidth+20);
  203.                 jQuery(thumbnailHolderContainer).animate({left:scrollThumbnails});
  204.                 jQuery('.thumbnail-nav-left').show();
  205.             }else if(tnContainerXPos == 0){
  206.                 jQuery(this).hide();
  207.             }
  208.         });
  209.     };
  210. };
  211.  
  212. function additionalThemeJS() {
  213.     try{
  214.         upcp_style_hover();
  215.     }
  216.     catch(e) {
  217.     }
  218. }
  219.  
  220. function addClickHandlers() {
  221.     if (typeof maintain_filtering === 'undefined' || maintain_filtering === null) {maintain_filtering = "Yes";}
  222.  
  223.     if (maintain_filtering != "No") {
  224.         jQuery(".upcp-catalogue-link").on('click', function(event) {
  225.             event.preventDefault();
  226.             var link = jQuery(this).attr('href');
  227.             jQuery("#upcp-hidden-filtering-form").attr('action', link);
  228.  
  229.             if (jQuery('.upcp-lightbox-mode').length) {return;}
  230.  
  231.             jQuery("#upcp-hidden-filtering-form").submit();
  232.         });
  233.     }
  234.     additionalThemeJS();
  235. }
  236.  
  237. function FieldFocus (Field) {
  238.         if (Field.value == Field.defaultValue){
  239.               Field.value = '';
  240.         }
  241. }
  242.  
  243. function FieldBlur(Field) {
  244.         if (Field.value == '') {
  245.               Field.value = Field.defaultValue;
  246.         }
  247. }
  248.  
  249. function UPCPHighlight(Field, Color) {
  250.     var inputType = jQuery(Field).attr('name');
  251.     jQuery('input[name="' + inputType + '"][type="radio"]').each(function(){jQuery(this).parent().removeClass('highlight' + Color)});
  252.  
  253.     if (jQuery(Field.parentNode).hasClass('highlight'+Color)) {
  254.           jQuery(Field.parentNode).removeClass('highlight'+Color);
  255.     }
  256.     else {
  257.             jQuery(Field.parentNode).addClass('highlight'+Color);
  258.     }
  259. }
  260.  
  261. function UPCP_DisplayPage(PageNum) {
  262.     jQuery('#upcp-selected-current-page').val(PageNum);
  263.     jQuery('#upcp-current-page').html(PageNum);
  264.     UPCP_Ajax_Filter();
  265. }
  266.  
  267. function UPCP_Show_Hide_CF(cf_title) {
  268.     var CFID = jQuery(cf_title).data('cfid');
  269.  
  270.     jQuery('.prod-cat-sidebar-cf-content').each(function() {
  271.         if (jQuery(this).data('cfid') == CFID) {
  272.             jQuery(this).slideToggle('1000', 'swing');
  273.         }
  274.     });
  275. }
  276.  
  277. function UPCP_Show_Hide_Sidebar(sidebar_title) {
  278.     var TITLE = jQuery(sidebar_title).data('title');
  279.  
  280.     jQuery('.prod-cat-sidebar-content').each(function() {
  281.     if(jQuery(this).data('title') == TITLE) {
  282.         jQuery(this).slideToggle('1000', 'swing');
  283.     }
  284.     });
  285. }
  286.  
  287. function UPCP_Show_Hide_Subcat(sidebar_category) {
  288.     jQuery('#subcat-collapsible-'+sidebar_category).slideToggle('1000', 'swing');
  289.       jQuery('#cat-collapsible-'+sidebar_category).toggleClass("clicked");
  290.         if ( jQuery('#cat-collapsible-'+sidebar_category).hasClass("clicked") ) {
  291.             jQuery('#cat-collapsible-'+sidebar_category).text("-");
  292.         }
  293.         else {
  294.             jQuery('#cat-collapsible-'+sidebar_category).text("+");
  295.         }
  296. }
  297.  
  298. var RequestCount = 0;
  299. function UPCP_Ajax_Filter(AddResults) {
  300.     var CatValues = [];
  301.     var SubCatValues = [];
  302.     var TagBoxValues = [];
  303.     var CFBoxValues = [];
  304.  
  305.     var id = jQuery('#upcp-catalogue-id').html();
  306.     var sidebar = jQuery('#upcp-catalogue-sidebar').html();
  307.     var start_layout = jQuery('#upcp-starting-layout').html();
  308.     var current_layout = jQuery('#upcp-current-layout').html();
  309.     var excluded_layouts = jQuery('#upcp-excluded-layouts').html() || '';
  310.     var current_page = jQuery('#upcp-current-page').html();
  311.     var products_per_page = jQuery('#upcp-products-per-page').html();
  312.     var base_url = jQuery('#upcp-base-url').html();
  313.  
  314.     var values = jQuery('#upcp-price-score-filter').length && jQuery('#upcp-price-score-filter').slider("option", "values");
  315.     var min_price = values[0];
  316.     var max_price = values[1];
  317.     if (min_price == undefined) {min_price = 0;}
  318.     if (max_price == undefined) {max_price = 10000000;}
  319.  
  320.     jQuery('.jquery-prod-cat-value').each(function() {if (jQuery(this).prop('checked')) {CatValues.push(jQuery(this).val());}});
  321.     jQuery('.upcp-jquery-cat-dropdown').each(function() {if (jQuery(this).val() != "All") {CatValues.push(jQuery(this).val());}});
  322.     jQuery('.jquery-prod-sub-cat-value').each(function() {if (jQuery(this).prop('checked')) {SubCatValues.push(jQuery(this).val());}});
  323.     jQuery('.upcp-jquery-subcat-dropdown').each(function() {if (jQuery(this).val() != "All") {SubCatValues.push(jQuery(this).val());}});
  324.     jQuery('.jquery-prod-tag-value').each(function() {if (jQuery(this).prop('checked')) {TagBoxValues.push(jQuery(this).val());}});
  325.     jQuery('.upcp-jquery-tags-dropdown').each(function() {if (jQuery(this).val() != "All") {TagBoxValues.push(jQuery(this).val());}});
  326.     jQuery('.jquery-prod-cf-value').each(function() {if (jQuery(this).prop('checked')) {
  327.         Array_Value = jQuery(this).parent().parent().data('cfid') + "=" + jQuery(this).val();
  328.         CFBoxValues.push(Array_Value);
  329.     }});
  330.     jQuery('.jquery-prod-cf-select').each(function() {if (jQuery(this).val() != "All") {
  331.         Array_Value = jQuery(this).data('fieldid') + "=" + jQuery(this).val();
  332.         CFBoxValues.push(Array_Value);
  333.     }});
  334.     jQuery('.jquery-prod-cf-select').each(function() {if (jQuery(this).val() != "All") {
  335.         Array_Value = jQuery(this).data('fieldid') + "=" + jQuery(this).val();
  336.         CFBoxValues.push(Array_Value);
  337.     }});
  338.     jQuery('.jquery-prod-cf-select').each(function() {if (jQuery(this).val() != "All") {
  339.         Array_Value = jQuery(this).data('fieldid') + "=" + jQuery(this).val();
  340.         CFBoxValues.push(Array_Value);
  341.     }});
  342.     jQuery('.upcp-custom-field-slider').each(function() {
  343.         var Field_ID = jQuery(this).data("fieldid");
  344.  
  345.         var Array_Value = Field_ID + "=" + jQuery("#upcp-custom-field-"+Field_ID).slider("values", 0);
  346.         CFBoxValues.push(Array_Value);
  347.         var Array_Value = Field_ID + "=" + jQuery("#upcp-custom-field-"+Field_ID).slider("values", 1);
  348.         CFBoxValues.push(Array_Value);
  349.     });
  350.  
  351.     if (jQuery('.prod-cat-sidebar').css('display') == "none") {var SelectedProdName = jQuery('#upcp-mobile-search').val();}
  352.     else {var SelectedProdName = jQuery('#upcp-name-search').val();}
  353.  
  354.     if (SelectedProdName == undefined) {SelectedProdName = '';}
  355.  
  356.     if (AddResults == "Yes") {jQuery('.upcp-infinite-scroll-content-area').html('<h3>'+ajax_translations.updating_results_label+'</h3>');}
  357.     else {jQuery('.prod-cat-inner').html('<h3>'+ajax_translations.updating_results_label+'</h3>');}
  358.     RequestCount = RequestCount + 1;
  359.     var data = 'id=' + id + '&sidebar=' + sidebar + '&start_layout=' + current_layout + '&excluded_layouts=' + excluded_layouts + '&ajax_url=' + base_url + '&current_page=' + current_page + '&products_per_page=' + products_per_page + '&ajax_reload=Yes' + '&Prod_Name=' + SelectedProdName + '&max_price=' + max_price + '&min_price=' + min_price + '&Category=' + CatValues + '&SubCategory=' + SubCatValues + '&Tags=' + TagBoxValues + '&Custom_Fields=' + encodeURIComponent(CFBoxValues) + '&request_count=' + RequestCount + '&action=update_catalogue';
  360.     jQuery.post(ajaxurl, data, function(response) {
  361.         var parsed_response = jQuery.parseJSON(response);
  362.         if (parsed_response.request_count == RequestCount) {
  363.  
  364.             if (AddResults == "Yes") {jQuery('.upcp-infinite-scroll-content-area').replaceWith(parsed_response.message);}
  365.             else {jQuery('.prod-cat-inner').html(parsed_response.message);}
  366.             if (CatValues.length == 0 && SubCatValues.length == 0 && TagBoxValues.length == 0 && CFBoxValues.length == 0) {jQuery('.prod-cat-category-label').each(function() {jQuery(this).removeClass('Hide-Item');});}
  367.             if (jQuery('#upcp-sort-by').val() != "" && jQuery('#upcp-sort-by').val() != undefined) {UPCP_Sort_By();}
  368.             adjustCatalogueHeight();
  369.             adjustThumbnailHeights();
  370.             addClickHandlers();
  371.             addLightboxHandlers();
  372.             addProductcomparisonClickHandlers();
  373.             addInquiryAndCartHandlers();
  374.             UPCP_Infinite_Scroll();
  375.             UPCP_Adjust_Sidebar_Counts(min_price, max_price, CatValues, SubCatValues, TagBoxValues, CFBoxValues);
  376.             Filtering_Running = "No";
  377.         }
  378.     });
  379. }
  380.  
  381. function clearAllFilteringSelections() {
  382.     jQuery('.upcp-filtering-clear-all').addClass('upcp-Hide-Item');
  383.  
  384.     jQuery('#upcp-name-search').val('');
  385.     jQuery("#upcp-price-score-filter").slider("values", 0, min_price);
  386.     jQuery("#upcp-price-score-filter").slider("values", 1, max_price);
  387.     jQuery('.jquery-prod-cat-value, .jquery-prod-sub-cat-value, .jquery-prod-tag-value, .jquery-prod-cf-value').prop('checked', false).parent().removeClass('highlightBlack').removeClass('highlightBlue').removeClass('highlightGrey');
  388.     jQuery('.upcp-jquery-cat-dropdown, .upcp-jquery-subcat-dropdown, .upcp-jquery-tags-dropdown, .jquery-prod-cf-select').val('All');
  389.     jQuery('.upcp-custom-field-slider').each(function() {
  390.         var Field_ID = jQuery(this).data('fieldid');
  391.         max_value_int = parseInt(window['max_'+Field_ID]);
  392.         min_value_int = parseInt(window['min_'+Field_ID]);
  393.         jQuery("#upcp-custom-field-"+Field_ID).slider("values", [min_value_int, max_value_int]);
  394.     });
  395.  
  396.     UPCP_Ajax_Filter();
  397. }
  398.  
  399. function addProductcomparisonClickHandlers() {
  400.     jQuery('.upcp-product-comparison-button').on('click', function() {
  401.         var thisComparisonButton = jQuery(this);
  402.         var Prod_ID = jQuery(this).data('prodid');
  403.         var Prod_Name = jQuery(this).data('prodname');
  404.  
  405.         var input = jQuery('#upcp-product-comparison-form').find('input#upcp-pc-id'+Prod_ID);
  406.         if (!thisComparisonButton.hasClass('comparisonClicked')) {
  407.             thisComparisonButton.addClass('comparisonClicked');
  408.             if (input.length == 0) {
  409.                 jQuery('<input>').attr({
  410.                     type: 'hidden',
  411.                     id: 'upcp-pc-id'+Prod_ID,
  412.                     name: 'Comparison_Product_ID[]',
  413.                     value: Prod_ID
  414.                 }).data('prodname', Prod_Name).appendTo('#upcp-product-comparison-form');
  415.             }
  416.         }
  417.         else {
  418.             thisComparisonButton.removeClass('comparisonClicked');
  419.             jQuery(input.selector).remove();
  420.             jQuery('#upcp-product-comparison-form .upcp-prod-comp-submit-instructions').remove();
  421.         }
  422.  
  423.         if (jQuery('#upcp-product-comparison-form').find('input').length >= 2) {
  424.             jQuery('.upcp-prod-comp-submit-instructions').remove();
  425.             var Product_Name_String = "";
  426.             jQuery('#upcp-product-comparison-form input').each(function(index, el) {
  427.                 Product_Name_String += jQuery(this).data('prodname') + ", ";
  428.             });
  429.             Product_Name_String = Product_Name_String.slice(0, -2);
  430.             var replacement = " and";
  431.             Product_Name_String = Product_Name_String.replace(/,([^,]*)$/,replacement+'$1');
  432.             jQuery('#upcp-product-comparison-form').append('<div class="upcp-prod-comp-submit-instructions">' + ajax_translations.compare_label + ' ' + Product_Name_String + ' ' + ajax_translations.side_by_side_label + '!<input type="submit" value="' + ajax_translations.compare_label + '" /></div>');
  433.  
  434.             adjustCatalogueHeight();
  435.         }
  436.  
  437.  
  438.         if (jQuery('#upcp-product-comparison-form').find('input').length == 3) {
  439.             window.scrollTo(window.scrollX, jQuery('.upcp-prod-comp-submit-instructions').offset().top - 40);
  440.         }
  441.     })
  442. }
  443.  
  444. function UPCP_Setup_Price_Slider() {
  445.     if (typeof max_price === 'undefined' || max_price === null) {max_price = 10000000;}
  446.     if (typeof min_price === 'undefined' || min_price === null) {min_price = 0;}
  447.     if (typeof currency_symbol === 'undefined' || currency_symbol === null) {currency_symbol = '';}
  448.     if (typeof symbol_position === 'undefined' || symbol_position === null) {symbol_position = 'Before';}
  449.  
  450.     max_price_int = parseInt(max_price);
  451.     min_price_int = parseInt(min_price);
  452.  
  453.     jQuery("#upcp-price-score-filter").slider({
  454.         range: true,
  455.         min: min_price_int,
  456.         max: max_price_int,
  457.         values: [ min_price_int, max_price_int ],
  458.         change: function( event, ui ) {
  459.             jQuery('.upcp-filtering-clear-all').removeClass('upcp-Hide-Item');
  460.             jQuery('#upcp-current-page').html("1");
  461.             jQuery(".upcp-price-slider-min").val(ui.values[ 0 ]);
  462.             jQuery(".upcp-price-slider-max").val(ui.values[ 1 ]);
  463.             UPCP_Ajax_Filter();
  464.         }
  465.     });
  466.  
  467.     jQuery('.upcp-price-slider-min').on('keyup', function() {
  468.         jQuery("#upcp-price-score-filter").slider('values', 0, jQuery(this).val());
  469.     });
  470.  
  471.     jQuery('.upcp-price-slider-max').on('keyup', function() {
  472.         jQuery("#upcp-price-score-filter").slider('values', 1, jQuery(this).val());
  473.     });
  474.  
  475.     jQuery('.upcp-custom-field-slider').each(function() {
  476.         var Field_ID = jQuery(this).data("fieldid");
  477.  
  478.         max_value_int = parseInt(jQuery(this).data('maxvalue'));
  479.         min_value_int = parseInt(jQuery(this).data('minvalue'));
  480.  
  481.         jQuery("#upcp-custom-field-"+Field_ID).slider({
  482.             range: true,
  483.             min: min_value_int,
  484.             max: max_value_int,
  485.             values: [ min_value_int, max_value_int ],
  486.             change: function( event, ui ) {
  487.                jQuery('.upcp-filtering-clear-all').removeClass('upcp-Hide-Item');
  488.                jQuery(".upcp-custom-field-slider-min[data-fieldid='"+Field_ID+"']").val(ui.values[ 0 ]);
  489.                jQuery(".upcp-custom-field-slider-max[data-fieldid='"+Field_ID+"']").val(ui.values[ 1 ]);
  490.                UPCP_Ajax_Filter();
  491.             }
  492.         });
  493.     });
  494.  
  495.     jQuery(".upcp-custom-field-slider-min").on('keyup', function() {
  496.         var Field_ID = jQuery(this).data('fieldid');
  497.         jQuery(".upcp-custom-field-slider[data-fieldid='"+Field_ID+"']").slider('values', 0, jQuery(this).val());
  498.     });
  499.  
  500.     jQuery(".upcp-custom-field-slider-max").on('keyup', function() {
  501.         var Field_ID = jQuery(this).data('fieldid');
  502.         jQuery(".upcp-custom-field-slider[data-fieldid='"+Field_ID+"']").slider('values', 1, jQuery(this).val());
  503.     });
  504. }
  505.  
  506. /* Used in the bare-list layout to show or hide extra product details */
  507. function ToggleItem(Item_ID) {
  508.     if (jQuery('#prod-cat-title-'+Item_ID+'.upcp-list-title').hasClass('upcp-list-action-Product')) {
  509.         if (jQuery('.upcp-lightbox-mode').length) {return;}
  510.  
  511.         var product_page = jQuery('#prod-cat-details-'+Item_ID).find('.upcp-catalogue-link').attr('href');
  512.         window.location.href = product_page;
  513.         return;
  514.     }
  515.  
  516.     if (jQuery('#prod-cat-details-'+Item_ID).css('display') == "none") {
  517.         jQuery('#prod-cat-details-'+Item_ID).removeClass('hidden-field');
  518.         adjustCatalogueHeight();
  519.     }
  520.     else {
  521.         jQuery('#prod-cat-details-'+Item_ID).addClass('hidden-field');
  522.         adjustCatalogueHeight();
  523.     }
  524. }
  525.  
  526. /* Used to track the number of times that a product is clicked in all catalogues */
  527. function RecordView(Item_ID) {
  528.         var data = 'Item_ID=' + Item_ID + '&action=record_view';
  529.         jQuery.post(ajaxurl, data, function(response) {});
  530. }
  531.  
  532. function ToggleView(DisplayType) {
  533.  
  534.         if (DisplayType == "Thumbnail" && jQuery('.thumb-display').hasClass('hidden-field')) {
  535.               jQuery('.list-display').animate({opacity: 0}, 500);
  536.                 jQuery('.detail-display').animate({opacity: 0}, 500);
  537.                 setTimeout(function(){jQuery('.thumb-display').animate({opacity: 1}, 500);})
  538.                 jQuery('.thumb-display').removeClass('hidden-field');
  539.                 jQuery('#upcp-current-layout').html('Thumbnail');
  540.                 setTimeout(function(){jQuery('.list-display').addClass('hidden-field');})
  541.                 setTimeout(function(){jQuery('.detail-display').addClass('hidden-field');})
  542.         }
  543.         if (DisplayType == "List" && jQuery('.list-display').hasClass('hidden-field')) {
  544.               jQuery('.thumb-display').animate({opacity: 0}, 500);
  545.                 jQuery('.detail-display').animate({opacity: 0}, 500);
  546.                 setTimeout(function(){jQuery('.list-display').animate({opacity: 1}, 500);})
  547.                 jQuery('.list-display').removeClass('hidden-field');
  548.                 jQuery('#upcp-current-layout').html('List');
  549.                 setTimeout(function(){jQuery('.thumb-display').addClass('hidden-field');})
  550.                 setTimeout(function(){jQuery('.detail-display').addClass('hidden-field');})
  551.         }
  552.         if (DisplayType == "Detail" && jQuery('.detail-display').hasClass('hidden-field')) {
  553.               jQuery('.list-display').animate({opacity: 0}, 500);
  554.                 jQuery('.thumb-display').animate({opacity: 0}, 500);
  555.                 setTimeout(function(){jQuery('.detail-display').animate({opacity: 1}, 500);})
  556.                 jQuery('.detail-display').removeClass('hidden-field');
  557.                 jQuery('#upcp-current-layout').html('Detail');
  558.                 setTimeout(function(){jQuery('.list-display').addClass('hidden-field');})
  559.                 setTimeout(function(){jQuery('.thumb-display').addClass('hidden-field');})
  560.         }
  561.  
  562.         setTimeout(function(){adjustCatalogueHeight();})
  563.  
  564.         return false;
  565. }
  566.  
  567. function ZoomImage(ProdID, ItemID) {
  568.     jQuery('.upcp-tabbed-video-container').addClass('upcp-Hide-Item');
  569.     jQuery('.upcp-tabbed-image-container').removeClass('upcp-Hide-Item');
  570.     if (ItemID == 0) {
  571.       PhotoSRC = jQuery('#prod-cat-addt-details-thumb-P'+ProdID).attr('src');
  572.     }
  573.     else {
  574.         PhotoSRC = jQuery('#prod-cat-addt-details-thumb-'+ItemID).attr('src');
  575.     }
  576.     jQuery('.prod-cat-addt-details-main').each(function() {jQuery(this).attr('src', PhotoSRC)});
  577.     jQuery('.prod-cat-addt-details-main').each(function() {jQuery(this).data('ulbsource', PhotoSRC)});
  578.     jQuery('.prod-cat-addt-details-link-a').each(function() {jQuery(this).attr('href', PhotoSRC)});
  579.     jQuery('.prod-cat-addt-details-link-a').each(function() {jQuery(this).data('ulbsource', PhotoSRC)});
  580. }
  581.  
  582. jQuery(document).ready(function() {
  583.     jQuery('.upcp-thumb-video').on('click', function(event){
  584.         var videoID = jQuery(this).data('videoid');
  585.         jQuery('.upcp-main-video').attr('src', 'http://www.youtube.com/embed/'+videoID);
  586.         jQuery('.upcp-tabbed-image-container').addClass('upcp-Hide-Item');
  587.         jQuery('.upcp-tabbed-video-container').removeClass('upcp-Hide-Item');
  588.         if (!jQuery(this).hasClass('ewd-ulb-lightbox')) {event.preventDefault();}
  589.     });
  590. });
  591.  
  592. function adjustCatalogueHeight() {
  593.     var objHeight = 0;
  594.  
  595.     var thumbOuterHeight = 0;
  596.     var listOuterHeight = 0;
  597.     var detailOuterHeight = 0;
  598.     jQuery('.prod-cat.thumb-display').each(function() {thumbOuterHeight += jQuery(this).outerHeight();});
  599.     jQuery('.prod-cat.list-display').each(function() {listOuterHeight += jQuery(this).outerHeight();});
  600.     jQuery('.prod-cat.detail-display').each(function() {detailOuterHeight += jQuery(this).outerHeight();});
  601.     objHeight = Math.max(thumbOuterHeight, listOuterHeight, detailOuterHeight);
  602.  
  603.     objHeight = objHeight + 120;
  604.     jQuery('.prod-cat-inner').height(objHeight);
  605.  
  606.     if (jQuery(window).width() <= 715) {
  607.         objHeight = jQuery('.prod-cat-inner').height() + jQuery('.prod-cat-sidebar').height();
  608.         jQuery('.prod-cat-container').height(objHeight);
  609.     }
  610.     else {
  611.         objHeight = Math.max(jQuery('.prod-cat-inner').height(), jQuery('.prod-cat-sidebar').height());
  612.         jQuery('.prod-cat-container').height(objHeight);
  613.     }
  614. }
  615.  
  616. function adjustThumbnailHeights() {
  617.     var maxHeight = Math.max.apply(null, jQuery(".upcp-thumb-item.upcp-thumb-adjust-height").map(function ()
  618.     {
  619.         return jQuery(this).outerHeight();
  620.     }).get());
  621.  
  622.     jQuery('.upcp-thumb-item.upcp-thumb-adjust-height').css('height', maxHeight);
  623. }
  624.  
  625. function addInquiryAndCartHandlers() {
  626.     if (jQuery('.upcp-product-interest-button').length) {
  627.         jQuery('.upcp-product-interest-button').off('click');
  628.         jQuery('.upcp-product-interest-button').on('click', function() {
  629.             var prod_ID = jQuery(this).data('prodid');
  630.  
  631.             jQuery('.upcp-wc-cart-div').removeClass('upcp-Hide-Item');
  632.             jQuery('.upcp-inquire-div').removeClass('upcp-Hide-Item');
  633.  
  634.             var Item_Count = parseInt(jQuery('.upcp-cart-item-count').html());
  635.             jQuery('.upcp-cart-item-count').html(Item_Count + 1);
  636.  
  637.             var data = 'prod_ID=' + prod_ID + '&action=upcp_add_to_cart';
  638.             jQuery.post(ajaxurl, data, function(response) {});
  639.         });
  640.  
  641.         jQuery('.upcp-clear-cart').off('click');
  642.         jQuery('.upcp-clear-cart').on('click', function() {
  643.             jQuery('.upcp-wc-cart-div').addClass('upcp-Hide-Item');
  644.             jQuery('.upcp-inquire-div').addClass('upcp-Hide-Item');
  645.  
  646.             jQuery('.upcp-cart-item-count').html('0');
  647.  
  648.             var data = '&action=upcp_clear_cart';
  649.             jQuery.post(ajaxurl, data, function(response) {});
  650.         })
  651.     }
  652. }
  653.  
  654. function UPCP_Adjust_Sidebar_Counts(min_price, max_price, CatValues, SubCatValues, TagBoxValues, CFBoxValues) {
  655.     var Decoded_Products = jQuery.parseJSON(filtering_values);
  656.  
  657.     var Selected_CustomFields = [];
  658.     jQuery(CFBoxValues).each(function(index, el) {
  659.         var CF_ID = el.substring(0, el.indexOf('='));
  660.         var CF_Value = el.substring(el.indexOf('=') + 1);
  661.  
  662.         if (Selected_CustomFields[CF_ID] === undefined) {Selected_CustomFields[CF_ID] = [];}
  663.        
  664.         Selected_CustomFields[CF_ID].push(CF_Value);
  665.     });
  666.     jQuery('.upcp-custom-field-slider').each(function(index, el) {
  667.         var CF_ID = jQuery(this).data('fieldid');
  668.         var Min = Math.min.apply(Math, Selected_CustomFields[CF_ID]);
  669.         var Max = Math.max.apply(Math, Selected_CustomFields[CF_ID]);
  670.         for (i=Min+1; i<Max; i++) {Selected_CustomFields[CF_ID].push(""+i);}
  671.     });
  672.  
  673.     var Sidebar_Counts = {"Categories" : {}, 'SubCategories' : {}, 'Tags' : {},  'CustomFields' : {}};
  674.     jQuery(Decoded_Products).each(function(index, el) {
  675.         if (el.Price < min_price || el.Price > max_price) {return;}
  676.  
  677.         var Missing = '';
  678.         if (CatValues.length != 0 && jQuery.inArray(el.Category, CatValues) == -1) {Missing = (Missing == '' ? 'Category' : 'Mismatch');}
  679.         if (SubCatValues.length != 0 && jQuery.inArray(el.SubCategory, SubCatValues) == -1) {Missing = (Missing == '' ? 'SubCategory' : 'Mismatch');}
  680.         if (TagBoxValues.length != 0 && !el.Tags.sort().compare(TagBoxValues.sort())) {Missing = (Missing == '' ? 'Tags' : 'Mismatch');}
  681.         if (Selected_CustomFields.length != 0){
  682.             for (var CF_ID in Selected_CustomFields) {
  683.                 if (Selected_CustomFields[CF_ID] == undefined || !jQuery.isArray(Selected_CustomFields[CF_ID])) {continue;}
  684.                 if (jQuery.inArray(el.CustomFields[CF_ID], Selected_CustomFields[CF_ID]) == -1) {Missing = (Missing == '' ? 'CustomField_' + CF_ID : 'Mismatch');}
  685.             }
  686.         }
  687.        
  688.         if (Missing != 'Mismatch') {
  689.             if (Missing == '' || Missing == 'Category') {
  690.                 if (Sidebar_Counts['Categories'][el.Category] === undefined) {Sidebar_Counts['Categories'][el.Category] = 1;}
  691.                 else {Sidebar_Counts['Categories'][el.Category] = Sidebar_Counts['Categories'][el.Category] + 1;}
  692.             }
  693.             if (Missing == '' || Missing == 'SubCategory') {
  694.                 if (Sidebar_Counts['SubCategories'][el.SubCategory] === undefined) {Sidebar_Counts['SubCategories'][el.SubCategory] = 1;}
  695.                 else {Sidebar_Counts['SubCategories'][el.SubCategory] = Sidebar_Counts['SubCategories'][el.SubCategory] + 1;}
  696.             }
  697.             if (Missing == '' || Missing == 'Tags') {
  698.                 jQuery(el.Tags).each(function(index, tag) {
  699.                     if (Sidebar_Counts['Tags'][tag] === undefined) {Sidebar_Counts['Tags'][tag] = 1;}
  700.                     else {Sidebar_Counts['Tags'][tag] = Sidebar_Counts['Tags'][tag] + 1;}
  701.                 });
  702.             }
  703.             if (Missing == '' || Missing.indexOf('CustomField') == 0) {
  704.                 if (Missing != '') {var CF_ID = Missing.substring(12);}
  705.  
  706.                 for (var index in el.CustomFields) {
  707.                     if (Missing == '' || index == CF_ID) {
  708.                         if (Sidebar_Counts['CustomFields'][index] === undefined) {Sidebar_Counts['CustomFields'][index] = [];}
  709.  
  710.                         if (Sidebar_Counts['CustomFields'][index][el.CustomFields[index]] === undefined) {Sidebar_Counts['CustomFields'][index][el.CustomFields[index]] = 1;}
  711.                         else {Sidebar_Counts['CustomFields'][index][el.CustomFields[index]] = Sidebar_Counts['CustomFields'][index][el.CustomFields[index]] + 1;}
  712.                     }
  713.                 };
  714.             }
  715.         }
  716.     });
  717.  
  718.     jQuery('.prod-cat-sidebar-category label').each(function(index, el) {
  719.         var ID = jQuery(this).attr('for').substring(4);
  720.         if (Sidebar_Counts['Categories'][ID] === undefined) {
  721.             jQuery(this).find('span span').html('(0)');
  722.             if (ajax_translations.hide_empty == "Yes") {jQuery(this).parent().css('display', 'none');}
  723.         }
  724.         else {jQuery(this).parent().css('display', 'block').find('span span').html('(' + Sidebar_Counts['Categories'][ID] + ')');}
  725.     });
  726.  
  727.     jQuery('.prod-cat-sidebar-subcategory label').each(function(index, el) {
  728.         var ID = jQuery(this).attr('for').substring(4);
  729.         if (Sidebar_Counts['SubCategories'][ID] === undefined) {
  730.             jQuery(this).find('span span').html('(0)');
  731.             if (ajax_translations.hide_empty == "Yes") {jQuery(this).parent().css('display', 'none');}
  732.         }
  733.         else {jQuery(this).parent().css('display', 'block').find('span span').html('(' + Sidebar_Counts['SubCategories'][ID] + ')');}
  734.     });
  735.  
  736.     jQuery('.prod-cat-sidebar-cf-content').each(function(index, el) {
  737.         var CF_ID = jQuery(this).data('cfid');
  738.         if (jQuery(this).find('select').length == 0) {
  739.             jQuery(this).find('label').each(function() {
  740.                 var CF_Value = jQuery(this).data('cf_value');
  741.                 if (Sidebar_Counts['CustomFields'][CF_ID] !== undefined && CF_Value in Sidebar_Counts['CustomFields'][CF_ID]) {jQuery(this).parent().css('display', 'block').find('span span').html('(' + Sidebar_Counts['CustomFields'][CF_ID][CF_Value] + ')');}
  742.                 else {
  743.                     jQuery(this).find('span span').html('(0)');
  744.                     if (ajax_translations.hide_empty == "Yes") {jQuery(this).parent().css('display', 'none');}
  745.                 }
  746.             });
  747.         }
  748.         else {
  749.             jQuery(this).find('option').each(function() {
  750.                 var CF_Value = jQuery(this).val();
  751.                 if (CF_Value != 'All' && Sidebar_Counts['CustomFields'][CF_ID] !== undefined && CF_Value in Sidebar_Counts['CustomFields'][CF_ID]) {
  752.                     var Option_Text = jQuery(this).html();
  753.                     jQuery(this).html(Option_Text.substring(0, Option_Text.indexOf('(')) + '(' + Sidebar_Counts['CustomFields'][CF_ID][CF_Value] + ')').css('display', 'inline-block');
  754.                 }
  755.                 else if (CF_Value != 'All') {
  756.                     var Option_Text = jQuery(this).html();
  757.                     jQuery(this).html(Option_Text.substring(0, Option_Text.indexOf('(')) + '(0)');
  758.                     if (ajax_translations.hide_empty == "Yes") {jQuery(this).css('display', 'none');}
  759.                 }
  760.             });
  761.         }
  762.     });
  763. }
  764.  
  765. /* Sort by price or by name */
  766. jQuery.fn.sortElements = (function(){
  767.  
  768.     var sort = [].sort;
  769.  
  770.     return function(comparator, getSortable) {
  771.  
  772.         getSortable = getSortable || function(){return this;};
  773.  
  774.         var placements = this.map(function(){
  775.  
  776.             var sortElement = getSortable.call(this),
  777.                 parentNode = sortElement.parentNode,
  778.  
  779.                 // Since the element itself will change position, we have
  780.                 // to have some way of storing its original position in
  781.                 // the DOM. The easiest way is to have a 'flag' node:
  782.                 nextSibling = parentNode.insertBefore(
  783.                     document.createTextNode(''),
  784.                     sortElement.nextSibling
  785.                 );
  786.  
  787.             return function() {
  788.  
  789.                 if (parentNode === this) {
  790.                     throw new Error(
  791.                         "You can't sort elements if any one is a descendant of another."
  792.                     );
  793.                 }
  794.  
  795.                 // Insert before flag:
  796.                 parentNode.insertBefore(this, nextSibling);
  797.                 // Remove flag:
  798.                 parentNode.removeChild(nextSibling);
  799.  
  800.             };
  801.  
  802.         });
  803.  
  804.         return sort.call(this, comparator).each(function(i){
  805.             placements[i].call(getSortable.call(this));
  806.         });
  807.  
  808.     };
  809.  
  810. })();
  811.  
  812. function UPCP_Sort_By() {
  813.         jQuery('.prod-cat-category-label').each(function() {jQuery(this).addClass('Hide-Item');});
  814.         var SortBy = jQuery('#upcp-sort-by').val();
  815.         if (SortBy == "name_asc")           {SortByNameASC();}
  816.         else if (SortBy == "name_desc")     {SortByNameDESC();}
  817.         else if (SortBy == "price_asc")     {SortByPriceASC();}
  818.         else if (SortBy == "price_desc")    {SortByPriceDESC();}
  819.         else if (SortBy == "rating_asc")    {SortByRatingASC();}
  820.         else if (SortBy == "rating_desc")   {SortByRatingDESC();}
  821.         else if (SortBy == "date_asc")      {SortByDateASC();}
  822.         else if (SortBy == "date_desc")     {SortByDateDESC();}
  823. }
  824.  
  825. function SortByNameASC() {
  826.         jQuery('.thumb-display div .prod-cat-title').sortElements(function(a, b){
  827.                         return jQuery(a).text() > jQuery(b).text() ? 1 : -1;
  828.         }, function() {
  829.                         return this.parentNode; //here
  830.                 });
  831.                 jQuery('.list-display div .prod-cat-title').sortElements(function(a, b){
  832.                         return jQuery(a).text() > jQuery(b).text() ? 1 : -1;
  833.         }, function() {
  834.                         return this.parentNode;
  835.                 });
  836.                 jQuery('.detail-display div .prod-cat-title').sortElements(function(a, b){
  837.                         return jQuery(a).text() > jQuery(b).text() ? 1 : -1;
  838.         }, function() {
  839.                         return this.parentNode.parentNode.parentNode; //here
  840.                 });
  841. }
  842.  
  843. function SortByNameDESC() {
  844.         jQuery('.thumb-display div .prod-cat-title').sortElements(function(a, b){
  845.                         return jQuery(a).text() < jQuery(b).text() ? 1 : -1;
  846.         }, function() {
  847.                         return this.parentNode; //here
  848.                 });
  849.                 jQuery('.list-display div .prod-cat-title').sortElements(function(a, b){
  850.                         return jQuery(a).text() < jQuery(b).text() ? 1 : -1;
  851.         }, function() {
  852.                         return this.parentNode;
  853.                 });
  854.                 jQuery('.detail-display div .prod-cat-title').sortElements(function(a, b){
  855.                         return jQuery(a).text() < jQuery(b).text() ? 1 : -1;
  856.         }, function() {
  857.                         return this.parentNode.parentNode.parentNode; //here
  858.                 });
  859. }
  860.  
  861. function SortByPriceASC() {
  862.         var first;
  863.                 var second;
  864.                 jQuery('.thumb-display div .prod-cat-price').sortElements(function(a, b){
  865.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  866.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  867.                         return Number(first) > Number(second) ? 1 : -1;
  868.         }, function() {
  869.                         return this.parentNode;
  870.                 });
  871.                 jQuery('.list-display div .prod-cat-price').sortElements(function(a, b){
  872.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  873.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  874.                         return Number(first) > Number(second) ? 1 : -1;
  875.         }, function() {
  876.                         return this.parentNode;
  877.                 });
  878.                 jQuery('.detail-display div .prod-cat-price').sortElements(function(a, b){
  879.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  880.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  881.                         return Number(first) > Number(second) ? 1 : -1;
  882.         }, function() {
  883.                         return this.parentNode.parentNode;
  884.                 });
  885. }
  886.  
  887. function SortByPriceDESC() {
  888.                 var first;
  889.                 var second;
  890.                 jQuery('.thumb-display div .prod-cat-price').sortElements(function(a, b){
  891.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  892.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  893.                         return Number(first) < Number(second) ? 1 : -1;
  894.         }, function() {
  895.                         return this.parentNode;
  896.                 });
  897.                 jQuery('.list-display div .prod-cat-price').sortElements(function(a, b){
  898.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  899.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  900.                         return Number(first) < Number(second) ? 1 : -1;
  901.         }, function() {
  902.                         return this.parentNode;
  903.                 });
  904.                 jQuery('.detail-display div .prod-cat-price').sortElements(function(a, b){
  905.                         first = jQuery(a).data('item_price').replace(/\D/g,'');
  906.                         second = jQuery(b).data('item_price').replace(/\D/g,'');
  907.                         return Number(first) < Number(second) ? 1 : -1;
  908.         }, function() {
  909.                         return this.parentNode.parentNode;
  910.                 });
  911. }
  912.  
  913. function SortByRatingASC() {
  914.     jQuery('.thumb-display div .prod-cat-title .upcp-urp-review-score').sortElements(function(a, b){
  915.                         return jQuery(a).attr('title') > jQuery(b).attr('title') ? 1 : -1;
  916.         }, function() {
  917.                         return this.parentNode.parentNode; //here
  918.                 });
  919.                 jQuery('.list-display div .upcp-urp-review-score').sortElements(function(a, b){
  920.                         return jQuery(a).attr('title') > jQuery(b).attr('title') ? 1 : -1;
  921.         }, function() {
  922.                         return this.parentNode;
  923.                 });
  924.                 jQuery('.detail-display div div .upcp-urp-review-score').sortElements(function(a, b){
  925.                         return jQuery(a).attr('title') > jQuery(b).attr('title') ? 1 : -1;
  926.         }, function() {
  927.                         return this.parentNode.parentNode; //here
  928.                 });
  929. }
  930.  
  931. function SortByRatingDESC() {
  932.         jQuery('.thumb-display div .prod-cat-title .upcp-urp-review-score').sortElements(function(a, b){
  933.                         return jQuery(a).attr('title') < jQuery(b).attr('title') ? 1 : -1;
  934.         }, function() {
  935.                         return this.parentNode.parentNode; //here
  936.                 });
  937.                 jQuery('.list-display div .upcp-urp-review-score').sortElements(function(a, b){
  938.                         return jQuery(a).attr('title') < jQuery(b).attr('title') ? 1 : -1;
  939.         }, function() {
  940.                         return this.parentNode;
  941.                 });
  942.                 jQuery('.detail-display div div .upcp-urp-review-score').sortElements(function(a, b){
  943.                         return jQuery(a).attr('title') < jQuery(b).attr('title') ? 1 : -1;
  944.         }, function() {
  945.                         return this.parentNode.parentNode; //here
  946.                 });
  947. }
  948.  
  949. function SortByDateASC() {
  950.         jQuery('.thumb-display div.upcp-thumb-item').sortElements(function(a, b){
  951.                         return jQuery(a).data('itemid') < jQuery(b).data('itemid') ? 1 : -1;
  952.         }, function() {
  953.                         return this; //here
  954.                 });
  955.                 jQuery('.list-display div.upcp-list-item').sortElements(function(a, b){
  956.                         return jQuery(a).data('itemid') < jQuery(b).data('itemid') ? 1 : -1;
  957.         }, function() {
  958.                         return this;
  959.                 });
  960.                 jQuery('.detail-display div.upcp-detail-item').sortElements(function(a, b){
  961.                         return jQuery(a).data('itemid') < jQuery(b).data('itemid') ? 1 : -1;
  962.         }, function() {
  963.                         return this; //here
  964.                 });
  965. }
  966.  
  967. function SortByDateDESC() {
  968.     jQuery('.thumb-display div.upcp-thumb-item').sortElements(function(a, b){
  969.                         return jQuery(a).data('itemid') > jQuery(b).data('itemid') ? 1 : -1;
  970.         }, function() {
  971.                         return this; //here
  972.                 });
  973.                 jQuery('.list-display div.upcp-list-item').sortElements(function(a, b){
  974.                         return jQuery(a).data('itemid') > jQuery(b).data('itemid') ? 1 : -1;
  975.         }, function() {
  976.                         return this;
  977.                 });
  978.                 jQuery('.detail-display div.upcp-detail-item').sortElements(function(a, b){
  979.                         return jQuery(a).data('itemid') > jQuery(b).data('itemid') ? 1 : -1;
  980.         }, function() {
  981.                         return this; //here
  982.                 });
  983.  
  984. }
  985.  
  986. /*Array.defineProperty(Array.prototype, 'compare', {
  987.     value: function(testArr) {
  988.     if (this.length != testArr.length) return false;
  989.     for (var i = 0; i < testArr.length; i++) {
  990.       if (this[i].compare) { //To test values in nested arrays
  991.         if (!this[i].compare(testArr[i])) return false;
  992.       }
  993.       else if (this[i] !== testArr[i]) return false;
  994.     }
  995.         return true;
  996.     },
  997.     writable: true,
  998.   configurable: false,
  999.   enumerable: false
  1000. });*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement