Subversion Repositories DevTools

Rev

Rev 5751 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<!-- // Hide

// *** TIPSTER ***

var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=(navigator.appName=='Netscape'&&!isDOM)?1:0;
var isWin=(navigator.platform.indexOf('Win')!=-1)?1:0;
var isDyn=(isDOM||isIE||isNS4);

function getRef(id, par)
{
 par = !par ? document : (par.navigator?par.document:par);
 return (isIE ? par.all[id] :
  (isDOM ? (par.getElementById?par:par.ownerDocument).getElementById(id) :
  par.layers[id]));
}

function getSty(id, par)
{
 return (isNS4 ? getRef(id, par) : getRef(id, par).style)
}

if (!window.LayerObj) var LayerObj = new Function('id', 'par',
 'this.ref=getRef(id, par); this.sty=getSty(id, par); return this');
function getLyr(id, par) { return new LayerObj(id, par) }

function LyrFn(fn, fc)
{
 LayerObj.prototype[fn] = new Function('var a=arguments,p=a[0]; with (this) { '+fc+' }');
}
LyrFn('x','if (!isNaN(a[0])) sty.left=p + "px"; else return parseInt(sty.left)');
LyrFn('y','if (!isNaN(a[0])) sty.top=p + "px"; else return parseInt(sty.top)');
LyrFn('vis','sty.visibility=p');
LyrFn('write','if (isNS4) with (ref.document) {write(p);close()} else ref.innerHTML=p');
LyrFn('alpha','var f=ref.filters; if (f) {' +
 'if (sty.filter.indexOf("alpha")==-1) sty.filter+="alpha()"; ' +
 'if (f.length&&f.alpha) f.alpha.opacity=p } else if (isDOM) sty.MozOpacity=(p/100)');


if (!window.page) var page = { win: window, minW: 0, minH: 0, MS: isIE&&!window.opera }

page.winW=function()
 { with (this) return Math.max(minW, MS?win.document.body.clientWidth:win.innerWidth) }
page.winH=function()
 { with (this) return Math.max(minH, MS?win.document.body.clientHeight:win.innerHeight) }

page.scrollX=function()
 { with (this) return MS?win.document.body.scrollLeft:win.pageXOffset }
page.scrollY=function()
 { with (this) return MS?win.document.body.scrollTop:win.pageYOffset }


// *** TIP FUNCTIONS AND OBJECT ***

function tipTrack(evt) { with (this)
{
 // If we've set tip tracking, call the position function.
 if (actTip && tipStick == 1) {
     // Figure out where the mouse is and call the position function.
     // Also set sX and sY as the scroll position of the document.
     sX = page.scrollX();
     sY = page.scrollY();
     mX = (isIE ? event.clientX + sX : evt.pageX);
     mY = (isIE ? event.clientY + sY : evt.pageY);

     position();
 }
}}

function tipPosition() { with (this)
{
 if (actTip)
 {
  // Pull the window sizes from the page object.
  // In NS4 we size down the window a little as it includes scrollbars.
  var wW = page.winW()-(isIE?0:15), wH = page.winH()-(isIE?0:15);

  // Pull the compulsory information out of the tip array.
  var t=tips[actTip], tipX=eval(t[0]), tipY=eval(t[1]), tipW=t[2], tipH=t[3], adjY = 1;

  // Add mouse position onto relatively positioned tips.
  if (typeof(t[0])=='number') tipX += mX;
  if (typeof(t[1])=='number') tipY += mY;

  // Check the tip is not within 5px of the screen boundaries.
  if (tipX + tipW + 5 > sX + wW) { tipX = sX + wW - tipW - 5; adjY = 2 }
  if (tipY + tipH + 5 > sY + wH) tipY = sY + wH - (adjY*tipH) - 5;
  if (tipX < sX+ 5) tipX = sX + 5;
  if (tipY < sY + 5) tipY = sY + 5;


  // If the tip is currently invisible, show at the calculated position.
  if (!showTip && (doFades ? !alpha : true))
  {
   xPos = tipX;
   yPos = tipY;
  }

  // Move the actual position towards the calculated by the stickiness factor.
  // Low stickinesses will result in slower catchup times.
  xPos += (tipX - xPos) * tipStick;
  yPos += (tipY - yPos) * tipStick;

  div.x(xPos);
  div.y(yPos);
 }
}}

function tipShow(tipN) { with (this)
{
 if (!isDyn) return;

 // Create tip div on the fly
 // No need for HTML to define the tip layer. Use it if its present
 if (!div){
         newdiv = document.getElementById(myName + 'Layer');
         if (!newdiv)
         {
                 newdiv = document.createElement('div');
                 newdiv.style.cssText = 'position: absolute; z-index: 1000; visibility: hidden; left:0; top: 0; width: 10';
                 newdiv.id = myName + 'Layer';
                 document.body.appendChild(newdiv);
         }

         div = getLyr(myName + 'Layer');
 }

 // My layer object we use.
 //if (!div || !div.ref) div = getLyr(myName + 'Layer');
 if (!div.ref) return;

 // If we're mousing over a different or new tip...
 if (actTip != tipN)
 {
  // Remember this tip number as active, for the other functions.
  actTip = tipN;

  // Set tip's onmouseover and onmouseout handlers.
  if (isNS4) div.ref.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
  div.ref.onmouseover = new Function(myName + '.show("' + tipN + '")');
  div.ref.onmouseout = new Function(myName + '.hide()');

  // Stick it somewhere onscreen.
  position();

  // Go through and replace %0% with the array's 0 index, %1% with tips[tipN][1] etc...
  var str = template;
  for (var i=0; i<tips[tipN].length; i++) str = str.replace('%'+i+'%', tips[tipN][i]);
  // Write the proper content... the last <br> strangely helps IE5/Mac...?
  div.write(str + ((document.all && !isWin) ? '<small><br></small>' : ''));
 }

 // For non-integer stickiness values, we need to use setInterval to animate the tip,
 // if it's 0 or 1 we can just use onmousemove to position it.
 clearInterval(trackTimer);
 if (tipStick != parseInt(tipStick)) trackTimer = setInterval(myName+'.position()', 50);

 // Set the showTip flag, as a signal for the fade/position routines.
 showTip = true;

 // Finally either fade in immediately or after a very short delay.
 // The delay is for NS4 to allow it to execute a 'hide' event after this, from a
 // previous mouseout when two tip triggers overlap, because it's a weird browser.
 // So, this show call can cancel a (slightly later) hide. Look, it works, OK? ;).
 clearTimeout(fadeTimer);
 if (isNS4) setTimeout(myName + '.fade()', 1);
 else fade();
}}

function tipHide() { with (this)
{
 if (!isDyn) return;

 // Fade out in 100ms, a larger delay so another mouseover can cancel this fade.
 // This allows the user to mouseover a static tip before its hides.
 clearTimeout(fadeTimer);
 fadeTimer = setTimeout('with (' + myName + ') { showTip=false; fade() }', 200);
}}

function tipFade() { with (this)
{
 // Clear to stop existing fades.
 clearTimeout(fadeTimer);

 // Show it and optionally increment alpha from 0 to 100.
 if (showTip)
 {
  div.vis('visible');
  if (doFades)
  {
   alpha += fadeSpeed;
   if (alpha > 100) alpha = 100;
   div.alpha(alpha);
   // Call this function again shortly, fading tip in further.
   if (alpha < 100) fadeTimer = setTimeout(myName + '.fade()', 50);
   return;
  }
 }

 else
 {
  // Similar to before but counting down and hiding at the end.
  if (doFades && alpha > 0)
  {
   alpha -= fadeSpeed;
   if (alpha < 0) alpha = 0;
   div.alpha(alpha);
   fadeTimer = setTimeout(myName + '.fade()', 50);
   return;
  }
  div.vis('hidden');
  // Clear the active tip flag so it is repositioned next time.
  actTip = '';
  // Stop any sticky-tip tracking if it's invisible.
  clearInterval(trackTimer);
 }
}}

function TipObj(myName)
{
 // Holds the properties the functions above use.
 this.myName = myName;
 this.tips = new Array();
 this.template = '';
 this.actTip = '';
 this.showTip = false;
 this.tipStick = 1;
 this.xPos = this.yPos = this.sX = this.sY = this.mX = this.mY = 0;

 this.track = tipTrack;
 this.position = tipPosition;
 this.show = tipShow;
 this.hide = tipHide;
 this.fade = tipFade;
 
 this.div = null;
 this.trackTimer = 0;
 this.fadeTimer = 0;
 this.alpha = 0;
 this.doFades = false;
 this.fadeSpeed = 20;
 this.template = '<table bgcolor="#000000" cellpadding="1" cellspacing="0" width="%2%" border="0">' +
                 '<tr><td><table bgcolor="#FFFFCC" cellpadding="2" cellspacing="0" width="100%" border="0">' +
                 '<tr><td height="%3%" class="tipClass">%4%</td></tr></table></td></tr></table>';
}
var formTips = new TipObj('formTips');

// Functions to assist in creating tips
// stdTip: width, Title, Body
function stdTip( w,t,b) {
    return newTip(10,0,w,10,t,b);
}
// newTip( x,y,width,height, title, body)
function newTip(x,y,w,h,t,b) {
    var tip = new Array(x,y,w,h,10);
    tip[4] = '<img src="images/i_help.gif" width="12px" height="12px" hspace="2" align="absmiddle">' +
    t + '<hr size="1" noshade>' + b;
    return tip;
} 

// Capture the onmousemove event so tips can follow the mouse. Add in all your tip objects here
// and also any functions from other scripts that need this event (e.g. my DHTML Scroller) too.
if (isNS4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function(evt)
{
 formTips.track(evt);
 if (isNS4) return document.routeEvent(evt);
}


// A small function that refreshes NS4 on horizontal resize.
var nsWinW = window.innerWidth, nsWinH = window.innerHeight;
function ns4BugCheck()
{
 if (isNS4 && (nsWinW!=innerWidth || nsWinH!=innerHeight)) location.reload()
}

window.onresize = function()
{
 ns4BugCheck();
}

// End Hide -->