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
|
/*
* draggable_methods.js
*/
(function($) {
function shouldmove(why) {
drag(el, 50, 50);
moved(50, 50, why);
}
function shouldnotmove(why) {
drag(el, 50, 50);
moved(0, 0, why);
}
module("draggable: methods");
test("init", function() {
expect(6);
$("<div></div>").appendTo('body').draggable().remove();
ok(true, '.draggable() called on element');
$([]).draggable();
ok(true, '.draggable() called on empty collection');
$("<div></div>").draggable();
ok(true, '.draggable() called on disconnected DOMElement');
$("<div></div>").draggable().draggable("foo");
ok(true, 'arbitrary method called after init');
$("<div></div>").draggable().data("foo.draggable");
ok(true, 'arbitrary option getter after init');
$("<div></div>").draggable().data("foo.draggable", "bar");
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(7);
$("<div></div>").appendTo('body').draggable().draggable("destroy").remove();
ok(true, '.draggable("destroy") called on element');
$([]).draggable().draggable("destroy");
ok(true, '.draggable("destroy") called on empty collection');
$("<div></div>").draggable().draggable("destroy");
ok(true, '.draggable("destroy") called on disconnected DOMElement');
$("<div></div>").draggable().draggable("destroy").draggable("foo");
ok(true, 'arbitrary method called after destroy');
$("<div></div>").draggable().draggable("destroy").data("foo.draggable");
ok(true, 'arbitrary option getter after destroy');
$("<div></div>").draggable().draggable("destroy").data("foo.draggable", "bar");
ok(true, 'arbitrary option setter after destroy');
var expected = $('<div></div>').draggable(),
actual = expected.draggable('destroy');
equals(actual, expected, 'destroy is chainable');
});
test("enable", function() {
expect(7);
el = $("#draggable2").draggable({ disabled: true });
shouldnotmove('.draggable({ disabled: true })');
el.draggable("enable");
shouldmove('.draggable("enable")');
equals(el.data("disabled.draggable"), false, "disabled.draggable getter");
el.draggable("destroy");
el.draggable({ disabled: true });
shouldnotmove('.draggable({ disabled: true })');
el.data("disabled.draggable", false);
equals(el.data("disabled.draggable"), false, "disabled.draggable setter");
shouldmove('.data("disabled.draggable", false)');
var expected = $('<div></div>').draggable(),
actual = expected.draggable('enable');
equals(actual, expected, 'enable is chainable');
});
test("disable", function() {
expect(7);
el = $("#draggable2").draggable({ disabled: false });
shouldmove('.draggable({ disabled: false })');
el.draggable("disable");
shouldnotmove('.draggable("disable")');
equals(el.data("disabled.draggable"), true, "disabled.draggable getter");
el.draggable("destroy");
el.draggable({ disabled: false });
shouldmove('.draggable({ disabled: false })');
el.data("disabled.draggable", true);
equals(el.data("disabled.draggable"), true, "disabled.draggable setter");
shouldnotmove('.data("disabled.draggable", true)');
var expected = $('<div></div>').draggable(),
actual = expected.draggable('disable');
equals(actual, expected, 'disable is chainable');
});
})(jQuery);
|