Source code for /src/cross_browser.js.txt
// =====================================================================//
// Author: Mark Qian <markqian@hotmail.com> //
// WWW: http://www.coolshare.com/ //
// Copyright (c) 2006, Mark Qian //
// //
// You must contact Mark Qian to get a permission of use //
// in case you want to make any use of the codes except viewing it //
// on Mark's site. //
//======================================================================//
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
if (checkIt('konqueror'))
{
browser = "Konqueror";
OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
browser = "Netscape Navigator"
version = detect.charAt(8);
}
else browser = "An unknown browser";
if (!version) version = detect.charAt(place + thestring.length);
if (!OS)
{
if (checkIt('linux')) OS = "Linux";
else if (checkIt('x11')) OS = "Unix";
else if (checkIt('mac')) OS = "Mac"
else if (checkIt('win')) OS = "Windows"
else OS = "an unknown operating system";
}
function checkIt(string)
{
place = detect.indexOf(string) + 1;
thestring = string;
return place;
}
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else
this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.getChildren){
HTMLElement.prototype.getChildren = function()
{
if (this.children)
return this.children;
return this.childNodes;
}
}
function sortedInsert(arr, obj, cField) {
if (arr.length==0) {
arr[0] = obj;
return;
}
for (var i=0; i<arr.length; i++) {
var f1 = parseInt(eval("obj."+cField));
var f2 = parseInt(eval("arr[i]."+cField));
if (f1<f2) {
shift(arr, i);
arr[i] = obj;
return;
}
}
arr[arr.length] = obj;
}
function shift(arr, n) {
for (var i=arr.length; i>n; i--) {
arr[i] = arr[i-1];
}
}
function insertDomNode(doc, o, tn, attri, where) {
var tt = "";
for (i in attri) {
tt += i+"="+attri[i]+" ";
}
o.insertAdjacentHTML( where, "<"+tn+" "+tt+"></"+tn+">");
return doc.getElementById(attri['id']);
}
function getEvent(e) {
//debugger
if (!e)
e = window.event;
if (!e)
e = event;
return e;
}
function getSrcElement(e) {
var e = getEvent(e);
if (e.srcElement)
return e.srcElement;
else
return e.originalTarget;
}
function getChildren(p) {
if (p.children)
return p.children;
return p.childNodes;
}
function getTBody(t) {
var tbs = getChildren(t);
for (var i=0; i<tbs.length; i++) {
if (tbs[i].tagName && tbs[i].tagName.toLowerCase()=="tbody")
return tbs[i];
}
return t;
}
function byId(id){
return document.getElementById(id);
}