1 | /* |
---|
2 | Sweet Titles (c) Creative Commons 2005 |
---|
3 | http://creativecommons.org/licenses/by-sa/2.5/ |
---|
4 | Author: Dustin Diaz | http://www.dustindiaz.com |
---|
5 | Revision:ex-ftb 2006*/ |
---|
6 | var sweetTitles = { |
---|
7 | xCord : 0, |
---|
8 | yCord : 0, |
---|
9 | tipElements : ['a','img','span','area'], |
---|
10 | obj : Object, |
---|
11 | x : Object, |
---|
12 | init : function() { |
---|
13 | if ( !document.getElementById || |
---|
14 | !document.createElement || |
---|
15 | !document.getElementsByTagName ) {return; } |
---|
16 | var i,j,Over; |
---|
17 | this.x = document.createElement('div'); |
---|
18 | this.x.id = 'toolTip'; |
---|
19 | document.getElementsByTagName('body')[0].appendChild(this.x); |
---|
20 | this.x.style.top = '0'; |
---|
21 | this.x.style.visibility = 'hidden'; |
---|
22 | var tipLen = this.tipElements.length; |
---|
23 | for ( i=0; i<tipLen; i++ ) { |
---|
24 | var Elms = document.getElementsByTagName(this.tipElements[i]); |
---|
25 | var curLen = Elms.length; |
---|
26 | for ( j=0; j<curLen; j++ ) { |
---|
27 | var el= Elms[j]; |
---|
28 | var tv = el.getAttribute('title') |
---|
29 | if ( tv != null && tv != "null" && tv !="") //chrome |
---|
30 | {addEvent(el,'mouseover',this.tipOver); |
---|
31 | addEvent(el,'mousemove',this.tipMouseMove); |
---|
32 | addEvent(el,'mouseout',this.tipOut); |
---|
33 | var sv = el.getAttribute('swttips'); |
---|
34 | el.setAttribute('tiptitle', tv); |
---|
35 | el.setAttribute('tipswt', sv ); |
---|
36 | el.removeAttribute('title'); |
---|
37 | el.removeAttribute('swttips');} |
---|
38 | el.removeAttribute('alt');} |
---|
39 | } |
---|
40 | }, |
---|
41 | |
---|
42 | updateXY : function(e) { |
---|
43 | if ( document.captureEvents ) { |
---|
44 | sweetTitles.xCord = e.pageX; |
---|
45 | sweetTitles.yCord = e.pageY; |
---|
46 | } else if ( window.event.clientX ) { |
---|
47 | sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft; |
---|
48 | sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;} |
---|
49 | }, |
---|
50 | tipOut: function() { |
---|
51 | if ( window.tID ) { |
---|
52 | clearTimeout(tID); } |
---|
53 | if ( window.opacityID ) { |
---|
54 | clearTimeout(opacityID);} |
---|
55 | sweetTitles.x.style.visibility = 'hidden';}, |
---|
56 | checkNode : function() { |
---|
57 | var trueObj = this.obj; |
---|
58 | if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) { |
---|
59 | return trueObj; |
---|
60 | } else {return trueObj.parentNode;} |
---|
61 | }, |
---|
62 | tipOver : function(e) {sweetTitles.obj = this; |
---|
63 | tID = window.setTimeout("sweetTitles.tipShow()",100); |
---|
64 | sweetTitles.updateXY(e);}, |
---|
65 | |
---|
66 | tipMouseMove : function(e) {sweetTitles.updateXY(e); sweetTitles.tipMove();}, |
---|
67 | |
---|
68 | tipShow : function() { |
---|
69 | var anch = this.checkNode(); |
---|
70 | this.x.innerHTML =""; |
---|
71 | this.x.innerHTML = "<p class='title'> <span> "+anch.getAttribute('tiptitle')+"</span></p>"; |
---|
72 | sv = anch.getAttribute('tipswt'); |
---|
73 | if (( sv != "null" )&& (sv !="")) // for chrome |
---|
74 | {this.x.innerHTML= this.x.innerHTML + "<p>" + anch.getAttribute('tipswt') + "</p>"; } |
---|
75 | sweetTitles.Move; |
---|
76 | var T = this.x.style; |
---|
77 | T.visibility = 'visible'; |
---|
78 | T.opacity = '.1'; |
---|
79 | this.tipFade(10); }, |
---|
80 | |
---|
81 | tipMove: function() |
---|
82 | { var scrX = Number(this.xCord); |
---|
83 | var scrY = Number(this.yCord); |
---|
84 | var tp = parseInt(scrY+8); |
---|
85 | var lt = parseInt(scrX+8); |
---|
86 | var D = document.documentElement; |
---|
87 | var T = this.x.style; |
---|
88 | if ( parseInt(D.clientWidth+D.scrollLeft) < parseInt(this.x.offsetWidth+lt) ) { |
---|
89 | T.left = parseInt(lt-(this.x.offsetWidth+3))+'px'; |
---|
90 | } else { |
---|
91 | T.left = lt+'px'; } |
---|
92 | if ( parseInt(D.clientHeight+D.scrollTop) < parseInt(this.x.offsetHeight+tp) ) { |
---|
93 | T.top = parseInt(tp-(this.x.offsetHeight+3))+'px'; |
---|
94 | } else {T.top = tp+'px'; } |
---|
95 | }, |
---|
96 | tipFade: function(opac) { |
---|
97 | var passed = parseInt(opac); |
---|
98 | var newOpac = parseInt(passed+10); |
---|
99 | T = this.x.style; |
---|
100 | if ( newOpac < 92 ) { |
---|
101 | T.opacity = '.'+newOpac; |
---|
102 | T.filter = "alpha(opacity:"+newOpac+")"; |
---|
103 | opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);} |
---|
104 | else { T.opacity = '.92'; |
---|
105 | T.filter = "alpha(opacity:92)"; } |
---|
106 | } |
---|
107 | }; |
---|
108 | function pageLoader() { sweetTitles.init();} |
---|
109 | addEvent2(window,'load',pageLoader); |
---|