1 | /*********************************************** |
||
2 | * Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) |
||
3 | * This notice MUST stay intact for legal use |
||
4 | * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code |
||
5 | ***********************************************/ |
||
6 | |||
7 | var offsetxpoint=-25 //Customize x offset of tooltip |
||
8 | var offsetypoint=-45 //Customize y offset of tooltip |
||
9 | var ie=document.all |
||
10 | var ns6=document.getElementById && !document.all |
||
11 | var enabletip=false |
||
12 | if (ie||ns6) |
||
13 | var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | function ietruebody(){ |
||
16 | return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body |
||
17 | } |
||
18 | |||
19 | function ddrivetip(thetext, thecolor, thewidth){ |
||
20 | if (ns6||ie){ |
||
0 ignored issues
–
show
There is no return statement if
ns6 || ie is false . Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
![]() |
|||
21 | if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
22 | if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
23 | tipobj.innerHTML=thetext |
||
24 | enabletip=true |
||
25 | return false |
||
26 | } |
||
27 | } |
||
28 | |||
29 | function positiontip(e){ |
||
30 | if (enabletip){ |
||
31 | var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft; |
||
32 | var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop; |
||
33 | //Find out how close the mouse is to the corner of the window |
||
34 | var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20 |
||
35 | var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20 |
||
36 | |||
37 | var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000 |
||
38 | |||
39 | //if the horizontal distance isn't enough to accomodate the width of the context menu |
||
40 | if (rightedge<tipobj.offsetWidth) |
||
0 ignored issues
–
show
|
|||
41 | //move the horizontal position of the menu to the left by it's width |
||
42 | tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px" |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
43 | else if (curX<leftedge) |
||
44 | tipobj.style.left="5px" |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
45 | else |
||
46 | //position the horizontal position of the menu where the mouse is positioned |
||
47 | tipobj.style.left=curX+offsetxpoint+"px" |
||
48 | |||
49 | //same concept with the vertical position |
||
50 | if (bottomedge<tipobj.offsetHeight) |
||
51 | tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px" |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
52 | else |
||
53 | tipobj.style.top=curY+offsetypoint+"px" |
||
54 | tipobj.style.visibility="visible" |
||
55 | } |
||
56 | } |
||
57 | |||
58 | function hideddrivetip(){ |
||
59 | if (ns6||ie){ |
||
60 | enabletip=false |
||
61 | tipobj.style.visibility="hidden" |
||
0 ignored issues
–
show
|
|||
62 | tipobj.style.left="-1000px" |
||
63 | tipobj.style.backgroundColor='' |
||
64 | tipobj.style.width='' |
||
65 | } |
||
66 | } |
||
67 | document.onmousemove=positiontip |
||
68 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.