Advertisement
Guest User

Untitled

a guest
May 27th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. function handlers($el) {
  2. $el = $($el);
  3. var events = $._data(document.body).events;
  4. var matched_handlers = [];
  5. Object.keys(events).forEach(function(event_type) {
  6. var handlers = events[event_type].filter(function (handler) {
  7. if (!handler.selector) { return false; }
  8. return $el.is(handler.selector) || $el.has(handler.selector).length;
  9. });
  10. matched_handlers = matched_handlers.concat(handlers)
  11. });
  12. return matched_handlers;
  13. }
  14.  
  15. function controls_for_handler(handler) {
  16. return $(document.body).controls().filter(function (control) {
  17. var actions = control.constructor.actions;
  18. var action = handler.selector + ' ' + handler.origType;
  19. return actions[action];
  20. });
  21. }
  22.  
  23. var obs = new MutationObserver(function(mutations) {
  24. mutations.forEach(function (mutation) {
  25. [].forEach.call(mutation.addedNodes, function (node) {
  26. var h = handlers(node);
  27. if (!h.length) {
  28. return;
  29. }
  30. var controls = [];
  31. h.forEach(function (handler) {
  32. controls = controls.concat(controls_for_handler(handler));
  33. });
  34. controls = controls.reduce(function (prev, current, i, arr) {
  35. console.log(current, prev.indexOf(current), prev);
  36. if (prev.indexOf(current) === -1) {
  37. prev.push(current);
  38. }
  39. return prev;
  40. }, []);
  41. console.log('node has handler(s), control(s)', node, h, controls);
  42. });
  43. });
  44. });
  45. obs.observe(document.body, {childList: true})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement