~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/tests/resizable.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * resizable tests
3
 
 */
4
 
(function($) {
5
 
//
6
 
// Resizable Test Helper Functions
7
 
//
8
 
 
9
 
var drag = function(el, dx, dy, complete) {
10
 
        
11
 
        // speed = sync -> Drag syncrhonously.
12
 
        // speed = fast|slow -> Drag asyncrhonously - animated.
13
 
        
14
 
        //this mouseover is to work around a limitation in resizable
15
 
        //TODO: fix resizable so handle doesn't require mouseover in order to be used
16
 
        $(el).simulate("mouseover");
17
 
 
18
 
        return $(el).simulate("drag", {
19
 
                dx: dx||0, dy: dy||0, speed: 'sync', complete: complete 
20
 
        });
21
 
};
22
 
 
23
 
var defaults = {
24
 
        alsoResize: null,
25
 
        aspectRatio: false,
26
 
        autoHide: false,
27
 
        containment: null,
28
 
        grid: null,
29
 
        handles: 'e,s,se',
30
 
        helper: null,
31
 
        disabled: false,
32
 
        maxHeight: null,
33
 
        maxWidth: null,
34
 
        minHeight: 10,
35
 
        minWidth: 10,
36
 
        proportionallyResize: null
37
 
};
38
 
 
39
 
// Resizable Tests
40
 
module("resizable");
41
 
 
42
 
test("init", function() {
43
 
        expect(6);
44
 
 
45
 
        $("#resizable1").resizable().remove();
46
 
        ok(true, '.resizable() called on element');
47
 
 
48
 
        $([]).resizable().remove();
49
 
        ok(true, '.resizable() called on empty collection');
50
 
 
51
 
        $('<div/>').resizable().remove();
52
 
        ok(true, '.resizable() called on disconnected DOMElement');
53
 
 
54
 
        $('<div/>').resizable().resizable("foo").remove();
55
 
        ok(true, 'arbitrary method called after init');
56
 
 
57
 
        el = $('<div/>').resizable()
58
 
        var foo = el.data("foo.resizable");
59
 
        el.remove();
60
 
        ok(true, 'arbitrary option getter after init');
61
 
 
62
 
        $('<div/>').resizable().data("foo.resizable", "bar").remove();
63
 
        ok(true, 'arbitrary option setter after init');
64
 
});
65
 
 
66
 
test("destroy", function() {
67
 
        expect(6);
68
 
 
69
 
        $("#dialog1").resizable().resizable("destroy").remove();
70
 
        ok(true, '.resizable("destroy") called on element');
71
 
 
72
 
        $([]).resizable().resizable("destroy").remove();
73
 
        ok(true, '.resizable("destroy") called on empty collection');
74
 
 
75
 
        $('<div/>').resizable().resizable("destroy").remove();
76
 
        ok(true, '.resizable("destroy") called on disconnected DOMElement');
77
 
 
78
 
        $('<div/>').resizable().resizable("destroy").resizable("foo").remove();
79
 
        ok(true, 'arbitrary method called after destroy');
80
 
 
81
 
        el = $('<div/>').resizable();
82
 
        var foo = el.resizable("destroy").data("foo.resizable");
83
 
        el.remove();
84
 
        ok(true, 'arbitrary option getter after destroy');
85
 
 
86
 
        $('<div/>').resizable().resizable("destroy").data("foo.resizable", "bar").remove();
87
 
        ok(true, 'arbitrary option setter after destroy');
88
 
});
89
 
 
90
 
test("element types", function() {
91
 
        var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
92
 
                + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
93
 
                + ',acronym,code,samp,kbd,var,img,object,hr'
94
 
                + ',input,button,label,select,iframe').split(',');
95
 
 
96
 
        $.each(typeNames, function(i) {
97
 
                var typeName = typeNames[i];
98
 
                el = $(document.createElement(typeName)).appendTo('body');
99
 
                (typeName == 'table' && el.append("<tr><td>content</td></tr>"));
100
 
                el.resizable();
101
 
                ok(true, '$("&lt;' + typeName + '/&gt").resizable()');
102
 
                el.resizable("destroy");
103
 
                el.remove();
104
 
        });
105
 
});
106
 
 
107
 
test("defaults", function() {
108
 
        el = $('<div/>').resizable();
109
 
        $.each(defaults, function(key, val) {
110
 
                var actual = el.data(key + ".resizable"), expected = val,
111
 
                        method = (expected && expected.constructor == Object) ?
112
 
                                compare2 : equals;
113
 
                method(actual, expected, key);
114
 
        });
115
 
        el.remove();
116
 
});
117
 
 
118
 
test("n", function() {
119
 
        expect(2);
120
 
        
121
 
        var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' });
122
 
 
123
 
        drag(handle, 0, -50);
124
 
        equals( target.height(), 150, "compare height" );
125
 
 
126
 
        drag(handle, 0, 50);
127
 
        equals( target.height(), 100, "compare height" );
128
 
});
129
 
 
130
 
test("s", function() {
131
 
        expect(2);
132
 
        
133
 
        var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' });
134
 
 
135
 
        drag(handle, 0, 50);
136
 
        equals( target.height(), 150, "compare height" );
137
 
 
138
 
        drag(handle, 0, -50);
139
 
        equals( target.height(), 100, "compare height" );
140
 
});
141
 
 
142
 
test("e", function() {
143
 
        expect(2);
144
 
        
145
 
        var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' });
146
 
 
147
 
        drag(handle, 50);
148
 
        equals( target.width(), 150, "compare width");
149
 
 
150
 
        drag(handle, -50);
151
 
        equals( target.width(), 100, "compare width" );
152
 
});
153
 
 
154
 
test("w", function() {
155
 
        expect(2);
156
 
        
157
 
        var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' });
158
 
 
159
 
        drag(handle, -50);
160
 
        equals( target.width(), 150, "compare width" );
161
 
 
162
 
        drag(handle, 50);
163
 
        equals( target.width(), 100, "compare width" );
164
 
});
165
 
 
166
 
test("ne", function() {
167
 
        expect(4);
168
 
        
169
 
        var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' });
170
 
 
171
 
        drag(handle, -50, -50);
172
 
        equals( target.width(), 50, "compare width" );
173
 
        equals( target.height(), 150, "compare height" );
174
 
 
175
 
        drag(handle, 50, 50);
176
 
        equals( target.width(), 100, "compare width" );
177
 
        equals( target.height(), 100, "compare height" );
178
 
});
179
 
 
180
 
test("se", function() {
181
 
        expect(4);
182
 
        
183
 
        var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' });
184
 
 
185
 
        drag(handle, 50, 50);
186
 
        equals( target.width(), 150, "compare width" );
187
 
        equals( target.height(), 150, "compare height" );
188
 
 
189
 
        drag(handle, -50, -50);
190
 
        equals( target.width(), 100, "compare width" );
191
 
        equals( target.height(), 100, "compare height" );
192
 
});
193
 
 
194
 
test("sw", function() {
195
 
        expect(4);
196
 
        
197
 
        var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' });
198
 
 
199
 
        drag(handle, -50, -50);
200
 
        equals( target.width(), 150, "compare width" );
201
 
        equals( target.height(), 50, "compare height" );
202
 
 
203
 
        drag(handle, 50, 50);
204
 
        equals( target.width(), 100, "compare width" );
205
 
        equals( target.height(), 100, "compare height" );
206
 
});
207
 
 
208
 
test("nw", function() {
209
 
        expect(4);
210
 
        
211
 
        var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' });
212
 
 
213
 
        drag(handle, -50, -50);
214
 
        equals( target.width(), 150, "compare width" );
215
 
        equals( target.height(), 150, "compare height" );
216
 
 
217
 
        drag(handle, 50, 50);
218
 
        equals( target.width(), 100, "compare width" );
219
 
        equals( target.height(), 100, "compare height" );
220
 
});
221
 
 
222
 
module("resizable: Options");
223
 
 
224
 
test("aspectRatio: 'preserve' (e)", function() {
225
 
        expect(4);
226
 
        
227
 
        var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
228
 
 
229
 
        drag(handle, 80);
230
 
        equals( target.width(), 130, "compare maxWidth");
231
 
        equals( target.height(), 130, "compare maxHeight");
232
 
 
233
 
        drag(handle, -130);
234
 
        equals( target.width(), 70, "compare minWidth");
235
 
        equals( target.height(), 70, "compare minHeight");
236
 
});
237
 
 
238
 
test("aspectRatio: 'preserve' (w)", function() {
239
 
        expect(4);
240
 
        
241
 
        var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
242
 
 
243
 
        drag(handle, -80);
244
 
        equals( target.width(), 130, "compare maxWidth");
245
 
        equals( target.height(), 130, "compare maxHeight");
246
 
 
247
 
        drag(handle, 130);
248
 
        equals( target.width(), 70, "compare minWidth");
249
 
        equals( target.height(), 70, "compare minHeight");
250
 
});
251
 
 
252
 
test("aspectRatio: 'preserve' (n)", function() {
253
 
        expect(4);
254
 
        
255
 
        var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
256
 
 
257
 
        drag(handle, 0, -80);
258
 
        equals( target.width(), 130, "compare maxWidth");
259
 
        equals( target.height(), 130, "compare maxHeight");
260
 
 
261
 
        drag(handle, 0, 80);
262
 
        equals( target.width(), 70, "compare minWidth");
263
 
        equals( target.height(), 70, "compare minHeight");
264
 
});
265
 
 
266
 
test("aspectRatio: 'preserve' (s)", function() {
267
 
        expect(4);
268
 
        
269
 
        var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
270
 
 
271
 
        drag(handle, 0, 80);
272
 
        equals( target.width(), 130, "compare maxWidth");
273
 
        equals( target.height(), 130, "compare maxHeight");
274
 
 
275
 
        drag(handle, 0, -80);
276
 
        equals( target.width(), 70, "compare minWidth");
277
 
        equals( target.height(), 70, "compare minHeight");
278
 
});
279
 
 
280
 
test("aspectRatio: 'preserve' (se)", function() {
281
 
        expect(4);
282
 
        
283
 
        var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
284
 
 
285
 
        drag(handle, 80, 80);
286
 
        equals( target.width(), 130, "compare maxWidth");
287
 
        equals( target.height(), 130, "compare maxHeight");
288
 
 
289
 
        drag(handle, -80, -80);
290
 
        equals( target.width(), 70, "compare minWidth");
291
 
        equals( target.height(), 70, "compare minHeight");
292
 
});
293
 
 
294
 
test("aspectRatio: 'preserve' (sw)", function() {
295
 
        expect(4);
296
 
        
297
 
        var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
298
 
 
299
 
        drag(handle, -80, 80);
300
 
        equals( target.width(), 130, "compare maxWidth");
301
 
        equals( target.height(), 130, "compare maxHeight");
302
 
 
303
 
        drag(handle, 80, -80);
304
 
        equals( target.width(), 70, "compare minWidth");
305
 
        equals( target.height(), 70, "compare minHeight");
306
 
});
307
 
 
308
 
test("aspectRatio: 'preserve' (ne)", function() {
309
 
        expect(4);
310
 
        
311
 
        var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
312
 
 
313
 
        drag(handle, 80, -80);
314
 
        equals( target.width(), 130, "compare maxWidth");
315
 
        equals( target.height(), 130, "compare maxHeight");
316
 
 
317
 
        drag(handle, -80, 80);
318
 
        equals( target.width(), 70, "compare minWidth");
319
 
        equals( target.height(), 70, "compare minHeight");
320
 
});
321
 
 
322
 
test("grid", function() {
323
 
        expect(4);
324
 
        
325
 
        var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] });
326
 
 
327
 
        drag(handle, 3, 9);
328
 
        equals( target.width(), 103, "compare width");
329
 
        equals( target.height(), 100, "compare height");
330
 
 
331
 
        drag(handle, 15, 11);
332
 
        equals( target.width(), 118, "compare width");
333
 
        equals( target.height(), 120, "compare height");
334
 
});
335
 
 
336
 
test("grid (wrapped)", function() {
337
 
        expect(4);
338
 
        
339
 
        var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] });
340
 
 
341
 
        drag(handle, 3, 9);
342
 
        equals( target.width(), 103, "compare width");
343
 
        equals( target.height(), 100, "compare height");
344
 
        
345
 
        drag(handle, 15, 11);
346
 
        equals( target.width(), 118, "compare width");
347
 
        equals( target.height(), 120, "compare height");
348
 
});
349
 
 
350
 
test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
351
 
        expect(4);
352
 
 
353
 
        var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
354
 
        
355
 
        drag(handle, -50, -50);
356
 
        equals( target.width(), 60, "compare minWidth" );
357
 
        equals( target.height(), 60, "compare minHeight" );
358
 
        
359
 
        drag(handle, 70, 70);
360
 
        equals( target.width(), 100, "compare maxWidth" );
361
 
        equals( target.height(), 100, "compare maxHeight" );
362
 
});
363
 
 
364
 
test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
365
 
        expect(4);
366
 
        
367
 
        var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
368
 
        
369
 
        drag(handle, 50, -50);
370
 
        equals( target.width(), 60, "compare minWidth" );
371
 
        equals( target.height(), 60, "compare minHeight" );
372
 
        
373
 
        drag(handle, -70, 70);
374
 
        equals( target.width(), 100, "compare maxWidth" );
375
 
        equals( target.height(), 100, "compare maxHeight" );
376
 
});
377
 
 
378
 
test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
379
 
        expect(4);
380
 
        
381
 
        var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
382
 
        
383
 
        drag(handle, -50, 50);
384
 
        equals( target.width(), 60, "compare minWidth" );
385
 
        equals( target.height(), 60, "compare minHeight" );
386
 
        
387
 
        drag(handle, 70, -70);
388
 
        equals( target.width(), 100, "compare maxWidth" );
389
 
        equals( target.height(), 100, "compare maxHeight" );
390
 
});
391
 
 
392
 
test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
393
 
        expect(4);
394
 
        
395
 
        var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
396
 
        
397
 
        drag(handle, 70, 70);
398
 
        equals( target.width(), 60, "compare minWidth" );
399
 
        equals( target.height(), 60, "compare minHeight" );
400
 
        
401
 
        drag(handle, -70, -70);
402
 
        equals( target.width(), 100, "compare maxWidth" );
403
 
        equals( target.height(), 100, "compare maxHeight" );
404
 
});
405
 
 
406
 
})(jQuery);