Created
October 5, 2008 09:24
-
-
Save karmi/14866 to your computer and use it in GitHub Desktop.
Somebody said "jQuery"?
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
// == Program == | |
Program : { | |
initialize : function() { | |
if (!$('program-tree-container')) return false; // Exit immediately if not on a Program page | |
this.Tree.initialize() | |
}, | |
Tree : { | |
// Class: Item | |
Item : Class.create({ | |
initialize : function(element_id) { | |
this.element_id = element_id | |
this.element = $(element_id) | |
this.content_element = this.element.select('ul').first() | |
this.expanded = true | |
this.__add_observers() | |
this.collapse(true) | |
}, | |
toggle : function() { | |
( this.expanded ) ? this.collapse() : this.expand() | |
}, | |
expand : function() { | |
if (this.content_element) { | |
new Effect.SlideDown(this.content_element, {duration : 0.2}) | |
this.element.addClassName('opened') | |
this.expanded = true | |
} | |
}, | |
collapse : function(collapse_hard) { | |
if (this.content_element) { | |
(collapse_hard) ? this.content_element.hide() : new Effect.SlideUp(this.content_element, {duration : 0.1}) | |
this.element.removeClassName('opened') | |
this.expanded = false | |
} | |
}, | |
__add_observers : function() { | |
var zis = this | |
this.element.observe('mouseover', function(event) {zis.__handle_mouseover(event)} ). | |
observe('mouseout', function(event) {zis.__handle_mouseout(event)} ). | |
observe('click', function(event) {zis.__handle_mouseclick(event)} ) | |
}, | |
__handle_mouseover : function(event) { | |
this.element.addClassName('hover') | |
}, | |
__handle_mouseout : function(event) { | |
this.element.removeClassName('hover') | |
}, | |
__handle_mouseclick: function(event) { | |
console.log('click!') | |
this.toggle() | |
} | |
}), // end Item class | |
selector : '#program-tree-container ul li', | |
collection : null, // Collection of <li> nodes, see initialize() | |
initialize : function() { | |
this.collection = $$(this.selector) | |
this.collection.each( function(n) { new Admin.Program.Tree.Item(n) } ) | |
} | |
} // end Tree | |
} // end Program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment