Last active
December 8, 2015 17:11
-
-
Save rmcveigh/20d28c270b21e118b67a to your computer and use it in GitHub Desktop.
Simple accordion js for Drupal. Relies on jQuery
This file contains hidden or 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
/** | |
* @file | |
* A JavaScript file for the theme. | |
* This file should be used as a template for your other js files. | |
* It defines a drupal behavior the "Drupal way". | |
* | |
*/ | |
// JavaScript should be made compatible with libraries other than jQuery by | |
// wrapping it with an "anonymous closure". See: | |
// - https://drupal.org/node/1446420 | |
// - http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth | |
(function ($, Drupal, window, document, undefined) { | |
'use strict'; | |
// To understand behaviors, see https://drupal.org/node/756722#behaviors | |
Drupal.behaviors.cardCardholderAggreement = { | |
attach: function (context, settings) { // jshint ignore:line | |
var $allPanels = $('.accordion .accordion-content').hide(); | |
var $allIcons = $('.accordion .icon-triangle').addClass('closed'); | |
$('.accordion .trigger').click(function() { | |
var $wrapper = $(this).closest('.accordion'); | |
var $target = $wrapper.find('.accordion-content'); | |
var $icon = $(this).find('.icon-triangle'); | |
if(!$target.hasClass('active')){ | |
$target.addClass('active').slideDown(); | |
$icon.removeClass('closed').addClass('opened'); | |
} | |
else { | |
$target.removeClass('active').slideUp(); | |
$allIcons.removeClass('opened').addClass('closed'); | |
} | |
return false; | |
}); | |
} | |
}; | |
})(jQuery, Drupal, this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, the js above relies on jQuery and is designed for Drupal
scss for above js: