jQuery Event Stack Binder


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. (function($) {
  2. $.fn.bindIntoStack = function(namespace, func, pos) {
  3. var evt = namespace.split('.').shift();
  4.  
  5. return this
  6. .each(function() {
  7. var $this = $(this);
  8.  
  9. $this.bind(namespace, func);
  10.  
  11. var newOrder = new Array();
  12.  
  13. $.each($this.data('events')[evt], function(k) {
  14. newOrder.push(k);
  15. });
  16.  
  17. if (newOrder.length > pos + 1) {
  18. newOrder.splice(pos, 0, newOrder.pop());
  19.  
  20. var evts = new Object();
  21.  
  22. $.each(newOrder, function(k) {
  23. evts[this] = $this.data('events')[evt][this];
  24. });
  25.  
  26. $this.data('events')[evt] = evts;
  27. }
  28. });
  29. };
  30. })(jQuery);
  31.  
  32. (function($) {
  33. $.fn.reverseStack = function(namespace, func, pos) {
  34. var evt = namespace.split('.').shift();
  35.  
  36. return this
  37. .each(function() {
  38. var $this = $(this);
  39.  
  40. $this.bind(namespace, func);
  41.  
  42. var revOrder = new Array();
  43.  
  44. $.each($this.data('events')[evt], function(k) {
  45. revOrder.unshift(k);
  46. });
  47.  
  48. if (revOrder.length > pos + 1) {
  49. var evts = new Object();
  50.  
  51. $.each(revOrder, function(k) {
  52. evts[this] = $this.data('events')[evt][this];
  53. });
  54.  
  55. $this.data('events')[evt] = evts;
  56. }
  57. });
  58. };
  59. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.