Created
June 9, 2014 23:08
-
-
Save gneutzling/6c941b3a100558c596bf to your computer and use it in GitHub Desktop.
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 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