Comments (4)
Thanks! Probably the most complete and popular polyfill is this one. I've now referenced that from the README as the preferred choice.
from eventlisteneroptions.
Right you are. Seems EventTarget isn't in Webkit's prototype chain at all. I'll try to fix this this morning.
from eventlisteneroptions.
Didn't work in IE11 either. I made a EventTarget.js polyfill from this;
(function() {
if (!Event.prototype.preventDefault) {
Event.prototype.preventDefault=function() {
this.returnValue=false;
};
}
if (!Event.prototype.stopPropagation) {
Event.prototype.stopPropagation=function() {
this.cancelBubble=true;
};
}
if (!Element.prototype.addEventListener) {
var eventListeners=[];
var addEventListener=function(type,listener /*, useCapture (will be ignored) */) {
var self=this;
var wrapper=function(e) {
e.target=e.srcElement;
e.currentTarget=self;
if (typeof listener.handleEvent != 'undefined') {
listener.handleEvent(e);
} else {
listener.call(self,e);
}
};
if (type=="DOMContentLoaded") {
var wrapper2=function(e) {
if (document.readyState=="complete") {
wrapper(e);
}
};
document.attachEvent("onreadystatechange",wrapper2);
eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper2});
if (document.readyState=="complete") {
var e=new Event();
e.srcElement=window;
wrapper2(e);
}
} else {
this.attachEvent("on"+type,wrapper);
eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper});
}
};
var removeEventListener=function(type,listener /*, useCapture (will be ignored) */) {
var counter=0;
while (counter<eventListeners.length) {
var eventListener=eventListeners[counter];
if (eventListener.object==this && eventListener.type==type && eventListener.listener==listener) {
if (type=="DOMContentLoaded") {
this.detachEvent("onreadystatechange",eventListener.wrapper);
} else {
this.detachEvent("on"+type,eventListener.wrapper);
}
eventListeners.splice(counter, 1);
break;
}
++counter;
}
};
Element.prototype.addEventListener=addEventListener;
Element.prototype.removeEventListener=removeEventListener;
if (HTMLDocument) {
HTMLDocument.prototype.addEventListener=addEventListener;
HTMLDocument.prototype.removeEventListener=removeEventListener;
}
if (Window) {
Window.prototype.addEventListener=addEventListener;
Window.prototype.removeEventListener=removeEventListener;
}
}
})();
(from: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener )
After adding that it worked in both Safari <9 and IE again. Might be something to include or link to from this polyfill? :)
from eventlisteneroptions.
Closing this issue, as all work/discussion has migrated to https://github.com/whatwg/dom/
from eventlisteneroptions.
Related Issues (20)
- Suggestion: add more event types (xxxpassive or xxx-ed) instead of EventListenerOptions HOT 4
- Write explainer doc HOT 1
- Should the passive option be part of the event listener key HOT 33
- Should passive listeners be able to stopPropagation? HOT 3
- Add simpler feature detection mechanism? HOT 21
- passive is ambiguous HOT 14
- Should preventDefault not be exposed on passive event handlers? HOT 9
- Request for an Update Demo File to be added to this Repository HOT 3
- Add library to make touch listeners passive by default
- Add library which generates "touchstarted" events HOT 1
- Could/should the polyfill simply rewrite/extend addEventListener? HOT 3
- Polyfill doesn't work in firefox 47 HOT 1
- CFC to migrate to the Web Platform WG HOT 9
- Modernizr.passiveeventlisteners does not exist? HOT 6
- Make it easier to target non-passive event listeners to specific classes HOT 10
- Warning keeps showing when using preventDefault? HOT 3
- Swiping horizontally in iOS 10 HOT 2
- Publish polyfill to NPM
- Should this repo be set to "archived"? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventlisteneroptions.