Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger('refreshWookmark) not working #196

Open
macsupport opened this issue Jun 16, 2015 · 15 comments
Open

trigger('refreshWookmark) not working #196

macsupport opened this issue Jun 16, 2015 · 15 comments
Labels
Milestone

Comments

@macsupport
Copy link

I am working on a simple search option using quicksearch. It uses some callbacks to show and hide items. The show and hide works but the refreshWookmark call does not.

var handler = $('.item');
$("#search").quicksearch(".item", {
          'loader': 'span.loading',
          'minValLength': 2,
          'bind': 'search keydown',
    'show': function () {   
        $(this).removeClass('wookmark-inactive');
        handler.trigger('refreshWookmark');
    },
    'hide': function () {
        $(this).addClass('wookmark-inactive');
         handler.trigger('refreshWookmark');
    }
      });
@Sebobo
Copy link
Member

Sebobo commented Jun 16, 2015

You have to call the refresh on the initalised wookmark container since version 2.0.

For example

handler = $('.itemContainer').wookmark();
handler.trigger('refreshWookmark');

@macsupport
Copy link
Author

Thanks! That helped and the search now works as a "filter", but refreshWookmark will not trigger until after a change in window size.

@macsupport
Copy link
Author

I don't know why refreshWookmark only works after a change in window size but I was able to get things working by just calling

 $('.gallery').wookmark();  

in a callback, like this:

$("#search").quicksearch(".item", {
          'loader': 'span.loading',
         'bind': 'keyup keydown',
    'minValLength': 2,
    'show': function () {   
        $(this).removeClass('wookmark-inactive');   
    },
    'hide': function () {
        $(this).addClass('wookmark-inactive');  
    },
    'onAfter': function () {
      $('.gallery').wookmark();   
    }
      });

@Sebobo Sebobo added Bug and removed Question labels Jun 16, 2015
@Sebobo
Copy link
Member

Sebobo commented Jun 16, 2015

@macsupport yes I think I know why.
refreshWookmark is not strong enough. Means that it doesn't detect the change to the visible items and doesn't run a relayout because nothing seems to have changed.

Calling $.fn.wookmark again actually triggers the updateOptions function which forces a relayout.
Same as the filter function, which is the reason that all the filter examples work fine.

I will fix this soon in 2.0.2.
Thanks for helping me find the bug.

@macsupport
Copy link
Author

Thanks. Here is a Demo of the search function working, and using Photoswipe as the image lightbox with Wookmark. Thanks for a great plugin!

@ryanhovland
Copy link

Any update on this? Thanks!

@macsupport
Copy link
Author

Update?

@Sebobo
Copy link
Member

Sebobo commented Sep 9, 2015

Hi,

sorry I'm a bit busy lately. I already tried finding a solution and found a big issue with the events.
It seems the jQuery and standard events are not compatible. That means I have to implement both kind of events depending on what people use.
And the way you trigger events is also completely different and for the non-jQuery version not super nice.

Will get back on that in the next days.

@ryanhovland
Copy link

As a workaround, on resize I destroy wookmark and then re-initialize it. And if I remember right, I think I had to physically remove the DOM element and then re-add it to really clear things out. This is all super dirty but it works.

@virtuecai
Copy link

// Update the layout.
// Jquery Object 
var $wookmark = $('#container').wookmark({....});
wookmark.wookmarkInstance.initItems();
wookmark.wookmarkInstance.layout(true);
//JavaScript new
var wookmark = new Wookmark(container);
wookmark.initItems();
wookmark.layout(true);

@Sebobo
Copy link
Member

Sebobo commented Sep 22, 2015

Be careful that doesn't work currently when you initialize several instances with one call.

@Sebobo Sebobo added this to the 2.1.1 milestone Mar 10, 2016
@Sebobo Sebobo self-assigned this Mar 10, 2016
@Sebobo Sebobo modified the milestones: 2.1.2, 2.1.1 Apr 15, 2016
@zilions
Copy link

zilions commented May 4, 2016

I simply just used window.dispatchEvent(new Event('resize')); whenever I needed to refresh the feed. Very simple workaround until this bug is fixed.

@zilions
Copy link

zilions commented May 5, 2016

Scratch that, using the above code multiple times causes the browser to crash due to a "maximum call stack size exceeded" error.

Sebobo added a commit that referenced this issue May 5, 2016
Both events can now be triggered manually with or without jQuery.
See readme.md on how to do it.

Relates: #196
Sebobo added a commit that referenced this issue May 5, 2016
Both events can now be triggered manually with or without jQuery.
See readme.md on how to do it.

Relates: #196
@Sebobo
Copy link
Member

Sebobo commented May 5, 2016

Hey all,
events should now be triggered fine with 2.1.2.

@zilions I didn't get this error, do you have an example on how to get this error?

@zilions
Copy link

zilions commented May 8, 2016

I believe the error occurs when the event is called multiple times while it is still running. For example, not 100% sure if this would show the error, but guessing it would:

for(var i = 0; i < 10; i++) {
    window.dispatchEvent(new Event('resize'));
}

@Sebobo Sebobo removed their assignment May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants