Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == 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
Add Comment
Please, Sign In to add comment