Skip to content

Instantly share code, notes, and snippets.

@apipkin
Created December 29, 2010 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apipkin/758775 to your computer and use it in GitHub Desktop.
Save apipkin/758775 to your computer and use it in GitHub Desktop.
YUI.add('plugin-dt-accordion', function(Y){
Y.Node.prototype.wrapInner = function(html) {
var n = Y.Node.create(html);
this.setData('preWrappedContent', this.getContent())
n.prepend(this.getData('preWrappedContent'));
this.setContent(n);
return this;
};
var CLASS_OPEN = 'dta-toggle-open',
CLASS_CLOSE = 'dta-toggle-closed';
Y.namespace('Plugin').DTAccordion = Y.Base.create('dt-accordion', Y.Plugin.Base, [], {
_host : null,
_delegate : null,
_anim : null,
initializer : function() {
Y.log('initializer', 'info', 'Y.Plugin.DTAccordion');
this._host = this.get('host');
this.renderUI();
this.bindUI();
},
destructor : function() {
this.unrenderUI();
this.unbindUI();
},
renderUI : function() {
this._host.all('dt').each(function(dt){
dt.wrapInner('<a />').one('a').append('<span />');
dt.addClass(CLASS_CLOSE);
});
this._host.all('dd').addClass(CLASS_CLOSE).plug(Y.Plugin.NodeFX, {from: {}, to:{}, on:{}, duration: .3, easing: Y.Easing.easeOut});
},
bindUI : function() {
this._delegate = this._host.delegate('click', function(e){
var dt = e.currentTarget,
dd = dt.next('dd');
if (dd.fx.get('running')) {
dd.fx.pause();
}
dd.fx.set('from.height', dd.get('offsetHeight'));
if (dt.hasClass(CLASS_CLOSE)) {
dt.replaceClass(CLASS_CLOSE, CLASS_OPEN);
dd.fx.set('to.height', dd.get('scrollHeight'));
dd.fx.set('on.complete', function(){
dd.replaceClass(CLASS_CLOSE,CLASS_OPEN);
});
} else {
dt.replaceClass(CLASS_OPEN,CLASS_CLOSE);
dd.fx.set('to.height', 0);
dd.fx.set('on.complete', function(){
dd.replaceClass(CLASS_OPEN, CLASS_CLOSE);
});
}
dd.fx.run();
}, 'dt');
},
unrenderUI : function() {
this._host.all('.' + CLASS_OPEN + ', .' + CLASS_CLOSE).removeClass(CLASS_OPEN).removeClass(CLASS_CLOSE);
this._host.all('dt').each(function(dt){
dt.setContent(dt.getData('preWrappedContent'));
});
},
unbindUI : function() {
this._delegate.detach();
}
}, {
NS : 'dta',
ATTRS : {
}
});
}, '1.0', {requires: ['base-build','plugin','node','event', 'anim']});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment