/** * $Id: xbrowser.js 2554 2008-08-06 14:39:49Z micke $ **/ window.isContenteEditable = false; if (!window.Node){ Node=new Object(); Node.ELEMENT_NODE = 1; Node.ATTRIBUTE_NODE = 2; Node.TEXT_NODE = 3; Node.CDATA_SECTION_NODE = 4; Node.ENTITY_REFERENCE_NODE = 5; Node.ENTITY_NODE = 6; Node.PROCESSING_INSTRUCTION_NODE = 7; Node.COMMENT_NODE = 8; Node.DOCUMENT_NODE = 9; Node.DOCUMENT_TYPE_NODE = 10; Node.DOCUMENT_FRAGMENT_NODE = 11; Node.NOTATION_NODE = 12; } function parseInt_(val) { if(val=="") return 0; if(val==null) return 0; if(val==undefined) return 0; return(parseInt(val)); } function dump(arr,level) { var dumped_text = ""; if(!level) level = 0; //The padding given at the beginning of the line. var level_padding = ""; for(var j=0;j \"" + value + "\"\n"; } } } else { //Stings/Chars/Numbers etc. dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; } return dumped_text; } var UniversalSelection = Class.create(); UniversalSelection.prototype = { nativeSelection: "", isGecko: 0, type : "None", initialize: function(sel) { this.nativeSelection = sel; if(this.nativeSelection.toString().length > 0) this.type = "text"; else this.type = "none"; if(sel.rangeCount>0) { var range = sel.getRangeAt(0); if(range.toString().length > 0 ) this.type = "text"; else { var contents = range.cloneContents(); if(contents.childNodes.length) { var firstChild = contents.childNodes[0]; if(firstChild.nodeType==1 && firstChild.tagName.toLowerCase()=="img") this.type = "control"; } } } } , createRange: function() { return new UniversalTextRange(this.nativeSelection, this); } , empty : function() { var s = this.nativeSelection; if(s.rangeCount > 0) s.removeAllRanges(); } }; var UniversalTextRange = Class.create(); UniversalTextRange.prototype = { parentElement : null, length : 0, range: null, isGecko: 0, text: "", htmlText : "", commonAncestorContainer : null, boundingLeft : 0, boundingTop : 0, startOffset : 0, endOffset : 0, initialize: function(selection, s) { this.selection = selection; this.text = selection.toString(); this.htmlText = this.text; //alert(selection.rangeCount); if(selection.rangeCount > 0) { var r = selection.getRangeAt(0); this.range = r; this.commonAncestorContainer = r.commonAncestorContainer; var contents = r.cloneContents(); var firstChild = contents.childNodes[0]; if(firstChild && firstChild.nodeType == 1) { this.commonAncestorContainer = firstChild; this.commonAncestorContainer = r.startContainer.parentNode; } if(this.commonAncestorContainer.nodeType == 3) { this.length = 0; } else { var documentFragment = r.cloneContents(); if(documentFragment.hasChildNodes()) { if(selection.toString().length>0) this.length = 0; else this.length = 1; } } this.boundingLeft = Mouse.x; this.boundingTop = Mouse.y; this.startOffset = r.startOffset; this.endOffset = r.endOffset; } } , item : function(i) { if(this.selection.rangeCount == 0) return(window.selectedElement); var r = this.selection.getRangeAt(0); var df = r.extractContents(); var item = df.childNodes[i]; r.insertNode(df); return item; } , moveStart : function(how,count) { var r = this.selection.getRangeAt(0); r.setStart(r.commonAncestorContainer,r.startOffset + count); this.selection.removeAllRanges(); this.selection.addRange(r); } , moveEnd : function(how,count) { var r = this.selection.getRangeAt(0); r.setStart(r.commonAncestorContainer,r.endOffset + count); this.selection.removeAllRanges(); this.selection.addRange(r); } , moveToElementText : function(item) { try { var r = document.createRange(); r.selectNodeContents(item); this.startOffset = r.startOffset; this.endOffset = r.endOffset; this.commonAncestorContainer = r.commonAncestorContainer; } catch(e) { alert('movetoelementtext: ' + e.message); } } , add : function(obj) { this.commonAncestorContainer = obj; this.initialize(orgSelection()); } , select : function() { var r = document.createRange(); r.setStart(this.commonAncestorContainer, this.startOffset); r.setEnd(this.commonAncestorContainer, this.endOffset); var s = window.getSelection().nativeSelection; if(typeof s != typeof undefined) { if(s.rangeCount > 0) s.removeAllRanges(); s.addRange(r); } } , compareBoundaryPoints : function(how, source) { if(this.selection.rangeCount==0) return -1; var r = this.selection.getRangeAt(0); return source.compareBoundaryPoints(how,r); } , parentElement : function() { if(this.commonAncestorContainer == null) return(window.selectedElement); var p = this.commonAncestorContainer; while(p != null && p.nodeType == 3 && p.parentNode) p = p.parentNode; return p; } , duplicate : function() { return this; } , queryCommandValue : function(cmdId) { var val = document.queryCommandValue(cmdId.toLowerCase()); return val; } , queryCommandState : function(cmdId) { var val = document.queryCommandState(cmdId.toLowerCase()); return val; } , queryCommandIndeterm : function(cmdId) { return document.queryCommandIndeterm(cmdId.toLowerCase()); } , queryCommandEnabled : function(cmdId) { return document.queryCommandEnabled(cmdId.toLowerCase()); } , execCommand : function(one,two,three) { return document.execCommand(one,two,three); } , isEqual : function(source) { if(this.selection.rangeCount==0) return -1; var r = this.selection.getRangeAt(0); return source.compareBoundaryPoints(Range.START_TO_END,r); } , pasteHTML : function(html) { this.range.deleteContents(); var df = this.range.createContextualFragment(html); this.range.insertNode(df); } }; /** * set up some IE specific stuff */ var isGecko = navigator.userAgent.indexOf('Gecko') != -1; var isSafari = navigator.userAgent.indexOf('Safari') != -1; var isIE = navigator.userAgent.indexOf('MSIE') != -1; var isIE7 = navigator.userAgent.indexOf('MSIE 7') != -1; if(isIE) { document.execCommand("LiveResize",false,true); document.execCommand("2D-Position",false,true); window.getSelection = function() { return(document.selection); } window.getContentBoxParent = function(o) { var obj = o; while(obj) { if(obj.nodeType==1 && (obj.className.match(/contentRow/) || obj.className.match(/contentBox/) || obj.id.match(/headimg/) || obj.id.match(/headresizer/) || obj.id.match(/footresizer/)) ) return(obj); else if(obj.nodeType==1 && obj.tagName.toLowerCase()=="table") return(obj); obj = obj.parentNode; } return(null); } document.onclick = function(event) { if(!event) var event = window.event; try { if($('rightcoltabs').contains(event.srcElement)) return; } catch(e) { } try { if($('rightcol').contains(event.srcElement)) return; } catch(e) { } try { if($('movebuttons').contains(event.srcElement)) return; } catch(e) { } } } else if(isGecko) { var isInTool = false; try { isInTool = inTool; } catch(e) { isInTool = false; } Element.prototype.swapNode = function(swapWith) { this.parentNode.replaceChild(swapWith,this); } var orgSelection = window.getSelection; if(isInTool) { window.getSelection = function() { return(new UniversalSelection(orgSelection())); } } // fake CollectGarbage for FireFox window.CollectGarbage = function() {} Document.prototype.elementFromPoint__target = null; CSSStyleDeclaration.prototype.getAttribute = function(name) { return(this[name]); } CSSStyleDeclaration.prototype.setAttribute = function(name,value) { this[name] = value; } Event.prototype.__defineGetter__("srcElement", function() { return this.target; } ); HTMLElement.prototype.__defineGetter__("module", function() { return this.getAttribute("module"); } ); HTMLElement.prototype.__defineGetter__("innerText", function() { return(this.textContent); }); HTMLElement.prototype.__defineSetter__("innerText", function(value) { this.textContent = value; }); HTMLElement.prototype.__defineGetter__("isContentEditable", function() { return (this.contentEditable==="true"); }); HTMLElement.prototype.replaceNode = function(replaceWith) { this.parentNode.replaceChild(replaceWith, this); } HTMLElement.prototype.removeNode = function(childrenToo) { try { if(!childrenToo) { var children = this.childNodes; for(var i=0;i