Skip to content

Instantly share code, notes, and snippets.

@apipkin
Forked from anonymous/gist:808576
Created February 2, 2011 22:20
Show Gist options
  • Save apipkin/808577 to your computer and use it in GitHub Desktop.
Save apipkin/808577 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.Plugin.Xarno.CollapsingStalker.prototype.refresh = function() {
var top = Y.DOM.docScrollY(),
left = Y.DOM.docScrollX(),
n = this._root,
r = n.getXY(),
c = ["marginTop", "marginLeft", "borderLeftWidth", "borderTopWidth"];
// viewport computations
r[1] = Math.max(0, r[1] - top);
r[0] = r[0] - left;
// node size computation
Y.Array.each(c,
function(v) {
r[v] = parseInt(n.getStyle(v), 10) || 0;
});
n.setStyles({
top: r[1] - r.borderTopWidth - r.marginTop,
left: r[0] - r.borderLeftWidth - r.marginLeft,
position: 'fixed'
});
};
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