Skip to content

Instantly share code, notes, and snippets.

@mariohernandez
Last active November 6, 2016 02:17
Show Gist options
  • Save mariohernandez/c2e7316e7b2761738840e129861c6769 to your computer and use it in GitHub Desktop.
Save mariohernandez/c2e7316e7b2761738840e129861c6769 to your computer and use it in GitHub Desktop.
Example of Javascript for card component
(function ($) {
'use strict';
Drupal.behaviors.card = {
attach: function (context, settings) {
var $bioButton = $('.card__view-bio', context);
var $bioDrawer = $('.card__bio', context);
var showBio = 'View full biography';
var hideBio = 'Hide biography';
$bioButton.on('click', function() {
$bioDrawer.toggleClass('is-open');
$bioButton.toggleClass('flip-carat');
if ($bioDrawer.hasClass('is-open')) {
$bioButton.text(hideBio);
$bioButton.toggleClass('is-open');
}
else {
$bioButton.text(showBio);
$bioButton.removeClass('is-open');
}
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment