Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* A simple accordion.
*/
(function (jQuery) {
Drupal.behaviors.FiescAccordion = {
attach: function () {
this.init();
},
init: function (settings) {
console.log('Accordion init')
this.settings = settings;
this.setup();
this.bind();
},
setup: function () {
this.settings = jQuery.extend({
scope: '.view-video-media',
items: '.views-row .content > .title',
openedClass: 'opened',
animationDelay: 300
}, this.settings);
this.scope = jQuery(this.settings.scope);
this.items = this.scope.find(this.settings.items)
this.opened = this.settings.openedClass;
this.animationDelay = this.settings.animationDelay;
this.currentItem = null;
},
bind: function () {
var _this = this;
this.items.on('click', function (ev) {
console.log('item clicked');
ev.preventDefault();
_this.toggle(jQuery(ev.target));
});
},
toggle: function (target) {
var _this = this;
if (target.hasClass(this.opened)) {
this.close(target);
}
else {
if (this.currentItem) {
this.close(this.currentItem, function () {
_this.open(target);
});
}
else {
this.open(target);
}
}
},
close: function (target, callback) {
var _this = this,
element = target.siblings('div');
element.animate({
height: 0
}, this.animationDelay, function () {
target.removeClass(_this.opened);
_this.currentItem = null;
var iframe = jQuery(this).find('iframe');
iframe.get(0).contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*');
iframe.hide();
if (jQuery.isFunction(callback)) {
callback();
}
});
},
open: function (target) {
var _this = this,
element = target.siblings('div');
element.animate({
height: 360
}, this.animationDelay, function () {
target.addClass(_this.opened);
_this.currentItem = target;
jQuery(this).find('iframe').show();
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.