Reputation: 2679
UPDATE
Due to low activity on my original question (below) I rephrase it simply like this:
How can I initialize MIXITUP jQuery filter from other url using Hash or GET-parameters?
====
I am using MIXITUP jQuery filter for sorting several elements on one page. Is there a way to make a link from another page with one of the filers already active?
The idea is to have one link for each category
and also one main
link for the hole page. The category link would land the visitor on the second page with the selected category
filter already activated. If the visitor would choose the main
link he would land on the page with all categories
visible.
For example lets say I sell cables and want to have a link from index
to store
with HDMI
activated, so that when the jump has been made the visitor lands on the store
page and only sees HDMI
cables, with the option of selecting other filters to see the rest of the products of course.
Please ask if you need more information, sample code or anything else..
Thanks in advance
Upvotes: 1
Views: 1854
Reputation: 5064
You can specify the filter which will take effect right when the page is loaded by using the load.filter
setting like this:
$('#container').mixItUp({
load: {
filter: 'your filter'
}
});
Nothing stops you from getting the value for this setting from document.location.hash
property. You can check whether the hash is empty, and if it's not, use its value as a filter:
$('#container').mixItUp({
load: {
filter: document.location.hash == '' ? 'all' :
('.' + document.location.hash.substring(1))
}
});
hash.substring(1)
is needed because the string would include the #
character itself, and I append .
in the beginning because I think it's likely that you want to always filter by class and there's no need to include the dot in the URL.
Demo on CodePen:
category-1
: http://s.codepen.io/izstas/full/Ddkse#category-1Upvotes: 6