Guest User

Untitled

a guest
Mar 1st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // +---------------------------------------------------------------------------+
  2. // | This file is part of the MrJeep Agavi Extension package. |
  3. // | Copyright (c) 2006, 2007 Jean-Philippe Dery |
  4. // | |
  5. // | For the full copyright and license information, please view the LICENSE |
  6. // | file that was distributed with this source code. |
  7. // +---------------------------------------------------------------------------+
  8.  
  9. /**
  10. * Mjax.Selector is a mootools implementation of the original event selector.
  11. * This been ported to mootools by rossco.
  12. *
  13. * @package mjax
  14. * @subpackage behavior
  15. *
  16. * @author Ross Lawley
  17. * @author Jean-Philippe Dery (jeanphilippe_dery@hotmail.com)
  18. * @copyright Ross Lawley
  19. * @since 1.0.0
  20. * @version 1.0.0
  21. */
  22.  
  23. Mjax.Selector = new Class(
  24. {
  25.  
  26. // +-----------------------------------------------------------------------+
  27. // | METHODS |
  28. // +-----------------------------------------------------------------------+
  29.  
  30. /**
  31. * Constructor. Register the behaviors rules. Those rules are stored into
  32. * an object and they are used to separate the javascript from the html
  33. * in a nice clean way.
  34. *
  35. * @param object The rules.
  36. *
  37. * @return void
  38. *
  39. * @author Jean-Philippe Dery (jeanphilippe_dery@hotmail.com)
  40. * @since 1.0.0
  41. */
  42.  
  43. start: function(rules)
  44. {
  45.  
  46. window.onDomReady(function(){this.assign(rules);}.bind(this));
  47.  
  48. },
  49.  
  50. // ------------------------------------------------------------------------
  51.  
  52. /**
  53. * Assign the behaviors rules. Those rules are stored into an object and
  54. * they are used to separate the javascript from the html in a nice clean
  55. * way.
  56. *
  57. * @param object The rules.
  58. *
  59. * @return void
  60. *
  61. * @author Jean-Philippe Dery (jeanphilippe_dery@hotmail.com)
  62. * @since 1.0.0
  63. */
  64.  
  65. assign : function(rules)
  66. {
  67.  
  68. for(var key in rules)
  69. {
  70.  
  71. var rule = rules[key];
  72.  
  73. // Loop through all the selectors which are
  74. // separated by a ,
  75.  
  76. key.clean().split(',').each(function(selector)
  77. {
  78.  
  79. var pair = selector.split(':');
  80.  
  81. $$(pair[0]).each(function(elem)
  82. {
  83.  
  84. // Let see if there is no events binded to the selector. In
  85. // this case we just fire the rule
  86.  
  87. if (pair.length == 1)
  88. {
  89.  
  90. return rule(elem);
  91.  
  92. }
  93.  
  94. // At this point we have an event attached
  95. // to the selector so we simply add the event
  96.  
  97. elem.addEvent(pair[1], rule.pass(elem));
  98.  
  99. });
  100.  
  101. });
  102.  
  103. }
  104.  
  105. },
  106.  
  107. });
Add Comment
Please, Sign In to add comment