| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"./helper", |
| 6 |
"ui/widgets/resizable" |
| 7 |
], function( QUnit, $, helper, testHelper ) { |
| 8 |
"use strict"; |
| 9 |
|
| 10 |
QUnit.module( "resizable: options", { afterEach: helper.moduleAfterEach } ); |
| 11 |
|
| 12 |
QUnit.test( "alsoResize", function( assert ) { |
| 13 |
assert.expect( 2 ); |
| 14 |
|
| 15 |
var other = $( "<div>" ) |
| 16 |
.css( { |
| 17 |
width: 50, |
| 18 |
height: 50 |
| 19 |
} ) |
| 20 |
.appendTo( "body" ), |
| 21 |
element = $( "#resizable1" ).resizable( { |
| 22 |
alsoResize: other |
| 23 |
} ), |
| 24 |
handle = ".ui-resizable-e"; |
| 25 |
|
| 26 |
testHelper.drag( handle, 80 ); |
| 27 |
assert.equal( element.width(), 180, "resizable width" ); |
| 28 |
assert.equal( other.width(), 130, "alsoResize width" ); |
| 29 |
} ); |
| 30 |
|
| 31 |
QUnit.test( "aspectRatio: 'preserve' (e)", function( assert ) { |
| 32 |
assert.expect( 4 ); |
| 33 |
|
| 34 |
var handle = ".ui-resizable-e", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 35 |
|
| 36 |
testHelper.drag( handle, 80 ); |
| 37 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 38 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 39 |
|
| 40 |
testHelper.drag( handle, -130 ); |
| 41 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 42 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 43 |
} ); |
| 44 |
|
| 45 |
QUnit.test( "aspectRatio: 'preserve' (w)", function( assert ) { |
| 46 |
assert.expect( 4 ); |
| 47 |
|
| 48 |
var handle = ".ui-resizable-w", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 49 |
|
| 50 |
testHelper.drag( handle, -80 ); |
| 51 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 52 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 53 |
|
| 54 |
testHelper.drag( handle, 130 ); |
| 55 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 56 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 57 |
} ); |
| 58 |
|
| 59 |
QUnit.test( "aspectRatio: 'preserve' (n)", function( assert ) { |
| 60 |
assert.expect( 4 ); |
| 61 |
|
| 62 |
var handle = ".ui-resizable-n", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 63 |
|
| 64 |
testHelper.drag( handle, 0, -80 ); |
| 65 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 66 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 67 |
|
| 68 |
testHelper.drag( handle, 0, 80 ); |
| 69 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 70 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 71 |
} ); |
| 72 |
|
| 73 |
QUnit.test( "aspectRatio: 'preserve' (s)", function( assert ) { |
| 74 |
assert.expect( 4 ); |
| 75 |
|
| 76 |
var handle = ".ui-resizable-s", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 77 |
|
| 78 |
testHelper.drag( handle, 0, 80 ); |
| 79 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 80 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 81 |
|
| 82 |
testHelper.drag( handle, 0, -80 ); |
| 83 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 84 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 85 |
} ); |
| 86 |
|
| 87 |
QUnit.test( "aspectRatio: 'preserve' (se)", function( assert ) { |
| 88 |
assert.expect( 4 ); |
| 89 |
|
| 90 |
var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 91 |
|
| 92 |
testHelper.drag( handle, 80, 80 ); |
| 93 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 94 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 95 |
|
| 96 |
testHelper.drag( handle, -80, -80 ); |
| 97 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 98 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 99 |
} ); |
| 100 |
|
| 101 |
QUnit.test( "aspectRatio: 'preserve' (sw)", function( assert ) { |
| 102 |
assert.expect( 4 ); |
| 103 |
|
| 104 |
var handle = ".ui-resizable-sw", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 105 |
|
| 106 |
testHelper.drag( handle, -80, 80 ); |
| 107 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 108 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 109 |
|
| 110 |
testHelper.drag( handle, 80, -80 ); |
| 111 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 112 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 113 |
} ); |
| 114 |
|
| 115 |
QUnit.test( "aspectRatio: 'preserve' (ne)", function( assert ) { |
| 116 |
assert.expect( 4 ); |
| 117 |
|
| 118 |
var handle = ".ui-resizable-ne", target = $( "#resizable1" ).resizable( { aspectRatio: "preserve", handles: "all", minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 } ); |
| 119 |
|
| 120 |
testHelper.drag( handle, 80, -80 ); |
| 121 |
assert.equal( target.width(), 130, "compare maxWidth" ); |
| 122 |
assert.equal( target.height(), 130, "compare maxHeight" ); |
| 123 |
|
| 124 |
testHelper.drag( handle, -80, 80 ); |
| 125 |
assert.equal( target.width(), 70, "compare minWidth" ); |
| 126 |
assert.equal( target.height(), 70, "compare minHeight" ); |
| 127 |
} ); |
| 128 |
|
| 129 |
QUnit.test( "aspectRatio: Resizing can move objects", function( assert ) { |
| 130 |
assert.expect( 7 ); |
| 131 |
|
| 132 |
|
| 133 |
var handleW = ".ui-resizable-w", |
| 134 |
handleNW = ".ui-resizable-nw", |
| 135 |
target = $( "#resizable1" ).resizable( { |
| 136 |
aspectRatio: true, |
| 137 |
handles: "all", |
| 138 |
containment: "parent" |
| 139 |
} ); |
| 140 |
|
| 141 |
$( "#container" ).css( { width: 200, height: 300 } ); |
| 142 |
$( "#resizable1" ).css( { width: 100, height: 100, left: 75, top: 200 } ); |
| 143 |
|
| 144 |
testHelper.drag( handleW, -20 ); |
| 145 |
assert.equal( target.width(), 100, "compare width - no size change" ); |
| 146 |
assert.equal( target.height(), 100, "compare height - no size change" ); |
| 147 |
assert.equal( target.position().left, 75, "compare left - no movement" ); |
| 148 |
|
| 149 |
|
| 150 |
$( "#container" ).css( { width: 200, height: 300, position: "absolute", left: 100, top: 100 } ); |
| 151 |
$( "#resizable1" ).css( { width: 100, height: 100, left: 0, top: 0 } ); |
| 152 |
|
| 153 |
testHelper.drag( handleNW, -20, -20 ); |
| 154 |
assert.equal( target.width(), 100, "compare width - no size change" ); |
| 155 |
assert.equal( target.height(), 100, "compare height - no size change" ); |
| 156 |
assert.equal( target.position().left, 0, "compare left - no movement" ); |
| 157 |
assert.equal( target.position().top, 0, "compare top - no movement" ); |
| 158 |
} ); |
| 159 |
|
| 160 |
QUnit.test( "aspectRatio: aspectRatio can be changed after initialization", function( assert ) { |
| 161 |
assert.expect( 4 ); |
| 162 |
|
| 163 |
var target = $( "#resizable1" ) |
| 164 |
.resizable( { aspectRatio: 1 } ) |
| 165 |
.resizable( "option", "aspectRatio", false ); |
| 166 |
|
| 167 |
var handle = ".ui-resizable-e"; |
| 168 |
|
| 169 |
testHelper.drag( handle, 80 ); |
| 170 |
|
| 171 |
assert.equal( target.width(), 180, "compare width - size change" ); |
| 172 |
assert.equal( target.height(), 100, "compare height - no size change" ); |
| 173 |
|
| 174 |
target.resizable( "option", "aspectRatio", 2 ); |
| 175 |
|
| 176 |
testHelper.drag( handle, -40 ); |
| 177 |
|
| 178 |
assert.equal( target.width(), 140, "compare width - size change" ); |
| 179 |
assert.equal( target.height(), 70, "compare height - size change in proper relation" ); |
| 180 |
} ); |
| 181 |
|
| 182 |
QUnit.test( "containment", function( assert ) { |
| 183 |
assert.expect( 4 ); |
| 184 |
|
| 185 |
var element = $( "#resizable1" ).resizable( { |
| 186 |
containment: "#container" |
| 187 |
} ); |
| 188 |
|
| 189 |
testHelper.drag( ".ui-resizable-se", 20, 30 ); |
| 190 |
assert.equal( element.width(), 120, "unconstrained width within container" ); |
| 191 |
assert.equal( element.height(), 130, "unconstrained height within container" ); |
| 192 |
|
| 193 |
testHelper.drag( ".ui-resizable-se", 400, 400 ); |
| 194 |
assert.equal( element.width(), 300, "constrained width at containment edge" ); |
| 195 |
assert.equal( element.height(), 200, "constrained height at containment edge" ); |
| 196 |
} ); |
| 197 |
|
| 198 |
QUnit.test( "containment - not immediate parent", function( assert ) { |
| 199 |
assert.expect( 4 ); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
var element = $( "#child" ).resizable( { |
| 204 |
containment: "#container2", |
| 205 |
handles: "all" |
| 206 |
} ); |
| 207 |
|
| 208 |
testHelper.drag( ".ui-resizable-e", 300, 0 ); |
| 209 |
assert.equal( element.width(), 400, "Relative, contained within container width" ); |
| 210 |
|
| 211 |
testHelper.drag( ".ui-resizable-s", 0, 300 ); |
| 212 |
assert.equal( element.height(), 400, "Relative, contained within container height" ); |
| 213 |
|
| 214 |
$( "#child" ).css( { left: 50, top: 50 } ); |
| 215 |
$( "#parent" ).css( { left: 50, top: 50 } ); |
| 216 |
$( "#container2" ).css( { left: 50, top: 50 } ); |
| 217 |
|
| 218 |
element = $( "#child" ).resizable( { |
| 219 |
containment: "#container2", |
| 220 |
handles: "all" |
| 221 |
} ); |
| 222 |
|
| 223 |
testHelper.drag( ".ui-resizable-e", 400, 0 ); |
| 224 |
assert.equal( element.width(), 300, "Relative with Left, contained within container width" ); |
| 225 |
|
| 226 |
testHelper.drag( ".ui-resizable-s", 0, 400 ); |
| 227 |
assert.equal( element.height(), 300, "Relative with Top, contained within container height" ); |
| 228 |
} ); |
| 229 |
|
| 230 |
QUnit.test( "containment - immediate parent", function( assert ) { |
| 231 |
assert.expect( 4 ); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
var element = $( "#child" ).resizable( { |
| 236 |
containment: "parent", |
| 237 |
handles: "all" |
| 238 |
} ); |
| 239 |
|
| 240 |
testHelper.drag( ".ui-resizable-e", 400, 0 ); |
| 241 |
assert.equal( element.width(), 300, "Relative, contained within container width" ); |
| 242 |
|
| 243 |
testHelper.drag( ".ui-resizable-s", 0, 400 ); |
| 244 |
assert.equal( element.height(), 300, "Relative, contained within container height" ); |
| 245 |
|
| 246 |
$( "#child" ).css( { left: 50, top: 50 } ); |
| 247 |
$( "#parent" ).css( { left: 50, top: 50 } ); |
| 248 |
$( "#container2" ).css( { left: 50, top: 50 } ); |
| 249 |
|
| 250 |
element = $( "#child" ).resizable( { |
| 251 |
containment: "parent", |
| 252 |
handles: "all" |
| 253 |
} ); |
| 254 |
|
| 255 |
testHelper.drag( ".ui-resizable-e", 400, 0 ); |
| 256 |
assert.equal( element.width(), 250, "Relative with Left, contained within container width" ); |
| 257 |
|
| 258 |
testHelper.drag( ".ui-resizable-s", 0, 400 ); |
| 259 |
assert.equal( element.height(), 250, "Relative with Top, contained within container height" ); |
| 260 |
} ); |
| 261 |
|
| 262 |
QUnit.test( "grid", function( assert ) { |
| 263 |
assert.expect( 4 ); |
| 264 |
|
| 265 |
var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { handles: "all", grid: [ 0, 20 ] } ); |
| 266 |
|
| 267 |
testHelper.drag( handle, 3, 9 ); |
| 268 |
assert.equal( target.width(), 103, "compare width" ); |
| 269 |
assert.equal( target.height(), 100, "compare height" ); |
| 270 |
|
| 271 |
testHelper.drag( handle, 15, 11 ); |
| 272 |
assert.equal( target.width(), 118, "compare width" ); |
| 273 |
assert.equal( target.height(), 120, "compare height" ); |
| 274 |
} ); |
| 275 |
|
| 276 |
QUnit.test( "grid (min/max dimensions)", function( assert ) { |
| 277 |
assert.expect( 4 ); |
| 278 |
|
| 279 |
var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { handles: "all", grid: 20, minWidth: 65, minHeight: 65, maxWidth: 135, maxHeight: 135 } ); |
| 280 |
|
| 281 |
testHelper.drag( handle, 50, 50 ); |
| 282 |
assert.equal( target.width(), 120, "grid should respect maxWidth" ); |
| 283 |
assert.equal( target.height(), 120, "grid should respect maxHeight" ); |
| 284 |
|
| 285 |
testHelper.drag( handle, -100, -100 ); |
| 286 |
assert.equal( target.width(), 80, "grid should respect minWidth" ); |
| 287 |
assert.equal( target.height(), 80, "grid should respect minHeight" ); |
| 288 |
} ); |
| 289 |
|
| 290 |
QUnit.test( "grid (wrapped)", function( assert ) { |
| 291 |
assert.expect( 4 ); |
| 292 |
|
| 293 |
var handle = ".ui-resizable-se", target = $( "#resizable2" ).resizable( { handles: "all", grid: [ 0, 20 ] } ); |
| 294 |
|
| 295 |
testHelper.drag( handle, 3, 9 ); |
| 296 |
assert.equal( target.width(), 103, "compare width" ); |
| 297 |
assert.equal( target.height(), 100, "compare height" ); |
| 298 |
|
| 299 |
testHelper.drag( handle, 15, 11 ); |
| 300 |
assert.equal( target.width(), 118, "compare width" ); |
| 301 |
assert.equal( target.height(), 120, "compare height" ); |
| 302 |
} ); |
| 303 |
|
| 304 |
QUnit.test( "grid - Resizable: can be moved when grid option is set (#9611)", function( assert ) { |
| 305 |
assert.expect( 6 ); |
| 306 |
|
| 307 |
var oldPosition, |
| 308 |
handle = ".ui-resizable-nw", |
| 309 |
target = $( "#resizable1" ).resizable( { |
| 310 |
handles: "all", |
| 311 |
grid: 50 |
| 312 |
} ); |
| 313 |
|
| 314 |
testHelper.drag( handle, 50, 50 ); |
| 315 |
assert.equal( target.width(), 50, "compare width" ); |
| 316 |
assert.equal( target.height(), 50, "compare height" ); |
| 317 |
|
| 318 |
oldPosition = target.position(); |
| 319 |
|
| 320 |
testHelper.drag( handle, 50, 50 ); |
| 321 |
assert.equal( target.width(), 50, "compare width" ); |
| 322 |
assert.equal( target.height(), 50, "compare height" ); |
| 323 |
assert.equal( target.position().top, oldPosition.top, "compare top" ); |
| 324 |
assert.equal( target.position().left, oldPosition.left, "compare left" ); |
| 325 |
} ); |
| 326 |
|
| 327 |
QUnit.test( "grid - maintains grid with padding and border when approaching no dimensions", function( assert ) { |
| 328 |
assert.expect( 2 ); |
| 329 |
|
| 330 |
|
| 331 |
var handle = ".ui-resizable-nw", |
| 332 |
target = $( "#resizable1" ).css( { |
| 333 |
padding: 5, |
| 334 |
border: "5px solid black", |
| 335 |
width: 80, |
| 336 |
height: 80 |
| 337 |
} ).resizable( { |
| 338 |
handles: "all", |
| 339 |
grid: [ 50, 12 ] |
| 340 |
} ); |
| 341 |
|
| 342 |
testHelper.drag( handle, 50, 50 ); |
| 343 |
assert.equal( target.outerWidth(), 50, "compare width" ); |
| 344 |
assert.equal( target.outerHeight(), 52, "compare height" ); |
| 345 |
} ); |
| 346 |
|
| 347 |
QUnit.test( "ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function( assert ) { |
| 348 |
assert.expect( 4 ); |
| 349 |
|
| 350 |
var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { handles: "all", minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 } ); |
| 351 |
|
| 352 |
testHelper.drag( handle, -50, -50 ); |
| 353 |
assert.equal( target.width(), 60, "compare minWidth" ); |
| 354 |
assert.equal( target.height(), 60, "compare minHeight" ); |
| 355 |
|
| 356 |
testHelper.drag( handle, 70, 70 ); |
| 357 |
assert.equal( target.width(), 100, "compare maxWidth" ); |
| 358 |
assert.equal( target.height(), 100, "compare maxHeight" ); |
| 359 |
} ); |
| 360 |
|
| 361 |
QUnit.test( "ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function( assert ) { |
| 362 |
assert.expect( 4 ); |
| 363 |
|
| 364 |
var handle = ".ui-resizable-sw", target = $( "#resizable1" ).resizable( { handles: "all", minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 } ); |
| 365 |
|
| 366 |
testHelper.drag( handle, 50, -50 ); |
| 367 |
assert.equal( target.width(), 60, "compare minWidth" ); |
| 368 |
assert.equal( target.height(), 60, "compare minHeight" ); |
| 369 |
|
| 370 |
testHelper.drag( handle, -70, 70 ); |
| 371 |
assert.equal( target.width(), 100, "compare maxWidth" ); |
| 372 |
assert.equal( target.height(), 100, "compare maxHeight" ); |
| 373 |
} ); |
| 374 |
|
| 375 |
QUnit.test( "ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function( assert ) { |
| 376 |
assert.expect( 4 ); |
| 377 |
|
| 378 |
var handle = ".ui-resizable-ne", target = $( "#resizable1" ).resizable( { handles: "all", minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 } ); |
| 379 |
|
| 380 |
testHelper.drag( handle, -50, 50 ); |
| 381 |
assert.equal( target.width(), 60, "compare minWidth" ); |
| 382 |
assert.equal( target.height(), 60, "compare minHeight" ); |
| 383 |
|
| 384 |
testHelper.drag( handle, 70, -70 ); |
| 385 |
assert.equal( target.width(), 100, "compare maxWidth" ); |
| 386 |
assert.equal( target.height(), 100, "compare maxHeight" ); |
| 387 |
} ); |
| 388 |
|
| 389 |
QUnit.test( "ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function( assert ) { |
| 390 |
assert.expect( 4 ); |
| 391 |
|
| 392 |
var handle = ".ui-resizable-nw", target = $( "#resizable1" ).resizable( { handles: "all", minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 } ); |
| 393 |
|
| 394 |
testHelper.drag( handle, 70, 70 ); |
| 395 |
assert.equal( target.width(), 60, "compare minWidth" ); |
| 396 |
assert.equal( target.height(), 60, "compare minHeight" ); |
| 397 |
|
| 398 |
testHelper.drag( handle, -70, -70 ); |
| 399 |
assert.equal( target.width(), 100, "compare maxWidth" ); |
| 400 |
assert.equal( target.height(), 100, "compare maxHeight" ); |
| 401 |
} ); |
| 402 |
|
| 403 |
QUnit.test( "custom handles { handles: { 's': $('#resizer1'), containment: 'parent' }", function( assert ) { |
| 404 |
assert.expect( 2 ); |
| 405 |
|
| 406 |
var handle = "#resizer1", |
| 407 |
target = $( "#resizable1" ).resizable( { handles: { "s": $( "#resizer1" ) }, containment: "parent" } ); |
| 408 |
|
| 409 |
testHelper.drag( handle, 0, 70 ); |
| 410 |
assert.equal( target.height(), 170, "compare height" ); |
| 411 |
|
| 412 |
testHelper.drag( handle, 0, -70 ); |
| 413 |
assert.equal( target.height(), 100, "compare height" ); |
| 414 |
} ); |
| 415 |
|
| 416 |
QUnit.test( "custom handles { handles: { 's': $('#resizer1')[0], containment: 'parent' }", function( assert ) { |
| 417 |
assert.expect( 2 ); |
| 418 |
|
| 419 |
var handle = "#resizer1", |
| 420 |
target = $( "#resizable1" ).resizable( { handles: { "s": $( "#resizer1" )[ 0 ] }, containment: "parent" } ); |
| 421 |
|
| 422 |
testHelper.drag( handle, 0, 70 ); |
| 423 |
assert.equal( target.height(), 170, "compare height" ); |
| 424 |
|
| 425 |
testHelper.drag( handle, 0, -70 ); |
| 426 |
assert.equal( target.height(), 100, "compare height" ); |
| 427 |
} ); |
| 428 |
|
| 429 |
QUnit.test( "zIndex, applied to all handles", function( assert ) { |
| 430 |
assert.expect( 8 ); |
| 431 |
|
| 432 |
var target = $( "<div></div>" ).resizable( { handles: "all", zIndex: 100 } ); |
| 433 |
target.children( ".ui-resizable-handle" ).each( function( index, handle ) { |
| 434 |
assert.equal( $( handle ).css( "zIndex" ), 100, "compare zIndex" ); |
| 435 |
} ); |
| 436 |
} ); |
| 437 |
|
| 438 |
QUnit.test( "setOption handles", function( assert ) { |
| 439 |
assert.expect( 19 ); |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
var target = $( "<div></div>" ).resizable(), |
| 444 |
target2 = $( "<div>" + |
| 445 |
"<div class='ui-resizable-handle ui-resizable-e'></div>" + |
| 446 |
"<div class='ui-resizable-handle ui-resizable-w'></div>" + |
| 447 |
"</div>" ).resizable( { |
| 448 |
handles: { |
| 449 |
"e": "ui-resizable-e", |
| 450 |
"w": "ui-resizable-w" |
| 451 |
} |
| 452 |
} ); |
| 453 |
|
| 454 |
function checkHandles( target, expectedHandles ) { |
| 455 |
expectedHandles = $.map( expectedHandles, function( value ) { |
| 456 |
return ".ui-resizable-" + value; |
| 457 |
} ); |
| 458 |
|
| 459 |
var handles = target.find( ".ui-resizable-handle" ); |
| 460 |
|
| 461 |
assert.equal( handles.length, expectedHandles.length, "Correct number of handles found" ); |
| 462 |
$.each( expectedHandles, function( index, handleClass ) { |
| 463 |
assert.equal( handles.filter( handleClass ).length, 1, "Found " + handleClass ); |
| 464 |
} ); |
| 465 |
} |
| 466 |
|
| 467 |
checkHandles( target, [ "e", "s", "se" ] ); |
| 468 |
|
| 469 |
target.resizable( "option", "handles", "n, w, nw" ); |
| 470 |
checkHandles( target, [ "n", "w", "nw" ] ); |
| 471 |
|
| 472 |
target.resizable( "option", "handles", "s, w" ); |
| 473 |
checkHandles( target, [ "s", "w" ] ); |
| 474 |
|
| 475 |
target2.resizable( "option", "handles", "e, s, w" ); |
| 476 |
checkHandles( target2, [ "e", "s", "w" ] ); |
| 477 |
|
| 478 |
target.resizable( "destroy" ); |
| 479 |
checkHandles( target, [ ] ); |
| 480 |
|
| 481 |
target2.resizable( "destroy" ); |
| 482 |
checkHandles( target2, [ "e", "w" ] ); |
| 483 |
} ); |
| 484 |
|
| 485 |
QUnit.test( "alsoResize + containment", function( assert ) { |
| 486 |
assert.expect( 4 ); |
| 487 |
var other = $( "<div>" ) |
| 488 |
.css( { |
| 489 |
width: 50, |
| 490 |
height: 50 |
| 491 |
} ) |
| 492 |
.appendTo( "body" ), |
| 493 |
element = $( "#resizable1" ).resizable( { |
| 494 |
alsoResize: other, |
| 495 |
containment: "#container" |
| 496 |
} ); |
| 497 |
|
| 498 |
testHelper.drag( ".ui-resizable-se", 400, 400 ); |
| 499 |
assert.equal( element.width(), 300, "resizable constrained width at containment edge" ); |
| 500 |
assert.equal( element.height(), 200, "resizable constrained height at containment edge" ); |
| 501 |
assert.equal( other.width(), 250, "alsoResize constrained width at containment edge" ); |
| 502 |
assert.equal( other.height(), 150, "alsoResize constrained height at containment edge" ); |
| 503 |
} ); |
| 504 |
|
| 505 |
QUnit.test( "alsoResize + multiple selection", function( assert ) { |
| 506 |
assert.expect( 6 ); |
| 507 |
var other1 = $( "<div>" ) |
| 508 |
.addClass( "other" ) |
| 509 |
.css( { |
| 510 |
width: 50, |
| 511 |
height: 50 |
| 512 |
} ) |
| 513 |
.appendTo( "body" ), |
| 514 |
other2 = $( "<div>" ) |
| 515 |
.addClass( "other" ) |
| 516 |
.css( { |
| 517 |
width: 50, |
| 518 |
height: 50 |
| 519 |
} ) |
| 520 |
.appendTo( "body" ), |
| 521 |
element = $( "#resizable1" ).resizable( { |
| 522 |
alsoResize: other1.add( other2 ), |
| 523 |
containment: "#container" |
| 524 |
} ); |
| 525 |
|
| 526 |
testHelper.drag( ".ui-resizable-se", 400, 400 ); |
| 527 |
|
| 528 |
assert.strictEqual( element.width(), 300, |
| 529 |
"resizable constrained width at containment edge" ); |
| 530 |
assert.strictEqual( element.height(), 200, |
| 531 |
"resizable constrained height at containment edge" ); |
| 532 |
assert.strictEqual( other1.width(), 250, |
| 533 |
"alsoResize o1 constrained width at containment edge" ); |
| 534 |
assert.strictEqual( other1.height(), 150, |
| 535 |
"alsoResize o1 constrained height at containment edge" ); |
| 536 |
assert.strictEqual( other2.width(), 250, |
| 537 |
"alsoResize o2 constrained width at containment edge" ); |
| 538 |
assert.strictEqual( other2.height(), 150, |
| 539 |
"alsoResize o2 constrained height at containment edge" ); |
| 540 |
} ); |
| 541 |
|
| 542 |
QUnit.test( "alsoResize with box-sizing: border-box", function( assert ) { |
| 543 |
assert.expect( 4 ); |
| 544 |
|
| 545 |
$( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "#qunit-fixture" ); |
| 546 |
|
| 547 |
var other = $( "<div>" ) |
| 548 |
.css( { |
| 549 |
width: "50px", |
| 550 |
height: "50px", |
| 551 |
padding: "10px", |
| 552 |
border: "5px", |
| 553 |
borderStyle: "solid" |
| 554 |
} ) |
| 555 |
.appendTo( "#qunit-fixture" ), |
| 556 |
element = $( "#resizable1" ).resizable( { |
| 557 |
alsoResize: other |
| 558 |
} ), |
| 559 |
handle = ".ui-resizable-se"; |
| 560 |
|
| 561 |
testHelper.drag( handle, 80, 80 ); |
| 562 |
|
| 563 |
assert.equal( element.width(), 180, "resizable width" ); |
| 564 |
assert.equal( parseFloat( other.css( "width" ) ), 130, "alsoResize width" ); |
| 565 |
assert.equal( element.height(), 180, "resizable height" ); |
| 566 |
assert.equal( parseFloat( other.css( "height" ) ), 130, "alsoResize height" ); |
| 567 |
} ); |
| 568 |
|
| 569 |
QUnit.test( "alsoResize with scrollbars and box-sizing: border-box", function( assert ) { |
| 570 |
assert.expect( 4 ); |
| 571 |
testAlsoResizeWithBoxSizing( assert, { |
| 572 |
isBorderBox: true |
| 573 |
} ); |
| 574 |
} ); |
| 575 |
|
| 576 |
QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function( assert ) { |
| 577 |
assert.expect( 4 ); |
| 578 |
testAlsoResizeWithBoxSizing( assert, { |
| 579 |
isBorderBox: false |
| 580 |
} ); |
| 581 |
} ); |
| 582 |
|
| 583 |
function testAlsoResizeWithBoxSizing( assert, options ) { |
| 584 |
var widthBefore, heightBefore, |
| 585 |
cssBoxSizing = options.isBorderBox ? "border-box" : "content-box", |
| 586 |
other = $( "<div>" ) |
| 587 |
.css( { |
| 588 |
width: "150px", |
| 589 |
height: "150px", |
| 590 |
padding: "10px", |
| 591 |
border: "5px", |
| 592 |
borderStyle: "solid", |
| 593 |
margin: "20px", |
| 594 |
overflow: "scroll" |
| 595 |
} ) |
| 596 |
.appendTo( "#qunit-fixture" ), |
| 597 |
element = $( "#resizable1" ).resizable( { |
| 598 |
alsoResize: other |
| 599 |
} ), |
| 600 |
handle = ".ui-resizable-se"; |
| 601 |
|
| 602 |
$( "<style> * { box-sizing: " + cssBoxSizing + "; } </style>" ).appendTo( "#qunit-fixture" ); |
| 603 |
|
| 604 |
|
| 605 |
widthBefore = other.innerWidth(); |
| 606 |
heightBefore = other.innerHeight(); |
| 607 |
|
| 608 |
testHelper.drag( handle, 80, 80 ); |
| 609 |
|
| 610 |
assert.equal( element.width(), 180, "resizable width" ); |
| 611 |
assert.equal( parseFloat( other.innerWidth() ), widthBefore + 80, "alsoResize width" ); |
| 612 |
assert.equal( element.height(), 180, "resizable height" ); |
| 613 |
assert.equal( parseFloat( other.innerHeight() ), heightBefore + 80, "alsoResize height" ); |
| 614 |
} |
| 615 |
|
| 616 |
} ); |