This file contains 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 ( 'function' !== typeof window.addEventListener ) { | |
(function ( win, doc ) { | |
function docHijack( p ) { | |
var old = doc[p]; | |
doc[ p ] = function ( v ) { | |
return addListen( old( v ) ); | |
}; | |
} | |
function addEvent ( on, fn, self ) { | |
return ( self = this ).attachEvent( 'on' + on, function ( e ) { | |
var ev = e || win.event; | |
ev.preventDefault = ev.preventDefault || function () { | |
ev.returnValue = false; | |
}; | |
ev.stopPropagation = ev.stopPropagation || function () { | |
ev.cancelBubble = true; | |
}; | |
fn.call( self, ev ); | |
}); | |
} | |
function addListen ( obj, i ) { | |
i = obj.length; | |
if ( i ) { | |
while ( i-- ) { | |
obj[ i ].addEventListener = addEvent; | |
} | |
} else { | |
obj.addEventListener = addEvent; | |
} | |
return obj; | |
} | |
addListen( [ doc, win ] ); | |
if ( 'Element' in win ) { | |
// IE8 | |
win.Element.prototype.addEventListener = addEvent; | |
} else { | |
//IE < 8 | |
//Make sure we also init at domReady | |
doc.attachEvent( 'onreadystatechange', function () { | |
addListen( doc.all ); | |
}); | |
docHijack( 'getElementsByTagName' ); | |
docHijack( 'getElementById' ); | |
docHijack( 'createElement' ); | |
addListen( doc.all ); | |
} | |
}( window, document )); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment