1 |
(function( $ ) { |
2 |
|
3 |
module( "tooltip: options" ); |
4 |
|
5 |
test( "disabled: true", function() { |
6 |
expect( 1 ); |
7 |
$( "#tooltipped1" ).tooltip({ |
8 |
disabled: true |
9 |
}).tooltip( "open" ); |
10 |
equal( $( ".ui-tooltip" ).length, 0 ); |
11 |
}); |
12 |
|
13 |
test( "content: default", function() { |
14 |
expect( 1 ); |
15 |
var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); |
16 |
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); |
17 |
}); |
18 |
|
19 |
test( "content: default; HTML escaping", function() { |
20 |
expect( 2 ); |
21 |
var scriptText = "<script>$.ui.tooltip.hacked = true;</script>", |
22 |
element = $( "#tooltipped1" ); |
23 |
|
24 |
$.ui.tooltip.hacked = false; |
25 |
element.attr( "title", scriptText ) |
26 |
.tooltip() |
27 |
.tooltip( "open" ); |
28 |
equal( $.ui.tooltip.hacked, false, "script did not execute" ); |
29 |
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, |
30 |
"correct tooltip text" ); |
31 |
}); |
32 |
|
33 |
test( "content: return string", function() { |
34 |
expect( 1 ); |
35 |
var element = $( "#tooltipped1" ).tooltip({ |
36 |
content: function() { |
37 |
return "customstring"; |
38 |
} |
39 |
}).tooltip( "open" ); |
40 |
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); |
41 |
}); |
42 |
|
43 |
test( "content: return jQuery", function() { |
44 |
expect( 1 ); |
45 |
var element = $( "#tooltipped1" ).tooltip({ |
46 |
content: function() { |
47 |
return $( "<div>" ).html( "cu<b>s</b>tomstring" ); |
48 |
} |
49 |
}).tooltip( "open" ); |
50 |
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); |
51 |
}); |
52 |
|
53 |
asyncTest( "content: sync + async callback", function() { |
54 |
expect( 2 ); |
55 |
var element = $( "#tooltipped1" ).tooltip({ |
56 |
content: function( response ) { |
57 |
setTimeout(function() { |
58 |
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "loading..." ); |
59 |
|
60 |
response( "customstring2" ); |
61 |
setTimeout(function() { |
62 |
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "customstring2" ); |
63 |
start(); |
64 |
}, 13 ); |
65 |
}, 13 ); |
66 |
return "loading..."; |
67 |
} |
68 |
}).tooltip( "open" ); |
69 |
}); |
70 |
|
71 |
test( "content: change while open", function() { |
72 |
expect( 2 ) ; |
73 |
var element = $( "#tooltipped1" ).tooltip({ |
74 |
content: function() { |
75 |
return "old"; |
76 |
} |
77 |
}); |
78 |
|
79 |
element.one( "tooltipopen", function( event, ui ) { |
80 |
equal( ui.tooltip.text(), "old", "original content" ); |
81 |
element.tooltip( "option", "content", function() { |
82 |
return "new"; |
83 |
}); |
84 |
equal( ui.tooltip.text(), "new", "updated content" ); |
85 |
}); |
86 |
|
87 |
element.tooltip( "open" ); |
88 |
}); |
89 |
|
90 |
test( "content: string", function() { |
91 |
expect( 1 ); |
92 |
$( "#tooltipped1" ).tooltip({ |
93 |
content: "just a string", |
94 |
open: function( event, ui ) { |
95 |
equal( ui.tooltip.text(), "just a string" ); |
96 |
} |
97 |
}).tooltip( "open" ); |
98 |
}); |
99 |
|
100 |
test( "items", function() { |
101 |
expect( 2 ); |
102 |
var event, |
103 |
element = $( "#qunit-fixture" ).tooltip({ |
104 |
items: "#fixture-span" |
105 |
}); |
106 |
|
107 |
event = $.Event( "mouseenter" ); |
108 |
event.target = $( "#fixture-span" )[ 0 ]; |
109 |
element.tooltip( "open", event ); |
110 |
deepEqual( $( "#" + $( "#fixture-span" ).data( "ui-tooltip-id" ) ).text(), "title-text" ); |
111 |
|
112 |
// make sure default [title] doesn't get used |
113 |
event.target = $( "#tooltipped1" )[ 0 ]; |
114 |
element.tooltip( "open", event ); |
115 |
deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined ); |
116 |
|
117 |
element.tooltip( "destroy" ); |
118 |
}); |
119 |
|
120 |
test( "tooltipClass", function() { |
121 |
expect( 1 ); |
122 |
var element = $( "#tooltipped1" ).tooltip({ |
123 |
tooltipClass: "custom" |
124 |
}).tooltip( "open" ); |
125 |
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) ); |
126 |
}); |
127 |
|
128 |
test( "track + show delay", function() { |
129 |
expect( 2 ); |
130 |
var event, |
131 |
leftVal = 314, |
132 |
topVal = 159, |
133 |
offsetVal = 26, |
134 |
element = $( "#tooltipped1" ).tooltip({ |
135 |
track: true, |
136 |
show: { |
137 |
delay: 1 |
138 |
}, |
139 |
position: { |
140 |
my: "left+" + offsetVal + " top+" + offsetVal, |
141 |
at: "right bottom" |
142 |
} |
143 |
}); |
144 |
|
145 |
event = $.Event( "mouseover" ); |
146 |
event.target = $( "#tooltipped1" )[ 0 ]; |
147 |
event.originalEvent = { type: "mouseover" }; |
148 |
event.pageX = leftVal; |
149 |
event.pageY = topVal; |
150 |
element.trigger( event ); |
151 |
|
152 |
event = $.Event( "mousemove" ); |
153 |
event.target = $( "#tooltipped1" )[ 0 ]; |
154 |
event.originalEvent = { type: "mousemove" }; |
155 |
event.pageX = leftVal; |
156 |
event.pageY = topVal; |
157 |
element.trigger( event ); |
158 |
|
159 |
equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" ); |
160 |
equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" ); |
161 |
}); |
162 |
|
163 |
test( "track and programmatic focus", function() { |
164 |
expect( 1 ); |
165 |
$( "#qunit-fixture div input" ).tooltip({ |
166 |
track: true |
167 |
}).focus(); |
168 |
equal( "inputtitle", $( ".ui-tooltip" ).text() ); |
169 |
}); |
170 |
|
171 |
}( jQuery ) ); |