Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2011 22:20
Show Gist options
  • Save anonymous/808576 to your computer and use it in GitHub Desktop.
Save anonymous/808576 to your computer and use it in GitHub Desktop.
YUI.add('collapsing-stalker', function(Y){
var CS = Y.Base.create('collapsing-stalker', Y.Plugin.Base, [], {
_host : null,
_clickBind : null,
initializer : function() {
Y.log('initializer','info','Y.Plugin.Xarno.CollapsingStalker');
this._host = this.get('host');
this._renderUI();
this._bindUI();
},
destructor : function() {
Y.log('destructor','info','Y.Plugin.Xarno.CollapsingStalker');
if (this._clickBind) {
this._clickBind.detach();
this._clickBind = null;
}
_host.unplug(Y.Plugin.NodeStalker);
},
_renderUI : function() {
Y.log('_renderUI','info','Y.Plugin.Xarno.CollapsingStalker');
this._host.plug(Y.Plugin.NodeStalker);
this._host.all('.' + this.get('collapseClass')).plug(Y.Plugin.NodeFX, this.get('collapseConfig'));
},
_bindUI : function() {
Y.log('_bindUI','info','Y.Plugin.Xarno.CollapsingStalker');
this._clickBind = this._host.delegate('click', this._toggleCollapse, '.' + this.get('triggerClass'), this);
},
_toggleCollapse : function() {
Y.log('_toggleCollapse','info','Y.Plugin.Xarno.CollapsingStalker');
var height = 0;
this._host.all('.' + this.get('collapseClass')).each(function(c){
if (!c.hasClass('opened')) {
height = c.get('scrollHeight');
c.addClass('opened');
} else {
c.removeClass('opened');
}
if (c.fx.get('running')) {
c.fx.stop();
}
c.fx.set('to.height', height);
c.fx.run();
});
}
}, {
NS : 'cs',
ATTRS : {
triggerClass : {
value : 'trigger'
},
collapseClass : {
value : 'collapse'
},
collapseConfig : {
value : {duration: .5, to:{height: 0}}
}
}
});
Y.namespace('Plugin.Xarno').CollapsingStalker = CS;
}, '0.1', {requires: ['node','gallery-stalker','anim-node-plugin', 'plugin','base-build']});
YUI().use('collapsing-stalker', function(Y){
Y.one('#social').plug(Y.Plugin.Xarno.CollapsingStalker);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment