4cffea185d0b65d37731a64f73022fc5e41bee65
[myslice.git] / third-party / jquery-ui-1.10.2 / tests / unit / resizable / resizable_core.js
1 /*
2  * resizable_core.js
3  */
4
5 (function($) {
6
7 module("resizable: core");
8
9 /*
10 test("element types", function() {
11         var typeNames = ("p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form"
12                 + ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr"
13                 + ",acronym,code,samp,kbd,var,img,object,hr"
14                 + ",input,button,label,select,iframe").split(",");
15
16         $.each(typeNames, function(i) {
17                 var typeName = typeNames[i];
18                 el = $(document.createElement(typeName)).appendTo("body");
19                 (typeName == "table" && el.append("<tr><td>content</td></tr>"));
20                 el.resizable();
21                 ok(true, "$('&lt;" + typeName + "/&gt').resizable()");
22                 el.resizable("destroy");
23                 el.remove();
24         });
25 });
26 */
27
28 test("n", function() {
29         expect(4);
30
31         var handle = ".ui-resizable-n", target = $("#resizable1").resizable({ handles: "all" });
32
33         TestHelpers.resizable.drag(handle, 0, -50);
34         equal( target.height(), 150, "compare height" );
35
36         TestHelpers.resizable.drag(handle, 0, 50);
37         equal( target.height(), 100, "compare height" );
38
39         equal( target[0].style.left, "", "left should not be modified" );
40         equal( target[0].style.width, "", "width should not be modified" );
41 });
42
43 test("s", function() {
44         expect(5);
45
46         var handle = ".ui-resizable-s", target = $("#resizable1").resizable({ handles: "all" });
47
48         TestHelpers.resizable.drag(handle, 0, 50);
49         equal( target.height(), 150, "compare height" );
50
51         TestHelpers.resizable.drag(handle, 0, -50);
52         equal( target.height(), 100, "compare height" );
53
54         equal( target[0].style.top, "", "top should not be modified" );
55         equal( target[0].style.left, "", "left should not be modified" );
56         equal( target[0].style.width, "", "width should not be modified" );
57 });
58
59 test("e", function() {
60         expect(5);
61
62         var handle = ".ui-resizable-e", target = $("#resizable1").resizable({ handles: "all" });
63
64         TestHelpers.resizable.drag(handle, 50);
65         equal( target.width(), 150, "compare width");
66
67         TestHelpers.resizable.drag(handle, -50);
68         equal( target.width(), 100, "compare width" );
69
70         equal( target[0].style.height, "", "height should not be modified" );
71         equal( target[0].style.top, "", "top should not be modified" );
72         equal( target[0].style.left, "", "left should not be modified" );
73 });
74
75 test("w", function() {
76         expect(4);
77
78         var handle = ".ui-resizable-w", target = $("#resizable1").resizable({ handles: "all" });
79
80         TestHelpers.resizable.drag(handle, -50);
81         equal( target.width(), 150, "compare width" );
82
83         TestHelpers.resizable.drag(handle, 50);
84         equal( target.width(), 100, "compare width" );
85
86         equal( target[0].style.height, "", "height should not be modified" );
87         equal( target[0].style.top, "", "top should not be modified" );
88 });
89
90 test("ne", function() {
91         expect(5);
92
93         var handle = ".ui-resizable-ne", target = $("#resizable1").css({ overflow: "hidden" }).resizable({ handles: "all" });
94
95         TestHelpers.resizable.drag(handle, -50, -50);
96         equal( target.width(), 50, "compare width" );
97         equal( target.height(), 150, "compare height" );
98
99         TestHelpers.resizable.drag(handle, 50, 50);
100         equal( target.width(), 100, "compare width" );
101         equal( target.height(), 100, "compare height" );
102
103         equal( target[0].style.left, "", "left should not be modified" );
104 });
105
106 test("se", function() {
107         expect(6);
108
109         var handle = ".ui-resizable-se", target = $("#resizable1").resizable({ handles: "all" });
110
111         TestHelpers.resizable.drag(handle, 50, 50);
112         equal( target.width(), 150, "compare width" );
113         equal( target.height(), 150, "compare height" );
114
115         TestHelpers.resizable.drag(handle, -50, -50);
116         equal( target.width(), 100, "compare width" );
117         equal( target.height(), 100, "compare height" );
118
119         equal( target[0].style.top, "", "top should not be modified" );
120         equal( target[0].style.left, "", "left should not be modified" );
121 });
122
123 test("sw", function() {
124         expect(5);
125
126         var handle = ".ui-resizable-sw", target = $("#resizable1").resizable({ handles: "all" });
127
128         TestHelpers.resizable.drag(handle, -50, -50);
129         equal( target.width(), 150, "compare width" );
130         equal( target.height(), 50, "compare height" );
131
132         TestHelpers.resizable.drag(handle, 50, 50);
133         equal( target.width(), 100, "compare width" );
134         equal( target.height(), 100, "compare height" );
135
136         equal( target[0].style.top, "", "top should not be modified" );
137 });
138
139 test("nw", function() {
140         expect(4);
141
142         var handle = ".ui-resizable-nw", target = $("#resizable1").resizable({ handles: "all" });
143
144         TestHelpers.resizable.drag(handle, -50, -50);
145         equal( target.width(), 150, "compare width" );
146         equal( target.height(), 150, "compare height" );
147
148         TestHelpers.resizable.drag(handle, 50, 50);
149         equal( target.width(), 100, "compare width" );
150         equal( target.height(), 100, "compare height" );
151 });
152
153 test("handle with complex markup (#8756)", function() {
154         expect(2);
155
156         $("#resizable1")
157                 .append(
158                         $("<div>")
159                                 .addClass("ui-resizable-handle")
160                                 .addClass("ui-resizable-w")
161                                 .append($("<div>"))
162                 );
163
164         var handle = ".ui-resizable-w div", target = $("#resizable1").resizable({ handles: "all" });
165
166         TestHelpers.resizable.drag(handle, -50);
167         equal( target.width(), 150, "compare width" );
168
169         TestHelpers.resizable.drag(handle, 50);
170         equal( target.width(), 100, "compare width" );
171 });
172
173 test("resizable accounts for scroll position correctly (#3815)", function() {
174         expect( 3 );
175
176         var position, top, left,
177                 container = $("<div style='overflow:scroll;height:300px;width:300px;position:relative;'></div>").appendTo("#qunit-fixture"),
178                 overflowed = $("<div style='width: 1000px; height: 1000px;'></div>").appendTo( container ),
179                 el = $("<div style='height:100px;width:100px;position:absolute;top:10px;left:10px;'></div>").appendTo( overflowed ).resizable({ handles: "all" }),
180                 handle = ".ui-resizable-e";
181
182         container.scrollLeft( 100 ).scrollTop( 100 );
183
184         position = el.position();
185         left = el.css("left");
186         top = el.css("top");
187
188         TestHelpers.resizable.drag(handle, 50, 50);
189         deepEqual( el.position(), position, "position stays the same when resized" );
190         equal( el.css("left"), left, "css('left') stays the same when resized" );
191         equal( el.css("top"), top, "css('top') stays the same when resized" );
192 });
193
194 })(jQuery);