text: /*
   *  jquery-bigFastShopifyFilter - vv0.0.1
   *  Designed to sort and filter products using key value pairs in tags and metafields. Performs much faster on massive collections, and includes infinite scroll pagination
   *  http://colinbrogan.info/dev/big-fast-shopify-filter
   *
   *  Made by Colin Brogan
   *  Under MIT License
   */
  !function(a,b,c,d){"use strict";function e(b,c){this.element=b,this.settings=a.extend({},g,c),this._defaults=g,this._name=f,this.init()}var f="bigFastShopifyFilter",g={filter_criteria:null,collection_handle:null,paginate:30,key_value_overrides:null,metafields:null,tagfields:null,price:{enable:!0,ui_label:"Price",ui_component:"range-slider",placement:"sidebar",range_splits:4},vendor:{enable:!0,ui_component:"sidebar",placement:"sidebar",one_option_hide:!0},type:{enable:!1,ui_component:"checkbox-button-group",placement:"sidebar",one_option_hide:!0}},h=null;a.extend(e.prototype,{init:function(){if(a(this.element).data("collection")===d)return!1;this.setCollectionHandle(a(this.element).data("collection"));var c=a(this.element).find("ul.product-grid").data("fast-start");if(c!==d){var e=c;this.storeAllReceived(e)}var f=this;a(this.element).on("loadReceived",function(a,b){console.log("A load was received"),f.storeAllReceived(b),(b.page-1)%7==0&&(f.filter(),f.buildOptions())}),a(this.element).on("loadsFinished",function(){console.log("Finished all Loads"),f.buildOptions(),f.filter(),a("#options-go-here").removeClass("loading"),f.registerActions()}),b.location.hash="filter_ready",a(this.element).on("filterOptionsChanged",function(){b.location.hash="filter_ready",f.setActiveOptionsToHash(),f.registerActions()})},filtered:{},filter_options:{},allReceived:{},displayEndIndex:0,collection_handle:null,filter_criteria:null,all_loads_in:!1,sort_property:"price",queuedForScroll:[],$productGrid:a(),scroll_adding:!1,page:1,go:function(b){a(this.element).find("ul.product-grid").empty(),this.queuedForScroll=[],this.filter_criteria=b;var c=a(this.element);if(this.filter(),this.buildOptions(),this.all_loads_in===!1){var d=function(a){c.trigger("loadReceived",a)},e=this,f=function(b){e.all_loads_in=!0;var d=!0;for(var f in e.filtered){d=!1;break}d&&a("ul.product-grid").html(["<li class='emtpy-message'>","Nothing matched your filter criteria.","<a href='#' class='clear-all'>","Clear All <i class='icon icon-close'></i>","</a>","</li>"].join("")),c.trigger("loadsFinished",b)};Shopify.Mazer.pipeInCollection.go(this.collection_handle,d,1,f)}},fastReload:function(b){a(this.element).find("ul.product-grid").empty(),this.queuedForScroll=[],this.filter_criteria=b;a(this.element);this.filter()},filter:function(){a(this.element).find("ul.product-grid").addClass("loading"),this.filtered={};for(var b in this.allReceived){var c=!0;for(var d in this.filter_criteria){var e=decodeURIComponent(d.replace(/\+/g,"%20"));if(this.settings.metafields.hasOwnProperty(e))for(var f in this.allReceived[b].metafields){var g=this.allReceived[b].metafields[f];if(f===d)if(this.filter_criteria[d].constructor==Array){var h=!1;for(var i in this.filter_criteria[d]){var j=decodeURIComponent(this.filter_criteria[d][i].replace(/\+/g,"%20"));g===j&&(h=!0)}if(!h){c=!1;continue}}else{var j=decodeURIComponent(this.filter_criteria[d].replace(/\+/g,"%20"));if(g!==j){c=!1;continue}}}else if(this.settings.tagfields.hasOwnProperty(e)){var k=!1,l={};for(var m in this.allReceived[b].info.tags){var n=this.allReceived[b].info.tags[m];if(0===n.indexOf("kvp:"+e)){k=!0;var o=n.split(":"),p=o[1],q=o[2];if(p=a("<div/>").html(p).text(),q=a("<div/>").html(q).text(),p==decodeURIComponent(d.replace(/\+/g,"%20")))if(this.filter_criteria[d].constructor==Array){var h=!1;for(var i in this.filter_criteria[d]){var j=decodeURIComponent(this.filter_criteria[d][i].replace(/\+/g,"%20"));q===j&&(h=!0)}if(h)l[e]=q;else if(!l.hasOwnProperty(e)){c=!1;continue}}else{var j=decodeURIComponent(this.filter_criteria[d].replace(/\+/g,"%20"));if(j===q)l[e]=q;else if(!l.hasOwnProperty(e)){c=!1;continue}}}}if(0==k){c=!1;continue}}else if(this.settings.type.enable&&"Type"==d)if(this.filter_criteria[d].constructor==Array){var h=!1;for(var i in this.filter_criteria[d]){var j=decodeURIComponent(this.filter_criteria[d][i].replace(/\+/g,"%20"));this.allReceived[b].info.type===j&&(h=!0)}if(!h){c=!1;continue}}else{var r=decodeURIComponent(this.filter_criteria[d].replace(/\+/g,"%20"));if(this.allReceived[b].info.type!=r){c=!1;continue}}else if(this.settings.vendor.enable&&"Vendor"==d)if(this.filter_criteria[d].constructor==Array){var h=!1;for(var i in this.filter_criteria[d]){var j=decodeURIComponent(this.filter_criteria[d][i].replace(/\+/g,"%20"));this.allReceived[b].info.vendor===j&&(h=!0)}if(!h){c=!1;continue}}else{var r=decodeURIComponent(this.filter_criteria[d].replace(/\+/g,"%20"));if(this.allReceived[b].info.vendor!=r){c=!1;continue}}}c&&(this.filtered[b]=this.allReceived[b])}console.log("Currently filtered"),console.log(this.filtered),this.trickleToGrid()},storeAllReceived:function(a){null==this.allReceived&&(this.allReceived={});for(var b in a.products){a:for(var c in a.products[b].metafields){var e=a.products[b].metafields[c];if(this.settings.metafields.hasOwnProperty(c)){if(this.filter_options.hasOwnProperty(c)){if(this.filter_options[c].hasOwnProperty(e))continue a;this.filter_options[c][e]={}}else this.filter_options[c]={},this.filter_options[c][e]={};if(this.settings.filter_values.hasOwnProperty(c))if(this.settings.filter_values[c].hasOwnProperty(e)){var f=this.settings.filter_values[c][e].label,g=this.settings.filter_values[c][e].color,h=this.settings.filter_values[c][e].image;this.filter_options[c][e].label=f?f:e,g&&(this.filter_options[c][e].color=g),h&&(this.filter_options[c][e].image=h)}else this.filter_options[c][e].label=e;else this.filter_options[c][e].label=e}}a:for(var i=0;i<a.products[b].info.tags.length;i++){var j=a.products[b].info.tags[i];if(0===j.indexOf("kvp:")){var k=j.split(":"),l=k[1],m=k[2];if(this.settings.tagfields.hasOwnProperty(l)){if(this.filter_options.hasOwnProperty(l)){if(this.filter_options[l].hasOwnProperty(m))continue a;this.filter_options[l][m]={}}else this.filter_options[l]={},this.filter_options[l][m]={};if(this.settings.filter_values.hasOwnProperty(l))if(this.settings.filter_values[l].hasOwnProperty(m)){var f=this.settings.filter_values[l][m].label,g=this.settings.filter_values[l][m].color,h=this.settings.filter_values[l][m].image;this.filter_options[l][m].label=f?f:m,g&&(this.filter_options[l][m].color=g),h&&(this.filter_options[l][m].image=h)}else this.filter_options[l][m].label=m;else this.filter_options[l][m].label=m}}}this.settings.type.enable&&(this.filter_options.Type===d?this.filter_options.Type={}:(this.filter_options.Type[a.products[b].info.type]={},this.filter_options.Type[a.products[b].info.type].label=a.products[b].info.vendor)),this.settings.vendor.enable&&(this.filter_options.Vendor===d?this.filter_options.Vendor={}:(this.filter_options.Vendor[a.products[b].info.vendor]={},this.filter_options.Vendor[a.products[b].info.vendor].label=a.products[b].info.vendor)),this.allReceived[b]=a.products[b]}console.log("this.allReceived"),console.log(this.allReceived)},renderOptions:function(){var a="";for(var b in this.filter_options){var c=b;this.settings.tagfields.hasOwnProperty(b)?c=this.settings.tagfields[b].ui_label:this.settings.metafields.hasOwnProperty(b)&&(c=this.settings.metafields[b].ui_label),a+=this.filter_criteria.hasOwnProperty(encodeURIComponent(b).replace(/%20/g,"+"))?"<h3 class='active'>"+c+"</h3>":"<h3>"+c+"</h3>",a+='<ul class="tick-boxes">';for(var d in this.filter_options[b]){var e=this.filter_options[b][d],f="";if(this.filter_criteria.hasOwnProperty(encodeURIComponent(b).replace(/%20/g,"+")))if(this.filter_criteria[encodeURIComponent(b).replace(/%20/g,"+")]===encodeURIComponent(d).replace(/%20/g,"+"))f+="active";else if(this.filter_criteria[encodeURIComponent(b).replace(/%20/g,"+")].constructor===Array)for(var g in this.filter_criteria[encodeURIComponent(b).replace(/%20/g,"+")])this.filter_criteria[encodeURIComponent(b)][g]===encodeURIComponent(d).replace(/%20/g,"+")&&(f+="active");var h="";e.color&&(h+="background-color: "+e.color+"; ",parseInt(e.color.replace("#",""),16)<10329501&&(f+=" white-tick")),e.image&&(h+="background-image: url("+e.image+"); "),a+='<li><button class="'+f+'" name="'+b+'" value="'+d+'"><div class="tick-box" style="'+h+'"></div>'+e.label+"</button></li>"}a+="</ul>"}return a},buildOptions:function(){a(this.element).find("#options-go-here").empty(),a(this.element).find("#options-go-here").addClass("loading").append(this.renderOptions()),this.registerActions()},getAllReceived:function(){return this.allReceived},trickleToGrid:function(){a(".show-results").remove();var b=this.collection_handle,c=function(a){var c={};for(var d in a.info.tags){var e=a.info.tags[d];if(0===e.indexOf("kvp:")){var f=e.split(":");c[f[1]]=f[2]}}var g=a.info.images[0],h="",i=a.info.title;return["<li id='p"+a.info.id+"'>",'<div class="snapshot">','<a href="/collections/'+b+"/products/"+a.info.handle+'" class="product-image '+h+'" style="background-image: url(\'http:'+g+"')\">","</a>","</div>",'<h4 class="product-title"><a href="/collections/'+b+"/products/"+a.info.handle+'">'+i+"</a></h4>",'<div class="price-condition">','<dl class="price">',"<dt><span hidden>Price</span></dt>","<dd>$"+a.info.price/100+"</dd>","</dl>","</div>","</li>"].join("")},d=this,e=function(b,c,e){var f=!1,g=!1;if(b.find("li").length>0){var i=function(i){var j=a(this).attr("data-filter-index");if(d.filtered[j].info.id==d.filtered[h].info.id)return g=!0,!1;if(d.filtered[h].info[d.sort_property]<d.filtered[j].info[d.sort_property]){if(a(this).before(c),b.find("li").length>e){var k=b.find("li:last-child");f=k.clone(),k.remove()}return g=!0,!1}return i==b.find("li").length-1&&e-1>i?(a(this).after(c),g=!0,!1):void 0};b.find("li").each(i)}else b.append(c),g=!0;return{placed_item:g,add_to_next:f}},f=!0,g=a("ul.product-grid").clone();g.empty();for(var h in this.filtered){f=!1;var i=a(c(this.filtered[h])).attr("data-filter-index",h),j=this.settings.paginate*this.page,k=e(g,i,j);if(k.add_to_next&&this.queuedForScroll.unshift(k.add_to_next),!k.placed_item)if(this.queuedForScroll.length>0)for(var l in this.queuedForScroll){var m=a(this.queuedForScroll[l]).attr("data-filter-index"),n=0;if(d.filtered[m].info.id==d.filtered[h].info.id){n=1;break}if(d.filtered[h].info[d.sort_property]<d.filtered[m].info[d.sort_property]){n=2,this.queuedForScroll.splice(l-1,0,i);break}if(l==this.queuedForScroll.length-1){n=3,this.queuedForScroll.push(i);break}}else this.queuedForScroll.push(i)}a("ul.product-grid").replaceWith(g),this.addResultsButton(),a(this.element).find("ul.product-grid").removeClass("loading"),f&&this.all_loads_in&&a("ul.product-grid").html(["<li class='emtpy-message'>","Nothing matched your filter criteria.","<a href='#' class='clear-all'>","Clear All <i class='icon icon-close'></i>","</a>","</li>"].join("")),this.getProductNumbers(),this.afterDump()},addResultsButton:function(){if(this.queuedForScroll.length>0){var b=this.settings.paginate;this.queuedForScroll.length<b&&(b=this.queuedForScroll.length);var c=a(['<div class="show-results">','<button class="btn btn-purple" id="add-results">',"Show "+b+" more results.","</button>","</div>"].join(""));a(".show-results").length>0?a(".show-results").replaceWith(c):a("ul.product-grid").after(c);var d=this;a("#add-results").click(function(){d.infiniteScroll()})}else a(".show-results").replaceWith(['<div class="show-results">','<button class="btn disabled" id="add-results">',"You've reached the end","</button>","</div>"].join(""))},registerActions:function(){var b=this,c=a(this.element);a("ul.tick-boxes button").unbind("click"),a("ul.tick-boxes button").click(function(b){b.preventDefault(),a("ul.product-grid").addClass("loading"),a(this).toggleClass("active"),setTimeout(function(){c.trigger("filterOptionsChanged")},200)}),a("a.clear-all").unbind("click"),a("a.clear-all").click(function(c){c.preventDefault(),c.stopPropagation(),a("ul.tick-boxes button").removeClass("active"),b.setActiveOptionsToHash()}),a("#add-results").unbind("click"),a("#add-results").click(function(){b.infiniteScroll()}),a(this.element).find("#options-go-here h3").unbind("click"),a(this.element).find("#options-go-here h3").click(function(){a(this).toggleClass("active")})},setActiveOptionsToHash:function(){var b={};a("#options-go-here").find("ul.tick-boxes button.active").each(function(){var c=a(this).attr("name"),e=a(this).attr("value");b[c]==d&&(b[c]=[]),b[c].push(e)});var c=jQuery.param(b,!0);a.address.queryString(c)},infiniteScroll:function(){var b=this,c=function(){a("ul.product-grid").removeClass("adding-products"),b.page=b.page+1;for(var c=0;c<b.settings.paginate;)a("ul.product-grid").append(b.queuedForScroll.shift()),c++;b.scroll_adding=!1};c(),this.addResultsButton(),this.getProductNumbers(),this.afterDump()},afterDump:function(){a(this.element).trigger("afterDump")},getProductNumbers:function(){var b=Object.keys(this.filtered).length,c=b-this.queuedForScroll.length,d="Showing "+c+" / "+b+" Appliances";a(".result_count").html(d)},refresh:function(){somePrivateMethod("refresh")},setCollectionHandle:function(a){this.collection_handle=a},getSomeInfo:function(){return this.someInfo},getPrivateInfo:function(){return h}}),a.fn[f]=function(b){var c=arguments;if(b===d||"object"==typeof b)return this.each(function(){a.data(this,"plugin_"+f)||a.data(this,"plugin_"+f,new e(this,b))});if("string"==typeof b&&"_"!==b[0]&&"init"!==b){var g;return this.each(function(){var d=a.data(this,"plugin_"+f);d instanceof e&&"function"==typeof d[b]&&(g=d[b].apply(d,Array.prototype.slice.call(c,1))),"destroy"===b&&a.data(this,"plugin_"+f,null)}),g!==d?g:this}}}(jQuery,window,document);