Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. // == Program ==
  2. Program : {
  3.  
  4. initialize : function() {
  5. if (!$('program-tree-container')) return false; // Exit immediately if not on a Program page
  6. this.Tree.initialize()
  7. },
  8.  
  9. Tree : {
  10.  
  11. // Class: Item
  12. Item : Class.create({
  13.  
  14. initialize : function(element_id) {
  15. this.element_id = element_id
  16. this.element = $(element_id)
  17. this.content_element = this.element.select('ul').first()
  18. this.expanded = true
  19. this.__add_observers()
  20. this.collapse(true)
  21. },
  22.  
  23. toggle : function() {
  24. ( this.expanded ) ? this.collapse() : this.expand()
  25. },
  26. expand : function() {
  27. if (this.content_element) {
  28. new Effect.SlideDown(this.content_element, {duration : 0.2})
  29. this.element.addClassName('opened')
  30. this.expanded = true
  31. }
  32. },
  33. collapse : function(collapse_hard) {
  34. if (this.content_element) {
  35. (collapse_hard) ? this.content_element.hide() : new Effect.SlideUp(this.content_element, {duration : 0.1})
  36. this.element.removeClassName('opened')
  37. this.expanded = false
  38. }
  39. },
  40.  
  41. __add_observers : function() {
  42. var zis = this
  43. this.element.observe('mouseover', function(event) {zis.__handle_mouseover(event)} ).
  44. observe('mouseout', function(event) {zis.__handle_mouseout(event)} ).
  45. observe('click', function(event) {zis.__handle_mouseclick(event)} )
  46. },
  47. __handle_mouseover : function(event) {
  48. this.element.addClassName('hover')
  49. },
  50. __handle_mouseout : function(event) {
  51. this.element.removeClassName('hover')
  52. },
  53. __handle_mouseclick: function(event) {
  54. console.log('click!')
  55. this.toggle()
  56. }
  57.  
  58. }), // end Item class
  59.  
  60. selector : '#program-tree-container ul li',
  61. collection : null, // Collection of <li> nodes, see initialize()
  62.  
  63. initialize : function() {
  64. this.collection = $$(this.selector)
  65. this.collection.each( function(n) { new Admin.Program.Tree.Item(n) } )
  66. }
  67.  
  68. } // end Tree
  69.  
  70. } // end Program
Add Comment
Please, Sign In to add comment