Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. document.getElements('.toggler').addEvent('click', function(e){
  2.  
  3. var target = this.getChildren('i');
  4. console.log(target);
  5.  
  6. if (target.hasClass('icon-minus')) {
  7. console.log('hasclass - minus');
  8. target.addClass('icon-plus').removeClass('icon-minus');
  9. this.getNext('div').hide();
  10. } else {
  11. console.log('hasclass - plus');
  12. target.addClass('icon-minus').removeClass('icon-plus');
  13. this.getNext('div').show();
  14. }
  15. });
  16.  
  17. <div class="filter">
  18. <sup class="toggler">
  19. <i class="icon-minus"></i>
  20. </sup>
  21. </div>
  22.  
  23. 1: Object[i.icon-minus]
  24. hasclass - minus
  25. 2: Object[i.icon-plus]
  26. hasclass - minus
  27. 3: Object[i.icon-plus]
  28. hasclass - minus
  29.  
  30. document.getElements('.toggler').addEvent('click', function(e){
  31. e && e.stop();
  32. // the i and the div won't change. only get them from DOM once.
  33. var i = this.retrieve('i', this.getElement('i')),
  34. next = this.retrieve('next', this.getNext('div')),
  35. // keep state in storage also, no need to query dom all the time.
  36. isCollapsed = this.retrieve('state', i.hasClass('icon-plus'));
  37.  
  38. // based upon current state (which we don't need in DOM after the first time)
  39. // calls either hide or show dynamically.
  40. next[['hide', 'show'][+isCollapsed]]();
  41. // all we want is to swap the classes, use toggleClass.
  42. i.toggleClass('icon-plus').toggleClass('icon-minus');
  43. // save new state
  44. this.store('state', !isCollapsed);
  45. });
  46.  
  47. [i.icon-minus, $family: function, $constructor: function,// etc
  48.  
  49. [false, $family: function, $constructor: function, each: function, // etc
  50.  
  51. var target = this.getFirst('i');
  52. //or
  53. var target = this.getElement('i');
  54.  
  55. target.each(function(thisElement){
  56.  
  57. if (thisElement.hasClass('icon-minus')) {
  58. thisElement.addClass('icon-plus').removeClass('icon-minus');
  59. this.getNext('div').hide();
  60. } else {
  61. thisElement.addClass('icon-minus').removeClass('icon-plus');
  62. this.getNext('div').show();
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement