Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to correctly use .each here?
    primarykey
    data
    text
    <p>This is basically for a library I'm building. In this module I'll attempt to build a debug helper library to help me during debugging.</p> <p>My problems here are that when <code>FDL.D.ListEvents()</code> is called a couple of awkward things happen:</p> <blockquote> <p>1) If I include enough <code>_logEvent()</code> calls, the last few stop closing their groups at the console, which makes it completely unreadable.</p> <p>2) It "decides" that it listed less events than it actually did.</p> </blockquote> <p>When I use <code>_logEvent()</code> on, for instance, just the mouseevents, it lists them kind of "correctly", or at least in the way I'd expect the function to work, revealing and counting around 20 events on the DOM (though the timespan is determined to be zero, which is kind of weird). </p> <blockquote> <p>Apparently I'm too dangerous to post images :( <strong>Edit: ! Now I can!</strong></p> </blockquote> <p>Output image:</p> <p><br/></p> <p><img src="https://i.stack.imgur.com/iol5g.jpg" alt="Working ListEvents()"> </p> <p><br/> <br/></p> <p>When I call the function with the full listing of events, I get this weird output format instead:</p> <p><br/></p> <p><img src="https://i.stack.imgur.com/YaJsy.jpg" alt="Broken listing"></p> <p><br/> <br/></p> <p>The following would be the standalone part of the lib (you can run it) that is supposed to do the magic</p> <pre><code>var FDL = FDL || {}; // FIREBUG DEBUG LIBRARY FDL.D = (function() { function _logEvents(eventName) { var _arr = $(":visible"); var _count = 0; console.groupCollapsed(eventName); _arr.each(function(idx) { var _el = this; var _id = _el.id; if(!_id){ _id = _el.tagName; } var _ev = eval("_el." + eventName); if(_ev){ console.log("%o\n" + _ev + "\n\n",$(this)); _count++; } }); console.log(_count + " " + eventName + " events"); console.groupEnd(); return _count; } return { ListEvents : function () { var _start = new Date().getTime(); var _count = 0; console.group("Events"); _count += _logEvents("onblur"); _count += _logEvents("onchange"); _count += _logEvents("onclick"); _count += _logEvents("ondblclick"); _count += _logEvents("onerror"); _count += _logEvents("onfocus"); _count += _logEvents("onkeydown"); _count += _logEvents("onkeypress"); _count += _logEvents("onkeyup"); _count += _logEvents("onmousedown"); _count += _logEvents("onmousemove"); _count += _logEvents("onmouseout"); _count += _logEvents("onmouseover"); _count += _logEvents("onmouseup"); _count += _logEvents("onresize"); _count += _logEvents("onselect"); _count += _logEvents("onunload"); var _diff = new Date(new Date().getTime() - _start).getSeconds(); console.groupCollapsed("details"); console.log(_count + " events bound"); console.log(_diff + "s runtime"); console.groupEnd(); console.groupEnd(); } }; })(); </code></pre> <p><br/></p> <p>I tried a few ideas but I couldn't come up with the right solution to make these <code>_logEvent()</code> calls chain in the expected order. The problem basically being that <code>.each()</code> is called async and I suppose this is what breaks my code's execution order.</p> <p><br/></p> <hr> <p>Thanks for your input! &lt;3 stackoverflow</p> <p><strong>EDIT:</strong> I changed the groupCollapsed() calls with group() calls and it has worked indeed. Now I face a different problem, how should I make it so it only displays once for each event name the bindings as long as the bound function is the same?</p> <p>For instance if somewhere we had <code>$(":input").click(function(){alert("Clicked!");});</code></p> <p>I'd like <code>_logEvents("onclick")</code> to display the function and selector just once, but display how many times it was bound. For instance if we had 4 inputs, the output would be:</p> <blockquote> <p>jQuery(:input) Len:1 function () {alert("Clicked!");} </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload