" target="_blank">http://creativecommons.org/licenses/LGPL/2.1/>;
*/
/* Implement array.push for browsers which don't support it natively.
Please remove this if it's already in other code */
if (Array.prototype.push ==
null ){
Array.prototype.push =
function (){
for ( var i =
0 ; i < arguments.length; i ++ ){
this [ this .length] = arguments;
};
return
this .length;
};
};
/* Event Cache uses an anonymous function to create a hidden scope chain.
This is to prevent scoping issues. */
var EventCache =
function (){
var listEvents = [];
return {
listEvents : listEvents,
add : function (node, sEventName, fHandler, bCapture){
listEvents.push(arguments);
},
flush : function (){
var i, item;
for (i = listEvents.length -
1 ; i >=
0 ; i = i -
1 ){
item = listEvents;
if (item[ 0 ].removeEventListener){
item[ 0 ].removeEventListener(item[ 1 ], item[ 2 ], item[ 3 ]);
};
/* From this point on we need the event names to be prefixed with 'on" */
if (item[ 1 ].substring( 0 , 2 ) !=
" on " ){
item[ 1 ] =
" on "
+ item[ 1 ];
};
if (item[ 0 ].detachEvent){
item[ 0 ].detachEvent(item[ 1 ], item[ 2 ]);
};
item[ 0 ][item[ 1 ]] =
null ;
};
}
};
}();
/* Implementing EventCache for all event systems */
EventCache.add(oEventTarget, sEventType, fDest, true);
};
function createLeak(){
var body = document.body;
function someHandler(){
return body;
};
addEvent(body, "click", someHandler);
};
window.onload = function(){
var i = 500;
while(i > 0){
createLeak();
i = i - 1;
}
};
window.onunload = EventCache.flush;
</script>
var EventManager = {
_registry: null ,
Initialise: function () {
if ( this ._registry ==
null ) {
this ._registry = [];
// Register the cleanup handler on page unload.
EventManager.Add(window, " unload " , this .CleanUp);
}
},
/* *
* Registers an event and handler with the manager.
*
* @param obj Object handler will be attached to.
* @param type Name of event handler responds to.
* @param fn Handler function.
* @param useCapture Use event capture. False by default.
* If you don't understand this, ignore it.
*
* @return True if handler registered, else false.
*/
Add: function (obj, type, fn, useCapture) {
this .Initialise();
// If a string was passed in, it's an id.
if ( typeof obj ==
" string " ) {
obj = document.getElementById(obj);
}
if (obj ==
null
|| fn ==
null ) {
return
false ;
}
// Mozilla/W3C listeners?
if (obj.addEventListener) {
obj.addEventListener(type, fn, useCapture);
this ._registry.push({obj: obj, type: type, fn: fn, useCapture: useCapture});
return
true ;
}
// IE-style listeners?
if (obj.attachEvent && obj.attachEvent( " on "
+ type, fn)) {
this ._registry.push({obj: obj, type: type, fn: fn, useCapture: false });
return
true ;
}
return
false ;
},
/* *
* Cleans up all the registered event handlers.
*/
CleanUp: function () {
for ( var i =
0 ; i < EventManager._registry.length; i ++ ) {
with (EventManager._registry) {
// Mozilla/W3C listeners?
if (obj.removeEventListener) {
obj.removeEventListener(type, fn, useCapture);
}
// IE-style listeners?
else
if (obj.detachEvent) {
obj.detachEvent( " on "
+ type, fn);
}
}
}
// Kill off the registry itself to get rid of the last remaining
// references.
EventManager._registry =
null ;
}
};
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。