1 | Array.prototype.inArray = function (value) { |
---|
2 | var i; |
---|
3 | for (i=0; i < this.length; i++) { |
---|
4 | if (this[i] === value) { |
---|
5 | return true;} |
---|
6 | } |
---|
7 | return false; |
---|
8 | }; |
---|
9 | |
---|
10 | function addEvent2( obj, type, fn ) { |
---|
11 | if (obj.addEventListener) { |
---|
12 | obj.addEventListener( type, fn, false ); |
---|
13 | EventCache.add(obj, type, fn);} |
---|
14 | else if (obj.attachEvent) { |
---|
15 | obj["e"+type+fn] = fn; |
---|
16 | obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } |
---|
17 | obj.attachEvent( "on"+type, obj[type+fn] ); |
---|
18 | EventCache.add(obj, type, fn);} |
---|
19 | else { |
---|
20 | obj["on"+type] = obj["e"+type+fn]; |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | var EventCache = function(){ |
---|
25 | var listEvents = []; |
---|
26 | return { |
---|
27 | listEvents : listEvents, |
---|
28 | add : function(node, sEventName, fHandler){ |
---|
29 | listEvents.push(arguments); |
---|
30 | }, |
---|
31 | flush : function(){ |
---|
32 | var i, it; |
---|
33 | for(i = listEvents.length - 1; i >= 0; i = i - 1){ |
---|
34 | it = listEvents[i]; |
---|
35 | if(it[0].removeEventListener){ |
---|
36 | it[0].removeEventListener(it[1], it[2], it[3]);}; |
---|
37 | if(it[1].substring(0, 2) != "on"){it[1] = "on" + it[1];}; |
---|
38 | if(it[0].detachEvent){it[0].detachEvent(it[1], it[2]);}; |
---|
39 | it[0][it[1]] = null;}; |
---|
40 | } };}(); |
---|
41 | addEvent2(window,'unload',EventCache.flush); |
---|