1 | /*
|
---|
2 | * dialog_events.js
|
---|
3 | */
|
---|
4 | (function($) {
|
---|
5 |
|
---|
6 | module("dialog: events");
|
---|
7 |
|
---|
8 | test("open", function() {
|
---|
9 | expect(11);
|
---|
10 |
|
---|
11 | el = $("<div></div>");
|
---|
12 | el.dialog({
|
---|
13 | open: function(ev, ui) {
|
---|
14 | ok(true, 'autoOpen: true fires open callback');
|
---|
15 | equals(this, el[0], "context of callback");
|
---|
16 | equals(ev.type, 'dialogopen', 'event type in callback');
|
---|
17 | same(ui, {}, 'ui hash in callback');
|
---|
18 | }
|
---|
19 | });
|
---|
20 | el.remove();
|
---|
21 |
|
---|
22 | el = $("<div></div>");
|
---|
23 | el.dialog({
|
---|
24 | autoOpen: false,
|
---|
25 | open: function(ev, ui) {
|
---|
26 | ok(true, '.dialog("open") fires open callback');
|
---|
27 | equals(this, el[0], "context of callback");
|
---|
28 | equals(ev.type, 'dialogopen', 'event type in callback');
|
---|
29 | same(ui, {}, 'ui hash in callback');
|
---|
30 | }
|
---|
31 | }).bind('dialogopen', function(ev, ui) {
|
---|
32 | ok(true, 'dialog("open") fires open event');
|
---|
33 | equals(this, el[0], 'context of event');
|
---|
34 | same(ui, {}, 'ui hash in event');
|
---|
35 | });
|
---|
36 | el.dialog("open");
|
---|
37 | el.remove();
|
---|
38 | });
|
---|
39 |
|
---|
40 | test("dragStart", function() {
|
---|
41 | expect(7);
|
---|
42 |
|
---|
43 | el = $('<div></div>').dialog({
|
---|
44 | dragStart: function(ev, ui) {
|
---|
45 | ok(true, 'dragging fires dragStart callback');
|
---|
46 | equals(this, el[0], "context of callback");
|
---|
47 | equals(ev.type, 'dialogdragstart', 'event type in callback');
|
---|
48 | same(ui, {}, 'ui hash in callback');
|
---|
49 | }
|
---|
50 | }).bind('dialogdragstart', function(ev, ui) {
|
---|
51 | ok(true, 'dragging fires dialogdragstart event');
|
---|
52 | equals(this, el[0], 'context of event');
|
---|
53 | same(ui, {}, 'ui hash in event');
|
---|
54 | });
|
---|
55 | var handle = $(".ui-dialog-titlebar", dlg());
|
---|
56 | drag(handle, 50, 50);
|
---|
57 | el.remove();
|
---|
58 | });
|
---|
59 |
|
---|
60 | test("drag", function() {
|
---|
61 | expect(7);
|
---|
62 | var hasDragged = false;
|
---|
63 |
|
---|
64 | el = $('<div></div>').dialog({
|
---|
65 | drag: function(ev, ui) {
|
---|
66 | if (!hasDragged) {
|
---|
67 | ok(true, 'dragging fires drag callback');
|
---|
68 | equals(this, el[0], "context of callback");
|
---|
69 | equals(ev.type, 'dialogdrag', 'event type in callback');
|
---|
70 | same(ui, {}, 'ui hash in callback');
|
---|
71 |
|
---|
72 | hasDragged = true;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }).one('dialogdrag', function(ev, ui) {
|
---|
76 | ok(true, 'dragging fires dialogdrag event');
|
---|
77 | equals(this, el[0], 'context of event');
|
---|
78 | same(ui, {}, 'ui hash in event');
|
---|
79 | });
|
---|
80 | var handle = $(".ui-dialog-titlebar", dlg());
|
---|
81 | drag(handle, 50, 50);
|
---|
82 | el.remove();
|
---|
83 | });
|
---|
84 |
|
---|
85 | test("dragStop", function() {
|
---|
86 | expect(7);
|
---|
87 |
|
---|
88 | el = $('<div></div>').dialog({
|
---|
89 | dragStop: function(ev, ui) {
|
---|
90 | ok(true, 'dragging fires dragStop callback');
|
---|
91 | equals(this, el[0], "context of callback");
|
---|
92 | equals(ev.type, 'dialogdragstop', 'event type in callback');
|
---|
93 | same(ui, {}, 'ui hash in callback');
|
---|
94 | }
|
---|
95 | }).bind('dialogdragstop', function(ev, ui) {
|
---|
96 | ok(true, 'dragging fires dialogdragstop event');
|
---|
97 | equals(this, el[0], 'context of event');
|
---|
98 | same(ui, {}, 'ui hash in event');
|
---|
99 | });
|
---|
100 | var handle = $(".ui-dialog-titlebar", dlg());
|
---|
101 | drag(handle, 50, 50);
|
---|
102 | el.remove();
|
---|
103 | });
|
---|
104 |
|
---|
105 | test("resizeStart", function() {
|
---|
106 | expect(7);
|
---|
107 |
|
---|
108 | el = $('<div></div>').dialog({
|
---|
109 | resizeStart: function(ev, ui) {
|
---|
110 | ok(true, 'resizing fires resizeStart callback');
|
---|
111 | equals(this, el[0], "context of callback");
|
---|
112 | equals(ev.type, 'dialogresizestart', 'event type in callback');
|
---|
113 | same(ui, {}, 'ui hash in callback');
|
---|
114 | }
|
---|
115 | }).bind('dialogresizestart', function(ev, ui) {
|
---|
116 | ok(true, 'resizing fires dialogresizestart event');
|
---|
117 | equals(this, el[0], 'context of event');
|
---|
118 | same(ui, {}, 'ui hash in event');
|
---|
119 | });
|
---|
120 | var handle = $(".ui-resizable-se", dlg());
|
---|
121 | drag(handle, 50, 50);
|
---|
122 | el.remove();
|
---|
123 | });
|
---|
124 |
|
---|
125 | test("resize", function() {
|
---|
126 | expect(7);
|
---|
127 | var hasResized = false;
|
---|
128 |
|
---|
129 | el = $('<div></div>').dialog({
|
---|
130 | resize: function(ev, ui) {
|
---|
131 | if (!hasResized) {
|
---|
132 | ok(true, 'resizing fires resize callback');
|
---|
133 | equals(this, el[0], "context of callback");
|
---|
134 | equals(ev.type, 'dialogresize', 'event type in callback');
|
---|
135 | same(ui, {}, 'ui hash in callback');
|
---|
136 |
|
---|
137 | hasResized = true;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }).one('dialogresize', function(ev, ui) {
|
---|
141 | ok(true, 'resizing fires dialogresize event');
|
---|
142 | equals(this, el[0], 'context of event');
|
---|
143 | same(ui, {}, 'ui hash in event');
|
---|
144 | });
|
---|
145 | var handle = $(".ui-resizable-se", dlg());
|
---|
146 | drag(handle, 50, 50);
|
---|
147 | el.remove();
|
---|
148 | });
|
---|
149 |
|
---|
150 | test("resizeStop", function() {
|
---|
151 | expect(7);
|
---|
152 |
|
---|
153 | el = $('<div></div>').dialog({
|
---|
154 | resizeStop: function(ev, ui) {
|
---|
155 | ok(true, 'resizing fires resizeStop callback');
|
---|
156 | equals(this, el[0], "context of callback");
|
---|
157 | equals(ev.type, 'dialogresizestop', 'event type in callback');
|
---|
158 | same(ui, {}, 'ui hash in callback');
|
---|
159 | }
|
---|
160 | }).bind('dialogresizestop', function(ev, ui) {
|
---|
161 | ok(true, 'resizing fires dialogresizestop event');
|
---|
162 | equals(this, el[0], 'context of event');
|
---|
163 | same(ui, {}, 'ui hash in event');
|
---|
164 | });
|
---|
165 | var handle = $(".ui-resizable-se", dlg());
|
---|
166 | drag(handle, 50, 50);
|
---|
167 | el.remove();
|
---|
168 | });
|
---|
169 |
|
---|
170 | test("close", function() {
|
---|
171 | expect(7);
|
---|
172 |
|
---|
173 | el = $('<div></div>').dialog({
|
---|
174 | close: function(ev, ui) {
|
---|
175 | ok(true, '.dialog("close") fires close callback');
|
---|
176 | equals(this, el[0], "context of callback");
|
---|
177 | equals(ev.type, 'dialogclose', 'event type in callback');
|
---|
178 | same(ui, {}, 'ui hash in callback');
|
---|
179 | }
|
---|
180 | }).bind('dialogclose', function(ev, ui) {
|
---|
181 | ok(true, '.dialog("close") fires dialogclose event');
|
---|
182 | equals(this, el[0], 'context of event');
|
---|
183 | same(ui, {}, 'ui hash in event');
|
---|
184 | });
|
---|
185 | el.dialog('close');
|
---|
186 | el.remove();
|
---|
187 | });
|
---|
188 |
|
---|
189 | //handling of deprecated beforeclose (vs beforeClose) option
|
---|
190 | //Ticket #4669 http://dev.jqueryui.com/ticket/4669
|
---|
191 | //TODO: remove in 1.9pre
|
---|
192 | test("beforeclose", function() {
|
---|
193 | expect(10);
|
---|
194 |
|
---|
195 | el = $('<div></div>').dialog({
|
---|
196 | beforeclose: function(ev, ui) {
|
---|
197 | ok(true, '.dialog("close") fires beforeClose callback');
|
---|
198 | equals(this, el[0], "context of callback");
|
---|
199 | equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
---|
200 | same(ui, {}, 'ui hash in callback');
|
---|
201 | return false;
|
---|
202 | }
|
---|
203 | });
|
---|
204 | el.dialog('close');
|
---|
205 | isOpen('beforeclose (deprecated) callback should prevent dialog from closing');
|
---|
206 | el.remove();
|
---|
207 |
|
---|
208 | el = $('<div></div>').dialog();
|
---|
209 | el.dialog('option', 'beforeclose', function(ev, ui) {
|
---|
210 | ok(true, '.dialog("close") fires beforeClose callback');
|
---|
211 | equals(this, el[0], "context of callback");
|
---|
212 | equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
---|
213 | same(ui, {}, 'ui hash in callback');
|
---|
214 | return false;
|
---|
215 | });
|
---|
216 | el.dialog('close');
|
---|
217 | isOpen('beforeclose (deprecated) callback should prevent dialog from closing');
|
---|
218 | el.remove();
|
---|
219 | });
|
---|
220 |
|
---|
221 | test("beforeClose", function() {
|
---|
222 | expect(14);
|
---|
223 |
|
---|
224 | el = $('<div></div>').dialog({
|
---|
225 | beforeClose: function(ev, ui) {
|
---|
226 | ok(true, '.dialog("close") fires beforeClose callback');
|
---|
227 | equals(this, el[0], "context of callback");
|
---|
228 | equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
---|
229 | same(ui, {}, 'ui hash in callback');
|
---|
230 | return false;
|
---|
231 | }
|
---|
232 | });
|
---|
233 | el.dialog('close');
|
---|
234 | isOpen('beforeClose callback should prevent dialog from closing');
|
---|
235 | el.remove();
|
---|
236 |
|
---|
237 | el = $('<div></div>').dialog();
|
---|
238 | el.dialog('option', 'beforeClose', function(ev, ui) {
|
---|
239 | ok(true, '.dialog("close") fires beforeClose callback');
|
---|
240 | equals(this, el[0], "context of callback");
|
---|
241 | equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
---|
242 | same(ui, {}, 'ui hash in callback');
|
---|
243 | return false;
|
---|
244 | });
|
---|
245 | el.dialog('close');
|
---|
246 | isOpen('beforeClose callback should prevent dialog from closing');
|
---|
247 | el.remove();
|
---|
248 |
|
---|
249 | el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
|
---|
250 | ok(true, '.dialog("close") triggers dialogbeforeclose event');
|
---|
251 | equals(this, el[0], "context of event");
|
---|
252 | same(ui, {}, 'ui hash in event');
|
---|
253 | return false;
|
---|
254 | });
|
---|
255 | el.dialog('close');
|
---|
256 | isOpen('dialogbeforeclose event should prevent dialog from closing');
|
---|
257 | el.remove();
|
---|
258 | });
|
---|
259 |
|
---|
260 | })(jQuery);
|
---|