1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
define( [
"jquery",
"./helper",
"ui/dialog"
], function( $, testHelper ) {
module("dialog: events");
test("open", function() {
expect(13);
var element = $("<div></div>");
element.dialog({
open: function(ev, ui) {
ok(element.dialog( "instance" )._isOpen, "interal _isOpen flag is set");
ok(true, "autoOpen: true fires open callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogopen", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
}
});
element.remove();
element = $("<div></div>");
element.dialog({
autoOpen: false,
open: function(ev, ui) {
ok(true, ".dialog('open') fires open callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogopen", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
}
}).bind("dialogopen", function(ev, ui) {
ok(element.dialog( "instance" )._isOpen, "interal _isOpen flag is set");
ok(true, "dialog('open') fires open event");
equal(this, element[0], "context of event");
deepEqual(ui, {}, "ui hash in event");
});
element.dialog("open");
element.remove();
});
test( "focus", function() {
expect( 5 );
var element, other;
element = $("#dialog1").dialog({
autoOpen: false
});
other = $("#dialog2").dialog({
autoOpen: false
});
element.one( "dialogopen", function() {
ok( true, "open, just once" );
});
element.one( "dialogfocus", function() {
ok( true, "focus on open" );
});
other.dialog( "open" );
element.one( "dialogfocus", function() {
ok( true, "when opening and already open and wasn't on top" );
});
other.dialog( "open" );
element.dialog( "open" );
element.one( "dialogfocus", function() {
ok( true, "when calling moveToTop and wasn't on top" );
});
other.dialog( "moveToTop" );
element.dialog( "moveToTop" );
element.bind( "dialogfocus", function() {
ok( true, "when mousedown anywhere on the dialog and it wasn't on top" );
});
other.dialog( "moveToTop" );
element.trigger( "mousedown" );
// triggers just once when already on top
element.dialog( "open" );
element.dialog( "moveToTop" );
element.trigger( "mousedown" );
element.add( other ).remove();
});
test("dragStart", function() {
expect(9);
var handle,
element = $("<div></div>").dialog({
dragStart: function(ev, ui) {
ok(true, "dragging fires dragStart callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogdragstart", "event type in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
}
}).bind("dialogdragstart", function(ev, ui) {
ok(true, "dragging fires dialogdragstart event");
equal(this, element[0], "context of event");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
});
handle = $(".ui-dialog-titlebar", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
test("drag", function() {
expect(9);
var handle,
hasDragged = false,
element = $("<div></div>").dialog({
drag: function(ev, ui) {
if (!hasDragged) {
ok(true, "dragging fires drag callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogdrag", "event type in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
hasDragged = true;
}
}
}).one("dialogdrag", function(ev, ui) {
ok(true, "dragging fires dialogdrag event");
equal(this, element[0], "context of event");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
});
handle = $(".ui-dialog-titlebar", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
test("dragStop", function() {
expect(9);
var handle,
element = $("<div></div>").dialog({
dragStop: function(ev, ui) {
ok(true, "dragging fires dragStop callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogdragstop", "event type in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
}
}).bind("dialogdragstop", function(ev, ui) {
ok(true, "dragging fires dialogdragstop event");
equal(this, element[0], "context of event");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
});
handle = $(".ui-dialog-titlebar", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
test("resizeStart", function() {
expect(13);
var handle,
element = $("<div></div>").dialog({
resizeStart: function(ev, ui) {
ok(true, "resizing fires resizeStart callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogresizestart", "event type in callback");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
}
}).bind("dialogresizestart", function(ev, ui) {
ok(true, "resizing fires dialogresizestart event");
equal(this, element[0], "context of event");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
});
handle = $(".ui-resizable-se", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
test("resize", function() {
expect(13);
var handle,
hasResized = false,
element = $("<div></div>").dialog({
resize: function(ev, ui) {
if (!hasResized) {
ok(true, "resizing fires resize callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogresize", "event type in callback");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
hasResized = true;
}
}
}).one("dialogresize", function(ev, ui) {
ok(true, "resizing fires dialogresize event");
equal(this, element[0], "context of event");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
});
handle = $(".ui-resizable-se", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
test("resizeStop", function() {
expect(13);
var handle,
element = $("<div></div>").dialog({
resizeStop: function(ev, ui) {
ok(true, "resizing fires resizeStop callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogresizestop", "event type in callback");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
}
}).bind("dialogresizestop", function(ev, ui) {
ok(true, "resizing fires dialogresizestop event");
equal(this, element[0], "context of event");
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
});
handle = $(".ui-resizable-se", element.dialog("widget"));
testHelper.drag(element, handle, 50, 50);
element.remove();
});
asyncTest("close", function() {
expect(14);
var element = $("<div></div>").dialog({
close: function(ev, ui) {
ok(true, ".dialog('close') fires close callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogclose", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
}
}).bind("dialogclose", function(ev, ui) {
ok(true, ".dialog('close') fires dialogclose event");
equal(this, element[0], "context of event");
deepEqual(ui, {}, "ui hash in event");
});
element.dialog("close");
element.remove();
// Close event with an effect
element = $("<div></div>").dialog({
hide: 10,
close: function(ev, ui) {
ok(true, ".dialog('close') fires close callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogclose", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
start();
}
}).bind("dialogclose", function(ev, ui) {
ok(true, ".dialog('close') fires dialogclose event");
equal(this, element[0], "context of event");
deepEqual(ui, {}, "ui hash in event");
});
element.dialog("close");
});
test("beforeClose", function() {
expect(14);
var element = $("<div></div>").dialog({
beforeClose: function(ev, ui) {
ok(true, ".dialog('close') fires beforeClose callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogbeforeclose", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
return false;
}
});
element.dialog("close");
ok( element.dialog("widget").is(":visible"), "beforeClose callback should prevent dialog from closing");
element.remove();
element = $("<div></div>").dialog();
element.dialog("option", "beforeClose", function(ev, ui) {
ok(true, ".dialog('close') fires beforeClose callback");
equal(this, element[0], "context of callback");
equal(ev.type, "dialogbeforeclose", "event type in callback");
deepEqual(ui, {}, "ui hash in callback");
return false;
});
element.dialog("close");
ok( element.dialog("widget").is(":visible"), "beforeClose callback should prevent dialog from closing");
element.remove();
element = $("<div></div>").dialog().bind("dialogbeforeclose", function(ev, ui) {
ok(true, ".dialog('close') triggers dialogbeforeclose event");
equal(this, element[0], "context of event");
deepEqual(ui, {}, "ui hash in event");
return false;
});
element.dialog("close");
ok( element.dialog("widget").is(":visible"), "dialogbeforeclose event should prevent dialog from closing");
element.remove();
});
// #8789 and #8838
asyncTest("ensure dialog's container doesn't scroll on resize and focus", function() {
expect(2);
var element = $("#dialog1").dialog(),
initialScroll = $(window).scrollTop();
element.dialog("option", "height", 600);
equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after height change");
setTimeout( function(){
$(".ui-dialog-titlebar-close").simulate("mousedown");
equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog");
element.dialog("destroy");
start();
});
});
test("#5184: isOpen in dialogclose event is true", function() {
expect( 3 );
var element = $( "<div></div>" ).dialog({
close: function() {
ok( !element.dialog("isOpen"), "dialog is not open during close" );
}
});
ok( element.dialog("isOpen"), "dialog is open after init" );
element.dialog( "close" );
ok( !element.dialog("isOpen"), "dialog is not open after close" );
element.remove();
});
test("ensure dialog keeps focus when clicking modal overlay", function() {
expect( 2 );
var element = $( "<div></div>" ).dialog({
modal: true
});
equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" );
$(".ui-widget-overlay").simulate("mousedown");
equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" );
element.remove();
});
} );
|