home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
developer.apple.com
/
developer.apple.com.tar
/
developer.apple.com
/
main
/
js
/
adc.js
next >
Wrap
Text File
|
2009-11-09
|
2KB
|
86 lines
function detect() {
// simplify things
var agent = navigator.userAgent.toLowerCase();
// detect platform
this.isMac = (agent.indexOf('mac') != -1);
this.isWin = (agent.indexOf('win') != -1);
this.isWin2k = (this.isWin && (
agent.indexOf('nt 5') != -1));
this.isWinSP2 = (this.isWin && (
agent.indexOf('xp') != -1 ||
agent.indexOf('sv1') != -1));
this.isOther = (
agent.indexOf('unix') != -1 ||
agent.indexOf('sunos') != -1 ||
agent.indexOf('bsd') != -1 ||
agent.indexOf('x11') != -1 ||
agent.indexOf('linux') != -1);
// detect browser
this.isSafari = (agent.indexOf('safari') != -1);
this.isSafari2 = (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >= 300));
this.isOpera = (agent.indexOf('opera') != -1);
this.isNN = (agent.indexOf('netscape') != -1);
this.isIE = (agent.indexOf('msie') != -1);
}
function $() {
var aElems = [];
for (var i=0; i<arguments.length; i++) {
var soElem = arguments[i];
if (typeof soElem == 'string') soElem = document.getElementById(soElem);
if (arguments.length == 1) return soElem;
aElems.push(soElem);
}
return aElems;
}
function $t(sTag,oObj) {
oObj = oObj || document;
return oObj.getElementsByTagName(sTag);
}
function $c(sClass,oObj,sTag) {
oObj = oObj || document;
if (!oObj.length) { oObj = [oObj]; }
var aElements = [];
for(var i = 0; i<oObj.length; i++) {
oEl = oObj[i];
if(oEl.getElementsByTagName) {
oObj.children = oEl.getElementsByTagName(sTag || '*');
for (var j = 0; j<oObj.children.length; j++) {
oObj.child = oObj.children[j];
if(oObj.child.className&&(new RegExp('\\b'+sClass+'\\b').test(oObj.child.className))) {
aElements.push(oObj.child);
}
}
}
}
return aElements;
}
function SearchBoxFix(inputId, imageClass) {
var browser = new detect();
var str = "Search ADC";
var input = document.getElementById(inputId);
if (!browser.isSafari2) {
input.value=str;
input.onfocus = function() {
input.value="";
input.style.color="#000";
};
}
if (browser.isSafari2) {
input.style.fontSize = '12px';
input.style.width = input.offsetWidth+28+'px';
}
if (browser.isIE) input.style.margin = '0 0 -1px 0';
var images = $c(imageClass);
for (var i=0; i<images.length; i++) {
if (browser.isSafari2) {
images[i].style.display = 'none';
}
}
}