1/* 2* This library appends to DOM interface IE-proprietary extensions 3* 4* @version 1.1 5* @title DOMExtensions 6* @author Ilya Lebedev (ilya@lebedev.net), (c) 2004-2005 7* @license GNU LGPL 8* 9* This library is free software; you can redistribute it and/or 10* modify it under the terms of the GNU Lesser General Public 11* License as published by the Free Software Foundation; either 12* version 2.1 of the License, or (at your option) any later version. 13* See http://www.gnu.org/copyleft/lesser.html 14*/ 15 16if (Node && !Node.prototype) { 17 var node = document.createTextNode(''); 18 var Node = node.constructor; 19} 20if (window.Node) { 21 Node.prototype.removeNode = function(removeChildren) { 22 var self = this; 23 if (Boolean(removeChildren) || this.childNodes.length<1) 24 return this.parentNode.removeChild( self ); 25 else { 26 var r=document.createRange(); 27 r.selectNodeContents(self); 28 return this.parentNode.replaceChild(r.extractContents(),self); 29 } 30 } 31 Node.prototype.swapNode = function(swapNode) { 32 var self = this; 33 n = self.cloneNode(true); 34 nt = swapNode.cloneNode(true); 35 self.parentNode.insertBefore(nt,self); 36 self.removeNode(true); 37 swapNode.parentNode.insertBefore(n,swapNode); 38 swapNode.removeNode(true); 39 } 40 if (!Node.prototype.attachEvent) 41 Node.prototype.attachEvent = function (e,f,c) { 42 var self = this; 43 return self.addEventListener(e.substr(2), f, false); // was true--Opera7b workaround! 44 } 45 if (!Node.prototype.fireEvent) 46 Node.prototype.fireEvent = function (e) { 47 var eventTypes = { resize : ['HTMLEvents',1,0], 48 scroll : ['HTMLEvents',1,0], 49 focusin : ['HTMLEvents',0,0], 50 focusout : ['HTMLEvents',0,0], 51 gainselection : ['HTMLEvents',1,0], 52 loseselection : ['HTMLEvents',1,0], 53 activate : ['HTMLEvents',1,1], 54 //events above should be UIEvents, but Mozilla seems does not support this type 55 //or refuses to create such event from inside JS 56 load : ['HTMLEvents',0,0], 57 unload : ['HTMLEvents',0,0], 58 abort : ['HTMLEvents',1,0], 59 error : ['HTMLEvents',1,0], 60 select : ['HTMLEvents',1,0], 61 change : ['HTMLEvents',1,0], 62 submit : ['HTMLEvents',1,1], 63 reset : ['HTMLEvents',1,0], 64 focus : ['HTMLEvents',0,0], 65 blur : ['HTMLEvents',0,0], 66 click : ['MouseEvents',1,1], 67 mousedown : ['MouseEvents',1,1], 68 mouseup : ['MouseEvents',1,1], 69 mouseover : ['MouseEvents',1,1], 70 mousemove : ['MouseEvents',1,0], 71 mouseout : ['MouseEvents',1,0], 72 keypress : ['KeyEvents',1,1], 73 keydown : ['KeyEvents',1,1], 74 keyup : ['KeyEvents',1,1], 75 DOMSubtreeModified : ['MutationEvents',1,0], 76 DOMNodeInserted : ['MutationEvents',1,0], 77 DOMNodeRemoved : ['MutationEvents',1,0], 78 DOMNodeRemovedFromDocument : ['MutationEvents',0,0], 79 DOMNodeInsertedIntoDocument : ['MutationEvents',0,0], 80 DOMAttrModified : ['MutationEvents',1,0], 81 DOMCharacterDataModified : ['MutationEvents',1,0] 82 }; 83 var self = this; 84 e = e.substr(2); 85 if (!eventTypes[e]) return false; 86 var evt = document.createEvent(eventTypes[e][0]); 87 evt.initEvent(e,eventTypes[e][1],eventTypes[e][2]); 88 return self.dispatchEvent(evt); 89 } 90} 91if (!window.attachEvent) { 92 window.attachEvent= function (e,f,c) { 93 var self = this; 94 if (self.addEventListener) self.addEventListener(e.substr(2), f, false); // was true--Opera7b workaround! 95 else self[e] = f; // thing for Opera 6...... 96 } 97}