Skip to content

Instantly share code, notes, and snippets.

@dimmech
Created September 5, 2016 20:15
Show Gist options
  • Save dimmech/7dbcbd98a146cdd7e5ad519156ae40b7 to your computer and use it in GitHub Desktop.
Save dimmech/7dbcbd98a146cdd7e5ad519156ae40b7 to your computer and use it in GitHub Desktop.
Drupal Isotope Hierarchical js
(function ($) {
$(document).ready(function() {
//$('li.first').hover(function(){ alert("Hello"); });
// Insert li classes based on span value from views output
$('ul.isotope-options > li.first > a').text('Product Catalog');
$('.level0').parent().parent().addClass('sub-parent');
$('.level1').parent().parent().addClass('sub-child');
$('.level2').parent().parent().addClass('sub-grandchild');
// Hide all li(s) if mouse leaves the defined menu area
$('ul.isotope-options').hover(function(){
}, function(e){
if(!$(e.relatedTarget).is('span.level0')) {
$('ul.isotope-options > li').removeClass('hovered')
}
})
// Add/Remove classes on submenu parents
$('li.first').hover(function(){
$(this).siblings('li.sub-parent').addClass('hovered');
}, function(e){
if(!$(e.relatedTarget).is('span.level0')) {
$(this).siblings('li.sub-parent').removeClass('hovered');
$(this).siblings('li.sub-child').removeClass('hovered');
$(this).siblings('li.sub-grandchild').removeClass('hovered');
}
})
// Add/Remove classes on submenu children
$('li.sub-parent').hover(function(){
$('li.sub-child').removeClass('hovered');
$(this).nextUntil('li.sub-parent','li.sub-child').addClass('hovered');
}, function(e){
if(!$(e.relatedTarget).is('span.level1')) {
$(this).siblings('li.sub-child').removeClass('hovered');
$(this).siblings('li.sub-grandchild').removeClass('hovered');
}
})
// Add/Remove classes on submenu grandchildren
$('li.sub-child').hover(function(){
$('li.sub-grandchild').removeClass('hovered');
$(this).nextUntil('li.sub-child').addClass('hovered');
}, function(e){
if(!$(e.relatedTarget).is('span.level2')) {
$(this).siblings('li.sub-grandchild').removeClass('hovered');
}
})
});
}(jQuery, Drupal));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment