Created
October 24, 2015 09:15
-
-
Save xto3na/31e8e9eb16ec149877a1 to your computer and use it in GitHub Desktop.
Choosen filter block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************** CHOOSEN-FILTER-BLOCK *******************************/ | |
var choosen = {}; | |
choosen.listFilters = []; | |
choosen.update = function () { | |
this.listFilters = []; | |
$(".active_filter").each(function (index, elem) { | |
if ($(elem).attr("data-name") != "min_price" | |
&& $(elem).attr("data-name") != "max_price") { | |
var txt = $(elem).closest("label").find(".title").text(); | |
choosen.listFilters.push({ | |
key: $(elem).attr("data-name"), | |
value: $(elem).attr("value"), | |
text: txt | |
}); | |
}; | |
}); | |
this.listFilters = this.listFilters.reverse(); | |
var list = ""; | |
for (var i = choosen.listFilters.length - 1; i >= 0; i--) { | |
list += '<li class="list-filter-item" data-name="' | |
+ choosen.listFilters[i].key + '" value="' | |
+ choosen.listFilters[i].value + '">' | |
+ choosen.listFilters[i].text | |
+ '<i class="fa fa-times"></i></li>'; | |
}; | |
$("#list-filters").html(list); | |
$("#list-filters .list-filter-item").on("click", function () { | |
console.log("click"); | |
var keyAttr = $(this).attr("data-name"); | |
var valueAttr = $(this).attr("value"); | |
$('input[data-name="' + keyAttr + '"]') | |
.filter('input[value="' + valueAttr + '"]').click(); | |
}); | |
}; | |
/************************** CHOOSEN-FILTER-BLOCK END *******************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment