Skip to content

Instantly share code, notes, and snippets.

@sedoyjan
Forked from danburzo/README.md
Created November 8, 2019 07:12
Show Gist options
  • Select an option

  • Save sedoyjan/6cfba5ae749f62da3b7256eb6bf9287d to your computer and use it in GitHub Desktop.

Select an option

Save sedoyjan/6cfba5ae749f62da3b7256eb6bf9287d to your computer and use it in GitHub Desktop.

Revisions

  1. @danburzo danburzo revised this gist Dec 10, 2014. 2 changed files with 30 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,6 @@ var items = Array.prototype.slice.call(
    };
    }).filter(function(item) {
    return item.listeners.length;
    });
    });

    // See below for things you can do with the items
    27 changes: 27 additions & 0 deletions what-to-do.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // Things you can do with the items

    // 1. log them to the console
    console.log(items);


    // 2. Put a red border around the elements
    items.forEach(function(item) {
    item.element.style.outline = '1px solid red';
    })

    // 3. generate a summary
    var summary = .map(function(item) {
    var el = item.element,
    id = el.id,
    className = el.className;
    if (className instanceof SVGAnimatedString) {
    className = className.baseVal;
    }
    var str = el.tagName.toLowerCase() + (id ? '#' + id : '') + (className ? '.' + className.replace(/\s+/g, '.') : '');
    str += ' ' + item.listeners.map(function(l) {
    return l.event + ': ' + l.listeners.length;
    }).join(' ');
    return str;
    }).join('\n');

    console.log(summary);
  2. @danburzo danburzo revised this gist Dec 10, 2014. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    var items = Array.prototype.slice.call(
    document.querySelectorAll('*')
    document.querySelectorAll('*')
    ).map(function(element) {
    var listeners = getEventListeners(element);
    return {
    element: element,
    listeners: Object.keys(listeners).map(function(k) {
    return { event: k, listeners: listeners[k] };
    })
    };
    var listeners = getEventListeners(element);
    return {
    element: element,
    listeners: Object.keys(listeners).map(function(k) {
    return { event: k, listeners: listeners[k] };
    })
    };
    }).filter(function(item) {
    return item.listeners.length;
    return item.listeners.length;
    });
  3. @danburzo danburzo revised this gist Dec 10, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    Array.prototype.slice.call(
    var items = Array.prototype.slice.call(
    document.querySelectorAll('*')
    ).map(function(el) {
    var listeners = getEventListeners(el);
    ).map(function(element) {
    var listeners = getEventListeners(element);
    return {
    element: el,
    element: element,
    listeners: Object.keys(listeners).map(function(k) {
    return { event: k, listeners: listeners[k] };
    })
  4. @danburzo danburzo revised this gist Dec 10, 2014. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    Array.prototype.slice.call(
    document.querySelectorAll('*')
    ).map(function(el) {
    return {
    element: el,
    listeners: getEventListeners(el)
    };
    }).filter(function(o) {
    return Object.keys(o.listeners).length > 0;
    document.querySelectorAll('*')
    ).map(function(el) {
    var listeners = getEventListeners(el);
    return {
    element: el,
    listeners: Object.keys(listeners).map(function(k) {
    return { event: k, listeners: listeners[k] };
    })
    };
    }).filter(function(item) {
    return item.listeners.length;
    });
  5. @danburzo danburzo revised this gist Feb 27, 2014. 1 changed file with 10 additions and 12 deletions.
    22 changes: 10 additions & 12 deletions event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,10 @@
    function eventListeners(rootElement) {
    return Array.prototype.slice.call(
    (rootElement || document).querySelectorAll('*')
    ).map(function(el) {
    return {
    element: el,
    listeners: getEventListeners(el)
    };
    }).filter(function(o) {
    return Object.keys(o.listeners).length > 0;
    });
    };
    Array.prototype.slice.call(
    document.querySelectorAll('*')
    ).map(function(el) {
    return {
    element: el,
    listeners: getEventListeners(el)
    };
    }).filter(function(o) {
    return Object.keys(o.listeners).length > 0;
    });
  6. @danburzo danburzo created this gist Feb 27, 2014.
    12 changes: 12 additions & 0 deletions event-listeners.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function eventListeners(rootElement) {
    return Array.prototype.slice.call(
    (rootElement || document).querySelectorAll('*')
    ).map(function(el) {
    return {
    element: el,
    listeners: getEventListeners(el)
    };
    }).filter(function(o) {
    return Object.keys(o.listeners).length > 0;
    });
    };