Created
October 19, 2010 18:52
-
-
Save jwmcpeak/634808 to your computer and use it in GitHub Desktop.
Old Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************************************ | |
XWeb Base Class v0.9.5 by Jeremy McPeak | |
Browsers Supported: | |
MSIE 5.5+ | |
Mozilla RC 1+ | |
Documentation at: http://www.wdonline.com/api/ | |
Copyright (c) 2001 Jeremy McPeak jeremy@wdonline.com | |
************************************************************************************************/ | |
function chkBrwsr(){ | |
this.v = navigator.userAgent.toLowerCase(); | |
this.dom = document.getElementById?1:0; | |
this.ie5 = (this.v.indexOf("msie 5.5") > -1 && this.dom)?1:0; | |
this.ie6 = (this.v.indexOf("msie 6") > -1 && this.dom)?1:0; | |
this.cssCompat = (this.ie6 && document.compatMode == "CSS1Compat")?1:0; | |
this.moz = (this.v.indexOf("gecko") > -1 && this.dom)?1:0; | |
//this.moz = (this.v.indexOf("rv:1.") > -1 && this.dom)?1:0; | |
var geckoVersion = (this.moz)?parseInt(navigator.productSub):0; | |
this.moz = (geckoVersion > 20020512)?1:0; //Now checking for specific Gecko versions - 20020512 is as old as I want to support. | |
this.ie = (this.ie5 || this.ie6)?1:0; | |
this.ns = (this.moz)?1:0; | |
this.dhtml = (this.ie || this.ns)?1:0; | |
} | |
var user = new chkBrwsr(); | |
if (!user.dhtml) { | |
var bContinue = confirm("The browser you are using is not capable of " + | |
"rendering this site. It is strongly recommended that you upgrade your browser. "+ | |
"Press 'OK' to head to the browser download information page, or press 'Cancel' to continue " + | |
"to the site. Please note that if you choose to continue to the site, you will more than likely " + | |
"not be able to view or navigate through the site."); | |
if (bContinue) self.location = "nodom.html"; | |
} | |
function pgObj() { | |
this.x = (user.ns)?innerWidth:(user.cssCompat)?document.documentElement.clientWidth:document.body.clientWidth; | |
this.y = (user.ns)?innerHeight:(user.cssCompat)?document.documentElement.clientHeight:document.body.clientHeight; | |
this.x2 = this.x / 2; this.y2 = this.y / 2; | |
} | |
var XWeb = { | |
all : {}, | |
XWebLayer : { | |
idNum : 0, | |
idPrefix : "xweb_layer_", | |
getID : function () { return this.idPrefix + this.idNum++; } | |
} | |
} | |
function XWebLayer(sClsName,sHTML) { | |
if (!sClsName) return; | |
this.id = XWeb.XWebLayer.getID(); | |
this.oLayer = document.createElement("DIV"); | |
this.oLayer.id = this.id; | |
this.oLayer.className = sClsName; | |
if (sHTML) this.oLayer.innerHTML = sHTML; | |
document.body.appendChild(this.oLayer); | |
this.base = XWeb_BaseClass; | |
this.base(this.id); | |
} | |
XWebLayer.prototype = new XWeb_BaseClass(); | |
XWebLayer.prototype.setClass = function (sClsName) { | |
this.oLayer.className = sClsName; | |
}; | |
XWebLayer.prototype.setHTML = function (sHTML,bClear) { | |
if (bClear) this.clearHTML(); | |
this.oLayer.innerHTML += sHTML; | |
}; | |
XWebLayer.prototype.clearHTML = function () { | |
this.oLayer.innerHTML = ""; | |
}; | |
function XWeb_BaseClass(sID) { | |
if (!sID) return; | |
this.el = document.getElementById(sID); | |
this.css = this.el.style; | |
this.id = sID; | |
XWeb.all[sID] = this; | |
if (XWebAnimatorClass) this.animator = new XWeb_Animator_Class(this); | |
} | |
XWeb_BaseClass.prototype.setTop = function (y) { | |
this.css.top = y + "px"; | |
}; | |
XWeb_BaseClass.prototype.setLeft = function (x) { | |
this.css.left = x + "px"; | |
}; | |
XWeb_BaseClass.prototype.setRight = function (x) { | |
this.css.left = (pg.x - x) + "px"; | |
}; | |
XWeb_BaseClass.prototype.setWidth = function (x) { | |
this.css.width = x + "px"; | |
}; | |
XWeb_BaseClass.prototype.setHeight = function (y) { | |
this.css.height = y + "px"; | |
}; | |
XWeb_BaseClass.prototype.getTop = function() { | |
return this.el.offsetTop; | |
}; | |
XWeb_BaseClass.prototype.getLeft = function () { | |
return this.el.offsetLeft; | |
}; | |
XWeb_BaseClass.prototype.getRight = function () { | |
return (pg.x - this.getLeft()); | |
}; | |
XWeb_BaseClass.prototype.getWidth = function () { | |
return this.el.offsetWidth; | |
}; | |
XWeb_BaseClass.prototype.getHeight = function () { | |
return this.el. offsetHeight; | |
}; | |
XWeb_BaseClass.prototype.getPosHeight = function () { | |
return this.getTop() + this.getHeight(); | |
}; | |
XWeb_BaseClass.prototype.getPosWidth = function () { | |
return this.getLeft() + this.getWidth(); | |
}; | |
XWeb_BaseClass.prototype.moveTo = function (x,y) { | |
this.setLeft(x); | |
this.setTop(y); | |
}; | |
XWeb_BaseClass.prototype.moveBy = function (x,y) { | |
this.moveTo(this.getLeft()+x,this.getTop()+y); | |
}; | |
XWeb_BaseClass.prototype.resizeTo = function (x,y) { | |
this.css.width = x + "px"; | |
this.css.height = y + "px"; | |
}; | |
XWeb_BaseClass.prototype.docCenter = function (x,y) { | |
var args = this.docCenter.arguments; | |
if (typeof args[0] == "undefined") { | |
x = 0; | |
y = 0; | |
} else { | |
if (typeof args[1] == "undefined") y = 0; | |
} | |
this.moveTo((pg.x2 - (this.getWidth()/2)) + x,(pg.y2 - (this.getHeight()/2)) + y); | |
}; | |
XWeb_BaseClass.prototype.show = function () { | |
this.css.visibility = "visible"; | |
}; | |
XWeb_BaseClass.prototype.hide = function () { | |
this.css.visibility = "hidden"; | |
}; | |
XWeb_BaseClass.prototype.clipTo = function (top,right,bottom,left) { | |
this.css.clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)"; | |
}; | |
XWeb_BaseClass.prototype.getClipVals = function () { | |
var clip = new Array(); | |
if (user.ie) { | |
clip[0] = (this.el.currentStyle.clipTop == "auto")?0:parseInt(this.el.currentStyle.clipTop); | |
clip[1] = (this.el.currentStyle.clipRight == "auto")?parseInt(this.el.currentStyle.width):parseInt(this.el.currentStyle.clipRight); | |
clip[2] = (this.el.currentStyle.clipBottom == "auto")?parseInt(this.el.currentStyle.height):parseInt(this.el.currentStyle.clipBottom); | |
clip[3] = (this.el.currentStyle.clipLeft == "auto")?0:parseInt(this.el.currentStyle.clipLeft); | |
} | |
if (user.ns) { | |
var str = document.defaultView.getComputedStyle(this.el, '').getPropertyValue("clip"); | |
if (str != "auto") { | |
var i; | |
i = str.indexOf("("); | |
clip[0] = parseInt(str.substring(i + 1, str.length), 10); | |
i = str.indexOf(" ", i + 1); | |
clip[1] = parseInt(str.substring(i + 1, str.length), 10); | |
i = str.indexOf(" ", i + 1); | |
clip[2] = parseInt(str.substring(i + 1, str.length), 10); | |
i = str.indexOf(" ", i + 1); | |
clip[3] = parseInt(str.substring(i + 1, str.length), 10); | |
} else { | |
clip[0] = 0; | |
clip[1] = parseInt(document.defaultView.getComputedStyle(this.el, '').getPropertyValue("width")); | |
clip[2] = parseInt(document.defaultView.getComputedStyle(this.el, '').getPropertyValue("height")); | |
clip[3] = 0; | |
} | |
} | |
return clip; | |
}; | |
XWeb_BaseClass.prototype.getStyle = function (cssProp) { | |
if (user.ns) { | |
cssProp = (cssProp == "paddingTop")?"padding-top":cssProp; | |
cssProp = (cssProp == "paddingRight")?"padding-right":cssProp; | |
cssProp = (cssProp == "paddingBottom")?"padding-bottom":cssProp; | |
cssProp = (cssProp == "paddingLeft")?"padding-left":cssProp; | |
} | |
return (user.ie)?this.el.currentStyle[cssProp]:document.defaultView.getComputedStyle(this.el, '').getPropertyValue(cssProp); | |
} | |
//Sets the opacity of the layer | |
XWeb_BaseClass.prototype.setOpacity = function (opac) { | |
if (user.ie) this.css.filter = "Alpha(opacity=" + (opac*100) + ")"; | |
if (user.ns) this.css.MozOpacity = opac; | |
}; | |
//Setting and releasing events (OO) | |
XWeb_BaseClass.prototype.setEvent = function (sEvent,fn) { | |
if (user.ie) { | |
sEvent = "on" + sEvent; | |
this.el.attachEvent(sEvent,fn); | |
} else { | |
if (sEvent == "mouseenter") sEvent = "mouseover"; | |
if (sEvent == "mouseleave") sEvent = "mouseout"; | |
this.el.addEventListener(sEvent,fn,false); | |
} | |
}; | |
XWeb_BaseClass.prototype.releaseEvent = function (sEvent,fn) { | |
if (user.ie) { | |
sEvent = "on" + sEvent; | |
this.el.detachEvent(sEvent,fn); | |
} else { | |
if (sEvent == "mouseenter") sEvent = "mouseover"; | |
if (sEvent == "mouseleave") sEvent = "mouseout"; | |
this.el.addEventListener(sEvent,fn,false); | |
} | |
}; | |
//Setting and releasing events (non-OO) | |
function setEvent(oName,sEvent,fn) { | |
if (user.ie) { | |
sEvent = "on" + sEvent; | |
oName.attachEvent(sEvent,fn); | |
} | |
if (user.ns) { | |
//alert("bleh"); | |
if (sEvent == "mouseenter") sEvent = "mouseover"; | |
if (sEvent == "mouseleave") sEvent = "mouseout"; | |
oName.addEventListener(sEvent,fn,false); | |
} | |
} | |
function releaseEvent(oName,sEvent,fn) { | |
if (user.ie) { | |
var sEvent = "on" + sEvent; | |
oName.detachEvent(sEvent,fn); | |
} | |
if (user.ns) { | |
if (sEvent == "mouseenter") sEvent = "mouseover"; | |
if (sEvent == "mouseleave") sEvent = "mouseout"; | |
oName.removeEventListener(sEvent,fn,false); | |
} | |
} | |
//Extending the capabilities of NS6 | |
if (user.ns) { | |
//Thanks to Erik @ WebFX for the contains method | |
HTMLElement.prototype.contains = function (oElement) { | |
var tmp = oElement; | |
while (tmp != null) { | |
if (tmp == this) return true; | |
tmp = tmp.parentNode; | |
} | |
return false; | |
}; | |
} | |
// Variables for included files | |
var XWebAnimatorClass; | |
//The following three functions were written by Paul Sowden (with a few changes on my part). The original script posted on ALA | |
//did not work for IE6. With a few changes made, it now works in IE6. | |
function setActiveStyleSheet(title) { | |
var i, a; | |
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { | |
if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { | |
a.disabled = true; | |
if (a.getAttribute("title") == title) a.disabled = false; | |
} | |
} | |
} | |
function getActiveStyleSheet() { | |
var i, a; | |
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { | |
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); | |
} | |
return null; | |
} | |
function getDefaultStyleSheet() { | |
var i, a; | |
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { | |
if(a.getAttribute("rel").indexOf("style") != -1 | |
&& a.getAttribute("rel").indexOf("alt") == -1 | |
&& a.getAttribute("title") | |
) return a.getAttribute("title"); | |
} | |
return null; | |
} | |
//The following 2 functions were written by Peter-Paul Koch to read and write cookies. | |
function createCookie(name,value,days) { | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime()+(days*24*60*60*1000)); | |
var expires = "; expires="+date.toGMTString(); | |
} | |
else expires = ""; | |
document.cookie = name+"="+value+expires+"; path=/"; | |
} | |
function readCookie(name) { | |
var nameEQ = name + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0;i < ca.length;i++) { | |
var c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | |
} | |
return null; | |
} | |
onload = function () { pg = new pgObj(); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment