DOMContentLoaded event is not fired
-
Jonathan R.-Brochu
If I may, let me contribute to the ticket.
It appears that every events for the first element attached are never triggered.
In $w.addEventListener(), you set this.uuid to $events.length
w.addEventListener = function(type, fn){ //$log("adding event listener " + type);
if ( !this.uuid ) { this.uuid = $events.length; $events[this.uuid] = {}; } if ( !$events[this.uuid][type] ){ $events[this.uuid][type] = []; } if ( $events[this.uuid][type].indexOf( fn ) < 0 ){ $events[this.uuid][type].push( fn ); }
};BUT, in $w.dispatchEvent() you check this.uuid like so:
$debug("event target: " + event.target);
if ( event.type ) { if ( this.uuid && $events[this.uuid][event.type] ) {</code>
Effectively, this first call to $w.addEventListener() will set the element'd uuid to 0, so $w.dispatchEvent() will never triger its events.
So it should be this.uuid = $events.length+1; in both $w.addEventListener() and $w.removeEventListener()
-
Jonathan R.-Brochu
Well, I just had a little time to take a look at John Resig's original code to see were it got broken. It turns out that his code set the $events array (then simply events) with a first element, an empty object, as such:
var events = [{}];Compare it to code in Thatcher's master branch (/src/window/event.js):
var $events = [],Although never used, the first object in the events array of Resig's code made sure the check in dispatchEvent()
never failed/evaluated to false, since this.uuid, set from events.length (now $events.length) for any new element, couldn't be zero.if ( this.uuid && events[this.uuid][event.type] ) {Actually, initializing $events back to [{}] would be more elegant than using this.uuid = $events.length + 1; for both addEventListener() and removeEventListener(), as suggested is the previous ticket update (unless the change from Resig original code was done for a reason-I'm not familiar with envjs' history).
I don't have time to setup a github account, clone and submit a patch, so I'll leave it to you guys, hoping the extra details will help.
-
Thatcher
- Tag set to document, domcontentloaded, event, ready, uuid
- Milestone set to 1.0 Release
- State changed from new to resolved
- Assigned user set to Thatcher
again sorry for delay, adding this now. will be pushed out asap.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.