Last active
September 19, 2015 17:46
-
-
Save wesruv/3e65616d38828dd85ba4 to your computer and use it in GitHub Desktop.
Generic Toggle JS for Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#" class="js-dropdown__toggle">Toggle Link</a> | |
<div class="js-dropdown__wrapper"> | |
<h3>Toggleable Content</h3> | |
<p>Can have other wrappers, but no tag should be between the toggle link and toggle wrapper.</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, Drupal, window, document, undefined) { | |
// Generic toggle behavior | |
Drupal.behaviors.toggleOpen = { | |
attach: function(context, settings) { | |
// Only run this stuff once | |
$('.js-dropdown__toggle', context).once('js-dropdown--triggered', function(){ | |
$(this).click(function (e) { | |
e.preventDefault(); | |
$(this).toggleClass('js-is-active'); | |
$(this).next('.js-dropdown__wrapper').toggleClass('js-is-open'); | |
$(this).blur(); | |
}); | |
}); | |
} | |
}; | |
})(jQuery, Drupal, this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment