germanysbestkeptsecret / Wookmark-jQuery

A jQuery plugin to create a dynamic, multi-column layout.
MIT License
2.63k stars 759 forks source link

adding new items to data-filter-class of list item, filter ignores this #141

Closed Terrahe closed 10 years ago

Terrahe commented 10 years ago

hi there, my li elements have data-filter-class='["test"]'

i add with jquery a new item to some li elements so data-filter-class='["test", "addItem"]'

but data-filter="additem" dont filter matching li elements

can you give me a hint to solve this issue

thank you very much marc

Sebobo commented 10 years ago

Hi,

wookmark caches the filter classes for performance reasons. You can reload those after your modifying them with a simple call to the handler:

$handler.wookmarkInstance.updateFilterClasses();
Terrahe commented 10 years ago

hi sebobo, many thanks for the hint ... i get it working ?!... the image disapear from original filter but dont show in the new filter section (class=inactive)

i think its a problem with adding new filter "additem" to data-filter-class array i tried

$('li.class').attr('data-filter-class' , "additem"); $('li.class').data('filter-class' , "additem"); $('li.class').attr('data-filter-class' , '["additem"]');

and so on.

did you know what is the correct way to push new filtername to the filter-class array

1000 thanks marc

Terrahe commented 10 years ago

update .... i get it to work, so for others interest => to push another filter to array

var kat=$('.classX").data('filter-class'); //reads existing filter

if (kat.indexOf("additem")==-1){ //looks for duplicates $("li.classX").data('filter-class' , [ kat , "additem"]) //adds filter to array }

thank you

Sebobo commented 10 years ago

Wouldn't your code create a nested array? I would recommend something like this:

var filterClasses = $('.classX").data('filter-class');

if (filterClasses.indexOf("newFilterClass") == -1) {
    filterClasses.push("newFilterClass");
    $("li.classX").data('filter-class' , filterClasses);
}