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 addEvent( 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 {obj["on"+type] = obj["e"+type+fn];} |
---|
20 | } |
---|
21 | |
---|
22 | var EventCache = function(){ |
---|
23 | var listEvents = []; |
---|
24 | return { |
---|
25 | listEvents : listEvents, |
---|
26 | add : function(node, sEventName, fHandler){ |
---|
27 | listEvents.push(arguments); |
---|
28 | }, |
---|
29 | flush : function(){ |
---|
30 | var i, it; |
---|
31 | for(i = listEvents.length - 1; i >= 0; i = i - 1){ |
---|
32 | it = listEvents[i]; |
---|
33 | if(it[0].removeEventListener){ |
---|
34 | it[0].removeEventListener(it[1], it[2], it[3]);}; |
---|
35 | if(it[1].substring(0, 2) != "on"){it[1] = "on" + it[1];}; |
---|
36 | if(it[0].detachEvent){it[0].detachEvent(it[1], it[2]);}; |
---|
37 | it[0][it[1]] = null;}; |
---|
38 | } };}(); |
---|
39 | addEvent(window,'unload',EventCache.flush); |
---|