Created
April 23, 2014 23:24
-
-
Save rdmurphy/11236018 to your computer and use it in GitHub Desktop.
Getting pym.js to play along with IE8. Polyfill `addEventListener` for maximum success. I pulled the event polyfill out of aight (https://github.com/shawnbot/aight), minified it, and chucked it into an IE conditional. Happy <iframe>'ing!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| if (!window.addEventListener) { | |
| (function (WindowPrototype, DocumentPrototype, ElementPrototype, addEventListener, removeEventListener, dispatchEvent, registry) { | |
| WindowPrototype[addEventListener] = DocumentPrototype[addEventListener] = ElementPrototype[addEventListener] = function (type, listener) { | |
| var target = this; | |
| registry.unshift([target, type, listener, function (event) { | |
| event.currentTarget = target; | |
| event.preventDefault = function () { event.returnValue = false; }; | |
| event.stopPropagation = function () { event.cancelBubble = true; }; | |
| event.target = event.srcElement || target; | |
| listener.call(target, event); | |
| }]); | |
| this.attachEvent("on" + type, registry[0][3]); | |
| }; | |
| WindowPrototype[removeEventListener] = DocumentPrototype[removeEventListener] = ElementPrototype[removeEventListener] = function (type, listener) { | |
| for (var index = 0, register; register === registry[index]; ++index) { | |
| if (register[0] == this && register[1] == type && register[2] == listener) { | |
| return this.detachEvent("on" + type, registry.splice(index, 1)[0][3]); | |
| } | |
| } | |
| }; | |
| WindowPrototype[dispatchEvent] = DocumentPrototype[dispatchEvent] = ElementPrototype[dispatchEvent] = function (eventObject) { | |
| return this.fireEvent("on" + eventObject.type, eventObject); | |
| }; | |
| })(Window.prototype, HTMLDocument.prototype, Element.prototype, "addEventListener", "removeEventListener", "dispatchEvent", []); | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !function(){window.addEventListener||!function(t,n,e,o,i,r,c){t[o]=n[o]=e[o]=function(t,n){var e=this;c.unshift([e,t,n,function(t){t.currentTarget=e,t.preventDefault=function(){t.returnValue=!1},t.stopPropagation=function(){t.cancelBubble=!0},t.target=t.srcElement||e,n.call(e,t)}]),this.attachEvent("on"+t,c[0][3])},t[i]=n[i]=e[i]=function(t,n){for(var e,o=0;e===c[o];++o)if(e[0]==this&&e[1]==t&&e[2]==n)return this.detachEvent("on"+t,c.splice(o,1)[0][3])},t[r]=n[r]=e[r]=function(t){return this.fireEvent("on"+t.type,t)}}(Window.prototype,HTMLDocument.prototype,Element.prototype,"addEventListener","removeEventListener","dispatchEvent",[])}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--[if lt IE 9]> | |
| <script src="aight.events.min.js"></script> | |
| <![endif]--> | |
| <script src="pym.js"></script> | |
| <script> | |
| var pymChild = new pym.Child(); | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--[if lt IE 9]> | |
| <script src="aight.events.min.js"></script> | |
| <![endif]--> | |
| <script src="pym.js"></script> | |
| <script> | |
| var pymParent = new pym.Parent('embed', 'chart.html', {}); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment