Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
<!-- // Hide
2
 
3
// *** TIPSTER ***
4
 
5
var isDOM=document.getElementById?1:0;
6
var isIE=document.all?1:0;
7
var isNS4=(navigator.appName=='Netscape'&&!isDOM)?1:0;
8
var isWin=(navigator.platform.indexOf('Win')!=-1)?1:0;
9
var isDyn=(isDOM||isIE||isNS4);
10
 
11
function getRef(id, par)
12
{
13
 par = !par ? document : (par.navigator?par.document:par);
14
 return (isIE ? par.all[id] :
15
  (isDOM ? (par.getElementById?par:par.ownerDocument).getElementById(id) :
16
  par.layers[id]));
17
}
18
 
19
function getSty(id, par)
20
{
21
 return (isNS4 ? getRef(id, par) : getRef(id, par).style)
22
}
23
 
24
if (!window.LayerObj) var LayerObj = new Function('id', 'par',
25
 'this.ref=getRef(id, par); this.sty=getSty(id, par); return this');
26
function getLyr(id, par) { return new LayerObj(id, par) }
27
 
28
function LyrFn(fn, fc)
29
{
30
 LayerObj.prototype[fn] = new Function('var a=arguments,p=a[0]; with (this) { '+fc+' }');
31
}
5114 dpurdie 32
LyrFn('x','if (!isNaN(a[0])) sty.left=p + "px"; else return parseInt(sty.left)');
33
LyrFn('y','if (!isNaN(a[0])) sty.top=p + "px"; else return parseInt(sty.top)');
119 ghuddy 34
LyrFn('vis','sty.visibility=p');
35
LyrFn('write','if (isNS4) with (ref.document) {write(p);close()} else ref.innerHTML=p');
36
LyrFn('alpha','var f=ref.filters; if (f) {' +
37
 'if (sty.filter.indexOf("alpha")==-1) sty.filter+="alpha()"; ' +
38
 'if (f.length&&f.alpha) f.alpha.opacity=p } else if (isDOM) sty.MozOpacity=(p/100)');
39
 
40
 
41
if (!window.page) var page = { win: window, minW: 0, minH: 0, MS: isIE&&!window.opera }
42
 
43
page.winW=function()
44
 { with (this) return Math.max(minW, MS?win.document.body.clientWidth:win.innerWidth) }
45
page.winH=function()
46
 { with (this) return Math.max(minH, MS?win.document.body.clientHeight:win.innerHeight) }
47
 
48
page.scrollX=function()
49
 { with (this) return MS?win.document.body.scrollLeft:win.pageXOffset }
50
page.scrollY=function()
51
 { with (this) return MS?win.document.body.scrollTop:win.pageYOffset }
52
 
53
 
54
// *** TIP FUNCTIONS AND OBJECT ***
55
 
56
function tipTrack(evt) { with (this)
57
{
58
 // Figure out where the mouse is and call the position function.
59
 // Also set sX and sY as the scroll position of the document.
60
 sX = page.scrollX();
61
 sY = page.scrollY();
62
 mX = (isIE ? event.clientX + sX : evt.pageX);
63
 mY = (isIE ? event.clientY + sY : evt.pageY);
64
 
65
 // If we've set tip tracking, call the position function.
66
 if (tipStick == 1) position();
67
}}
68
 
69
function tipPosition() { with (this)
70
{
71
 if (actTip)
72
 {
73
  // Pull the window sizes from the page object.
74
  // In NS4 we size down the window a little as it includes scrollbars.
75
  var wW = page.winW()-(isIE?0:15), wH = page.winH()-(isIE?0:15);
76
 
77
  // Pull the compulsory information out of the tip array.
78
  var t=tips[actTip], tipX=eval(t[0]), tipY=eval(t[1]), tipW=t[2], tipH=t[3], adjY = 1;
79
 
80
  // Add mouse position onto relatively positioned tips.
81
  if (typeof(t[0])=='number') tipX += mX;
82
  if (typeof(t[1])=='number') tipY += mY;
83
 
84
  // Check the tip is not within 5px of the screen boundaries.
85
  if (tipX + tipW + 5 > sX + wW) { tipX = sX + wW - tipW - 5; adjY = 2 }
86
  if (tipY + tipH + 5 > sY + wH) tipY = sY + wH - (adjY*tipH) - 5;
87
  if (tipX < sX+ 5) tipX = sX + 5;
88
  if (tipY < sY + 5) tipY = sY + 5;
89
 
90
 
91
  // If the tip is currently invisible, show at the calculated position.
92
  if (!showTip && (doFades ? !alpha : true))
93
  {
94
   xPos = tipX;
95
   yPos = tipY;
96
  }
97
 
98
  // Move the actual position towards the calculated by the stickiness factor.
99
  // Low stickinesses will result in slower catchup times.
100
  xPos += (tipX - xPos) * tipStick;
101
  yPos += (tipY - yPos) * tipStick;
102
 
103
  div.x(xPos);
104
  div.y(yPos);
105
 }
106
}}
107
 
108
function tipShow(tipN) { with (this)
109
{
110
 if (!isDyn) return;
111
 
112
 // My layer object we use.
113
 if (!div || !div.ref) div = getLyr(myName + 'Layer');
114
 if (!div.ref) return;
115
 
116
 // If we're mousing over a different or new tip...
117
 if (actTip != tipN)
118
 {
119
  // Remember this tip number as active, for the other functions.
120
  actTip = tipN;
121
 
122
  // Set tip's onmouseover and onmouseout handlers.
123
  if (isNS4) div.ref.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
124
  div.ref.onmouseover = new Function(myName + '.show("' + tipN + '")');
125
  div.ref.onmouseout = new Function(myName + '.hide()');
126
 
127
  // Stick it somewhere onscreen.
128
  position();
129
 
130
  // Go through and replace %0% with the array's 0 index, %1% with tips[tipN][1] etc...
131
  var str = template;
132
  for (var i=0; i<tips[tipN].length; i++) str = str.replace('%'+i+'%', tips[tipN][i]);
133
  // Write the proper content... the last <br> strangely helps IE5/Mac...?
134
  div.write(str + ((document.all && !isWin) ? '<small><br></small>' : ''));
135
 }
136
 
137
 // For non-integer stickiness values, we need to use setInterval to animate the tip,
138
 // if it's 0 or 1 we can just use onmousemove to position it.
139
 clearInterval(trackTimer);
140
 if (tipStick != parseInt(tipStick)) trackTimer = setInterval(myName+'.position()', 50);
141
 
142
 // Set the showTip flag, as a signal for the fade/position routines.
143
 showTip = true;
144
 
145
 // Finally either fade in immediately or after a very short delay.
146
 // The delay is for NS4 to allow it to execute a 'hide' event after this, from a
147
 // previous mouseout when two tip triggers overlap, because it's a weird browser.
148
 // So, this show call can cancel a (slightly later) hide. Look, it works, OK? ;).
149
 clearTimeout(fadeTimer);
150
 if (isNS4) setTimeout(myName + '.fade()', 1);
151
 else fade();
152
}}
153
 
154
function tipHide() { with (this)
155
{
156
 if (!isDyn) return;
157
 
158
 // Fade out in 100ms, a larger delay so another mouseover can cancel this fade.
159
 // This allows the user to mouseover a static tip before its hides.
160
 clearTimeout(fadeTimer);
161
 fadeTimer = setTimeout('with (' + myName + ') { showTip=false; fade() }', 200);
162
}}
163
 
164
function tipFade() { with (this)
165
{
166
 // Clear to stop existing fades.
167
 clearTimeout(fadeTimer);
168
 
169
 // Show it and optionally increment alpha from 0 to 100.
170
 if (showTip)
171
 {
172
  div.vis('visible');
173
  if (doFades)
174
  {
175
   alpha += fadeSpeed;
176
   if (alpha > 100) alpha = 100;
177
   div.alpha(alpha);
178
   // Call this function again shortly, fading tip in further.
179
   if (alpha < 100) fadeTimer = setTimeout(myName + '.fade()', 50);
180
   return;
181
  }
182
 }
183
 
184
 else
185
 {
186
  // Similar to before but counting down and hiding at the end.
187
  if (doFades && alpha > 0)
188
  {
189
   alpha -= fadeSpeed;
190
   if (alpha < 0) alpha = 0;
191
   div.alpha(alpha);
192
   fadeTimer = setTimeout(myName + '.fade()', 50);
193
   return;
194
  }
195
  div.vis('hidden');
196
  // Clear the active tip flag so it is repositioned next time.
197
  actTip = '';
198
  // Stop any sticky-tip tracking if it's invisible.
199
  clearInterval(trackTimer);
200
 }
201
}}
202
 
203
function TipObj(myName)
204
{
205
 // Holds the properties the functions above use.
206
 this.myName = myName;
207
 this.tips = new Array();
208
 this.template = '';
209
 this.actTip = '';
210
 this.showTip = false;
211
 this.tipStick = 1;
212
 this.xPos = this.yPos = this.sX = this.sY = this.mX = this.mY = 0;
213
 
214
 this.track = tipTrack;
215
 this.position = tipPosition;
216
 this.show = tipShow;
217
 this.hide = tipHide;
218
 this.fade = tipFade;
219
 
220
 this.div = null;
221
 this.trackTimer = 0;
222
 this.fadeTimer = 0;
223
 this.alpha = 0;
224
 this.doFades = false;
225
 this.fadeSpeed = 20;
4230 dpurdie 226
 this.template = '<table bgcolor="#000000" cellpadding="1" cellspacing="0" width="%2%" border="0">' +
227
                 '<tr><td><table bgcolor="#FFFFCC" cellpadding="2" cellspacing="0" width="100%" border="0">' +
228
                 '<tr><td height="%3%" class="tipClass">%4%</td></tr></table></td></tr></table>';
119 ghuddy 229
}
4230 dpurdie 230
var formTips = new TipObj('formTips');
119 ghuddy 231
 
4230 dpurdie 232
// Functions to assist in creating tips
233
// stdTip: width, Title, Body
234
function stdTip( w,t,b) {
235
    return newTip(10,0,w,10,t,b);
236
}
237
// newTip( x,y,width,height, title, body)
238
function newTip(x,y,w,h,t,b) {
239
    var tip = new Array(x,y,w,h,10);
5114 dpurdie 240
    tip[4] = '<img src="images/i_help.gif" width="12px" height="12px" hspace="2" align="absmiddle">' +
4230 dpurdie 241
    t + '<hr size="1" noshade>' + b;
242
    return tip;
243
} 
119 ghuddy 244
 
245
// Capture the onmousemove event so tips can follow the mouse. Add in all your tip objects here
246
// and also any functions from other scripts that need this event (e.g. my DHTML Scroller) too.
247
if (isNS4) document.captureEvents(Event.MOUSEMOVE);
248
document.onmousemove = function(evt)
249
{
250
 formTips.track(evt);
251
 if (isNS4) return document.routeEvent(evt);
252
}
253
 
254
 
255
// A small function that refreshes NS4 on horizontal resize.
256
var nsWinW = window.innerWidth, nsWinH = window.innerHeight;
257
function ns4BugCheck()
258
{
259
 if (isNS4 && (nsWinW!=innerWidth || nsWinH!=innerHeight)) location.reload()
260
}
261
 
262
window.onresize = function()
263
{
264
 ns4BugCheck();
265
}
266
 
4230 dpurdie 267
// End Hide -->