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

Can't run callback #1

Closed
senner007 opened this issue Feb 25, 2013 · 8 comments
Closed

Can't run callback #1

senner007 opened this issue Feb 25, 2013 · 8 comments

Comments

@senner007
Copy link

Great plugin.

How can I run a callback with for instance: $('#container').masonry( 'reload' )?

@rmm5t
Copy link
Owner

rmm5t commented Feb 25, 2013

Thanks!

Sieve is awfully new (idea formed yesterday, and launched today). I'd be happy to consider adding a callback, but just so we're on the same page, are you asking for a callback to fire every time after results have been filtered?

@senner007
Copy link
Author

Yes. I need to integrate search functionality with my masonry grid.

So the items would have to be removed with the masonry method:

$container.masonry( 'remove', 'items')

and then instant reload ( $container.masonry( 'reload' ); ). If possible.

@senner007
Copy link
Author

... and of course instantly appended with the masonry append method

thanks.

@rmm5t
Copy link
Owner

rmm5t commented Feb 25, 2013

Okay. So it sounds like you're asking for perhaps two things.

  1. A function override for the "show" and "hide" behavior that takes an item (or perhaps a list of items) as an argument.
  2. A callback when a search pass is complete so you can take some final action over the list of content.

Just brainstorming at the moment. Perhaps, this could be combined into one overall callback that passes a jquery wrapper argument representing the the list of items to hide and a list of the items to show.

@senner007
Copy link
Author

Yes that ought to do it.

@rmm5t rmm5t closed this as completed in 511789d Mar 6, 2013
@rmm5t
Copy link
Owner

rmm5t commented Mar 6, 2013

I added two callback functions, toggle and complete. They are currently experimental and might change, but it should give you enough to test your idea out. Let me know how it goes.

@senner007
Copy link
Author

Very cool!
I'll give it a try and let you know how it goes.

@senner007
Copy link
Author

Ok I am back and I found out how to do it. I wasn't that difficult and I ended up using a different plugin called jquery search which was recently added to the jQuery plugin repository.

Here is the code. Im still a beginner so it might not be the best solution.

Anyway, thanks for the effort.


jQuery.extend( jQuery.fn, {
search: function(p) {
jQuery.expr[':'].icontains = function(a, i, m) { // :icontains is a case insensitive selector
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
if (p.match(/.+/g) == null) return this;
return $(this).filter(':icontains(' + p + ')');
}
});

$('#container').on('keyup','#searchM',function() {
var v = $(this).val();
var s = $itemsAll.search(v);
var $container = $('#container')
var foundInCon = $container.find('.item');
var notItems = foundInCon.not(s);
var foundInAll = $itemsAll.filter(s).not(foundInCon);

if ( v != '') {
    $container.masonry( 'remove', notItems)
    .append( foundInAll )
    .masonry( 'reload' );
}

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants