Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function handlers($el) {
- $el = $($el);
- var events = $._data(document.body).events;
- var matched_handlers = [];
- Object.keys(events).forEach(function(event_type) {
- var handlers = events[event_type].filter(function (handler) {
- if (!handler.selector) { return false; }
- return $el.is(handler.selector) || $el.has(handler.selector).length;
- });
- matched_handlers = matched_handlers.concat(handlers)
- });
- return matched_handlers;
- }
- function controls_for_handler(handler) {
- return $(document.body).controls().filter(function (control) {
- var actions = control.constructor.actions;
- var action = handler.selector + ' ' + handler.origType;
- return actions[action];
- });
- }
- var obs = new MutationObserver(function(mutations) {
- mutations.forEach(function (mutation) {
- [].forEach.call(mutation.addedNodes, function (node) {
- var h = handlers(node);
- if (!h.length) {
- return;
- }
- var controls = [];
- h.forEach(function (handler) {
- controls = controls.concat(controls_for_handler(handler));
- });
- controls = controls.reduce(function (prev, current, i, arr) {
- console.log(current, prev.indexOf(current), prev);
- if (prev.indexOf(current) === -1) {
- prev.push(current);
- }
- return prev;
- }, []);
- console.log('node has handler(s), control(s)', node, h, controls);
- });
- });
- });
- obs.observe(document.body, {childList: true})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement