jonathantneal / EventListener

EventListener Polyfill for IE
Other
148 stars 32 forks source link

Event firing order issue in IE6 / IE7 version #9

Open jslegers opened 11 years ago

jslegers commented 11 years ago

I tried doing the following :

With the IE8 version, my code breaks completely ( see https://github.com/jonathantneal/EventListener/issues/8 )

With the IE6/IE7 version, event handling works fine for each of the selections and behaves the same across IE6-IE8. The only isue I'm having, is the classic random event firing order problem : when I hover above my span, it fires the second event first.

JamesMGreene commented 11 years ago

IIRC, the only way to get around this is to run your own event system to abstract it away, e.g. the underlying code attaches one handler per event type per element (when a user-defined handler is first added for that event-element pair), and then that handler is responsible for managing and dispatching all of the user-defined handlers.

Basic implementation concept from jQuery core: https://github.com/jquery/jquery/blob/ef154cc530155bc1d39840761313649eddcaae3a/src/event.js#L102-117

jonathantneal commented 11 years ago

I'm stoked to see the recent attention to this script. I continued my work on this script @ https://github.com/jonathantneal/polyfill/blob/master/source/Window.prototype.Event.ie8.js

I will backport it to this project.

JamesMGreene commented 11 years ago

Can't speak for @jslegers but I'm more than happy to just watch the new repo instead. I'd hate to miss fixes and such if you're not actively backporting to here.

jonathantneal commented 11 years ago

@JamesMGreene, I'd also love to know what you think of the polyfill project.

jslegers commented 11 years ago

@JamesMGreene & @jonathantneal :

I think polyfills are a much better solution for dealing with browser differences than abstraction layers as it offers much better performance for modern browsers for any custom JS implementation that needs to be cross-browser. I definitely support projects like the polyfill project for trying to provide a complete solution to take care of this.

What I don't like about the polyfill project in its current form, is that it gives you a monolithic file containing all the polyfills it thinks you need baded on browser sniffing. One reason is browser sniffing being unreliable and not very future proof. Another reason is my preference for asynchronously loaded modules in favor of monolithic files.

I would prefer feature sniffing a la Modernizr and a modular file system with one implemented feature per file. You'd then just run a configurable range of tests and asynchronously load the corresponding polyfill only when a test fails, using using a module loader like RequireJS ( http://requirejs.org/ ), YepNope ( http://yepnopejs.com/ ) or LABjs ( http://labjs.com/ ).

To avoid an unnecessary amount of tests for modern browsers, you could run tests in hierarchies, with tests for older features only being executed if tests for newer features fail. Or you could just have users run a test whenever they need a certain feature rather than in advance, to avoid any polyfills being loaded that you never are going to use anyway.

Anyway, at the moment I care most about adding support for standard implementations of QuerySelector / QuerySelectorAll , AddEventListener, XMLHttpRequest, JSON.parse and DOMParser to IE6-IE8. How many of these are fully implemented in the polyfill project and where can I find them? I'm a bit confused about how the source code is structured.

JamesMGreene commented 11 years ago

I have some of the same concerns as @jslegers:

  1. Not a fan of the UA sniffing but it is an interesting technique for the purpose of minimalistic polyfilling via a single script tag.
  2. I am also very confused about the structure of the polyfill project, especially regarding which files are used for which versions of IE (and friends).
jslegers commented 11 years ago

@JamesMGreene & @jonathantneal :

Dynamic asynchronous loading also allows you to use a single script tag.

Here's how I organised my JS code in Cascade Framework ( http://cascade-framework.com/ ) :

The file at the bottom does the following :

The files loaded with YepNope are the following sequence :

You can find the actual code at https://github.com/jslegers/cascadeframework/blob/master/assets/js/app.js

The site-specific code loads dependencies in a similar way :

You can find the actual code at https://github.com/jslegers/cascadeframework/blob/master/assets/js/site.js

Note that this is very alpha-stage code that can most definitely be improved in a multitude of ways, but it does work as expected in IE6+, Opera, Firefox, Chrome and Safari. I think a similar structure might be interesting for a project like the polyfill project.

jonathantneal commented 11 years ago

The polyfill project is:

All of these polyfills rely on existing, platform-agnostic JavaScript. For instance, Window.prototype.Event polyfills window.Event by relying on document.createEvent. As opposed to...

All of these polyfills rely on legacy, platform-specific technologies. For instance, Window.prototype.localStorage.ie7 relies on IE≤7's element.addBehavior('#default#userdata'), Window.prototype.getComputedStyle.ie8 relies on IE≤8's element.currentStyle, and Element.prototype.matches.o relies on Opera≤12's Element.prototype.oMatchesSelector method.

To avoid the pitfalls of UA sniffing ( future-proofing technologies not yet implemented in the latest releases of the browser ), scripts like Element.prototype.matches.webkit check for Element.prototype.matches before patching it with the vendor-specific Element.prototype.webkitMatchesSelector.

I agree that UA sniffing is a dangerous game that turns off developers who recall its historical abuse as a means of future-proofing. I believe that sniffing for IE6, IE7, and IE8 is very reliable and very future proof, considering that Microsoft will not be releasing a new IE6, IE7, or IE8 browser.

I think of it this way; my project does not sniff for the future. it sniffs for the past.

Please let me know if you are still confused about the structure of the polyfill project, or if you are still concerned about the polyfill project and future proofing. I hope I've explained the project clearly, and I'm totally open to exploring these concerns further.

JamesMGreene commented 11 years ago

@jonathantneal Thanks for the background.

@jslegers You might be interested in mout.

jonathantneal commented 11 years ago

If any of you would like to help modularize polyfill for those who prefer feature tests, let me know.