| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"ui/widgets/sortable" |
| 6 |
], function( QUnit, $, helper ) { |
| 7 |
"use strict"; |
| 8 |
|
| 9 |
QUnit.module( "sortable: options", { afterEach: helper.moduleAfterEach } ); |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
QUnit.test( "{ axis: false }, default", function( assert ) { |
| 22 |
assert.expect( 2 ); |
| 23 |
|
| 24 |
var offsetAfter, |
| 25 |
element = $( "#sortable" ).sortable( { |
| 26 |
axis: false, |
| 27 |
change: function() { |
| 28 |
offsetAfter = item.offset(); |
| 29 |
assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: false" ); |
| 30 |
assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: false" ); |
| 31 |
} |
| 32 |
} ), |
| 33 |
item = element.find( "li" ).eq( 0 ), |
| 34 |
offsetBefore = item.offset(); |
| 35 |
|
| 36 |
item.simulate( "drag", { |
| 37 |
dx: 50, |
| 38 |
dy: 25, |
| 39 |
moves: 1 |
| 40 |
} ); |
| 41 |
} ); |
| 42 |
|
| 43 |
QUnit.test( "{ axis: 'x' }", function( assert ) { |
| 44 |
assert.expect( 2 ); |
| 45 |
|
| 46 |
var offsetAfter, |
| 47 |
element = $( "#sortable" ).sortable( { |
| 48 |
axis: "x", |
| 49 |
change: function() { |
| 50 |
offsetAfter = item.offset(); |
| 51 |
assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" ); |
| 52 |
assert.equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" ); |
| 53 |
} |
| 54 |
} ), |
| 55 |
item = element.find( "li" ).eq( 0 ), |
| 56 |
offsetBefore = item.offset(); |
| 57 |
|
| 58 |
item.simulate( "drag", { |
| 59 |
dx: 50, |
| 60 |
dy: 25, |
| 61 |
moves: 1 |
| 62 |
} ); |
| 63 |
} ); |
| 64 |
|
| 65 |
QUnit.test( "{ axis: 'y' }", function( assert ) { |
| 66 |
assert.expect( 2 ); |
| 67 |
|
| 68 |
var offsetAfter, |
| 69 |
element = $( "#sortable" ).sortable( { |
| 70 |
axis: "y", |
| 71 |
change: function() { |
| 72 |
offsetAfter = item.offset(); |
| 73 |
assert.equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" ); |
| 74 |
assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" ); |
| 75 |
} |
| 76 |
} ), |
| 77 |
item = element.find( "li" ).eq( 0 ), |
| 78 |
offsetBefore = item.offset(); |
| 79 |
|
| 80 |
item.simulate( "drag", { |
| 81 |
dx: 50, |
| 82 |
dy: 25, |
| 83 |
moves: 1 |
| 84 |
} ); |
| 85 |
} ); |
| 86 |
|
| 87 |
QUnit.test( "#7415: Incorrect revert animation with axis: 'y'", function( assert ) { |
| 88 |
var ready = assert.async(); |
| 89 |
assert.expect( 2 ); |
| 90 |
var expectedLeft, |
| 91 |
element = $( "#sortable" ).sortable( { |
| 92 |
axis: "y", |
| 93 |
revert: true, |
| 94 |
sort: function() { |
| 95 |
expectedLeft = item.css( "left" ); |
| 96 |
} |
| 97 |
} ), |
| 98 |
item = element.find( "li" ).eq( 0 ); |
| 99 |
|
| 100 |
item.simulate( "drag", { |
| 101 |
dy: 300, |
| 102 |
dx: 50 |
| 103 |
} ); |
| 104 |
|
| 105 |
setTimeout( function() { |
| 106 |
var top = parseFloat( item.css( "top" ) ); |
| 107 |
assert.equal( item.css( "left" ), expectedLeft, "left not animated" ); |
| 108 |
assert.ok( top > 0 && top < 300, "top is animated" ); |
| 109 |
|
| 110 |
|
| 111 |
item.stop( true ); |
| 112 |
|
| 113 |
ready(); |
| 114 |
}, 100 ); |
| 115 |
} ); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
QUnit.test( "#8792: issues with floated items in connected lists", function( assert ) { |
| 128 |
assert.expect( 2 ); |
| 129 |
|
| 130 |
var element, |
| 131 |
changeCount = 0; |
| 132 |
|
| 133 |
$( "#qunit-fixture" ) |
| 134 |
.html( "<ul class='c'><li>a</li><li>a</li></ul><ul class='c'><li>a</li><li>a</li></ul>" ) |
| 135 |
.find( "ul" ).css( { "float": "left", width: "100px" } ).end() |
| 136 |
.find( "li" ).css( { "float": "left", width: "50px", height: "50px" } ); |
| 137 |
|
| 138 |
$( "#qunit-fixture .c" ).sortable( { |
| 139 |
connectWith: "#qunit-fixture .c", |
| 140 |
change: function() { |
| 141 |
changeCount++; |
| 142 |
} |
| 143 |
} ); |
| 144 |
|
| 145 |
element = $( "#qunit-fixture li" ).eq( 0 ); |
| 146 |
|
| 147 |
|
| 148 |
element.simulate( "drag", { |
| 149 |
dx: 55, |
| 150 |
moves: 15 |
| 151 |
} ); |
| 152 |
|
| 153 |
assert.equal( changeCount, 1, "change fired only once (no jitters) when dragging a floated sortable in it's own container" ); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
element.simulate( "drag", { |
| 158 |
dx: 100, |
| 159 |
moves: 15 |
| 160 |
} ); |
| 161 |
|
| 162 |
assert.equal( changeCount, 3, "change fired once for each expected change when dragging a floated sortable to a connected container" ); |
| 163 |
} ); |
| 164 |
|
| 165 |
QUnit.test( "#8301: single axis with connected list", function( assert ) { |
| 166 |
assert.expect( 1 ); |
| 167 |
|
| 168 |
var element = $( "#sortable" ).sortable( { |
| 169 |
axis: "y", |
| 170 |
tolerance: "pointer", |
| 171 |
connectWith: ".connected" |
| 172 |
} ); |
| 173 |
|
| 174 |
$( "<ul class='connected'><li>Item 7</li><li>Item 8</li></ul>" ) |
| 175 |
.sortable( { |
| 176 |
axis: "y", |
| 177 |
tolerance: "pointer", |
| 178 |
connectWith: "#sortable", |
| 179 |
receive: function() { |
| 180 |
assert.ok( true, "connected list received item" ); |
| 181 |
} |
| 182 |
} ) |
| 183 |
.insertAfter( element ); |
| 184 |
|
| 185 |
element.find( "li" ).eq( 0 ).simulate( "drag", { |
| 186 |
handle: "corner", |
| 187 |
dy: 120, |
| 188 |
moves: 1 |
| 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 |
QUnit.test( "{ forcePlaceholderSize: false } table rows", function( assert ) { |
| 267 |
assert.expect( 1 ); |
| 268 |
|
| 269 |
var element = $( "#sortable-table2 tbody" ); |
| 270 |
|
| 271 |
element.sortable( { |
| 272 |
placeholder: "test", |
| 273 |
forcePlaceholderSize: false, |
| 274 |
start: function( event, ui ) { |
| 275 |
assert.notEqual( ui.placeholder.height(), ui.item.height(), |
| 276 |
"placeholder is same height as item" ); |
| 277 |
} |
| 278 |
} ); |
| 279 |
|
| 280 |
|
| 281 |
$( "tr", element ).eq( 0 ).simulate( "drag", { |
| 282 |
dy: 1 |
| 283 |
} ); |
| 284 |
} ); |
| 285 |
|
| 286 |
QUnit.test( "{ forcePlaceholderSize: true } table rows", function( assert ) { |
| 287 |
assert.expect( 2 ); |
| 288 |
|
| 289 |
|
| 290 |
var element = $( "#sortable-table2 tbody" ), |
| 291 |
jqMinor = $.fn.jquery.substring( 0, 4 ); |
| 292 |
|
| 293 |
element.sortable( { |
| 294 |
placeholder: "test", |
| 295 |
forcePlaceholderSize: true, |
| 296 |
start: function( event, ui ) { |
| 297 |
assert.equal( ui.placeholder.height(), ui.item.height(), |
| 298 |
"placeholder is same height as item" ); |
| 299 |
} |
| 300 |
} ); |
| 301 |
|
| 302 |
|
| 303 |
$( "tr", element ).eq( 0 ).simulate( "drag", { |
| 304 |
dy: 1 |
| 305 |
} ); |
| 306 |
|
| 307 |
|
| 308 |
$( "tr", element ).eq( 1 ).simulate( "drag", { |
| 309 |
dy: 1 |
| 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 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
QUnit.test( "{ placeholder: false } img", function( assert ) { |
| 380 |
assert.expect( 3 ); |
| 381 |
|
| 382 |
var done = assert.async(), |
| 383 |
element = $( "#sortable-images" ).sortable( { |
| 384 |
start: function( event, ui ) { |
| 385 |
assert.ok( ui.placeholder.attr( "src" ).indexOf( "images/jqueryui_32x32.png" ) > 0, "placeholder img has correct src" ); |
| 386 |
assert.equal( ui.placeholder.height(), 32, "placeholder has correct height" ); |
| 387 |
assert.equal( ui.placeholder.width(), 32, "placeholder has correct width" ); |
| 388 |
} |
| 389 |
} ); |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
setTimeout( function() { |
| 394 |
element.find( "img" ).eq( 0 ).simulate( "drag", { |
| 395 |
dy: 1 |
| 396 |
} ); |
| 397 |
done(); |
| 398 |
}, 500 ); |
| 399 |
} ); |
| 400 |
|
| 401 |
QUnit.test( "{ placeholder: String }", function( assert ) { |
| 402 |
assert.expect( 1 ); |
| 403 |
|
| 404 |
var element = $( "#sortable" ).sortable( { |
| 405 |
placeholder: "test", |
| 406 |
start: function( event, ui ) { |
| 407 |
assert.hasClasses( ui.placeholder, "test" ); |
| 408 |
} |
| 409 |
} ); |
| 410 |
|
| 411 |
element.find( "li" ).eq( 0 ).simulate( "drag", { |
| 412 |
dy: 1 |
| 413 |
} ); |
| 414 |
} ); |
| 415 |
|
| 416 |
QUnit.test( "{ placholder: String } tr", function( assert ) { |
| 417 |
assert.expect( 4 ); |
| 418 |
|
| 419 |
var originalWidths, |
| 420 |
element = $( "#sortable-table tbody" ).sortable( { |
| 421 |
placeholder: "test", |
| 422 |
start: function( event, ui ) { |
| 423 |
var currentWidths = otherRow.children().map( function() { |
| 424 |
return $( this ).width(); |
| 425 |
} ).get(); |
| 426 |
assert.hasClasses( ui.placeholder, "test" ); |
| 427 |
assert.deepEqual( currentWidths, originalWidths, "table cells maintian size" ); |
| 428 |
assert.equal( ui.placeholder.children().length, dragRow.children().length, |
| 429 |
"placeholder has correct number of cells" ); |
| 430 |
assert.equal( ui.placeholder.children().html(), $( "<span> </span>" ).html(), |
| 431 |
"placeholder td has content for forced dimensions" ); |
| 432 |
} |
| 433 |
} ), |
| 434 |
rows = element.children( "tr" ), |
| 435 |
dragRow = rows.eq( 0 ), |
| 436 |
otherRow = rows.eq( 1 ); |
| 437 |
|
| 438 |
originalWidths = otherRow.children().map( function() { |
| 439 |
return $( this ).width(); |
| 440 |
} ).get(); |
| 441 |
dragRow.simulate( "drag", { |
| 442 |
dy: 1 |
| 443 |
} ); |
| 444 |
} ); |
| 445 |
|
| 446 |
QUnit.test( "{ placholder: String } tbody", function( assert ) { |
| 447 |
assert.expect( 6 ); |
| 448 |
|
| 449 |
var originalWidths, |
| 450 |
element = $( "#sortable-table" ).sortable( { |
| 451 |
placeholder: "test", |
| 452 |
start: function( event, ui ) { |
| 453 |
var currentWidths = otherBody.children().map( function() { |
| 454 |
return $( this ).width(); |
| 455 |
} ).get(); |
| 456 |
assert.ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); |
| 457 |
assert.deepEqual( currentWidths, originalWidths, "table cells maintain size" ); |
| 458 |
assert.equal( ui.placeholder.children().length, 1, |
| 459 |
"placeholder has one child" ); |
| 460 |
assert.equal( ui.placeholder.children( "tr" ).length, 1, |
| 461 |
"placeholder's child is tr" ); |
| 462 |
assert.equal( ui.placeholder.find( "> tr" ).children().length, |
| 463 |
dragBody.find( "> tr" ).first().children().length, |
| 464 |
"placeholder's tr has correct number of cells" ); |
| 465 |
assert.equal( ui.placeholder.find( "> tr" ).children().html(), |
| 466 |
$( "<span> </span>" ).html(), |
| 467 |
"placeholder td has content for forced dimensions" ); |
| 468 |
} |
| 469 |
} ), |
| 470 |
bodies = element.children( "tbody" ), |
| 471 |
dragBody = bodies.eq( 0 ), |
| 472 |
otherBody = bodies.eq( 1 ); |
| 473 |
|
| 474 |
originalWidths = otherBody.children().map( function() { |
| 475 |
return $( this ).width(); |
| 476 |
} ).get(); |
| 477 |
dragBody.simulate( "drag", { |
| 478 |
dy: 1 |
| 479 |
} ); |
| 480 |
} ); |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
QUnit.test( "{ connectToSortable: Selector } positioning (gh-2001)", function( assert ) { |
| 485 |
assert.expect( 1 ); |
| 486 |
|
| 487 |
|
| 488 |
function findCenter( elem ) { |
| 489 |
var offset, |
| 490 |
document = $( elem[ 0 ].ownerDocument ); |
| 491 |
offset = elem.offset(); |
| 492 |
|
| 493 |
return { |
| 494 |
x: Math.floor( offset.left + elem.outerWidth() / 2 - document.scrollLeft() ), |
| 495 |
y: Math.floor( offset.top + elem.outerHeight() / 2 - document.scrollTop( ) ) |
| 496 |
}; |
| 497 |
} |
| 498 |
|
| 499 |
var sortableElem = $( "#sortable" ); |
| 500 |
|
| 501 |
sortableElem.css( "position", "relative" ); |
| 502 |
|
| 503 |
var item = $( "<div></div>" ) |
| 504 |
.text( "6" ) |
| 505 |
.insertBefore( "#sortable" ); |
| 506 |
|
| 507 |
|
| 508 |
$( "<div></div>" ) |
| 509 |
.css( { |
| 510 |
width: "100px", |
| 511 |
height: "100px" |
| 512 |
} ) |
| 513 |
.insertBefore( "#sortable" ); |
| 514 |
|
| 515 |
item.draggable( { |
| 516 |
connectToSortable: "#sortable" |
| 517 |
} ); |
| 518 |
sortableElem.sortable(); |
| 519 |
|
| 520 |
|
| 521 |
var center = findCenter( item ); |
| 522 |
item.simulate( "mousedown", { |
| 523 |
clientX: center.x, |
| 524 |
clientY: center.y |
| 525 |
} ); |
| 526 |
item.simulate( "mousemove", { |
| 527 |
clientX: center.x, |
| 528 |
clientY: center.y + 60 |
| 529 |
} ); |
| 530 |
item.simulate( "mousemove", { |
| 531 |
clientX: center.x, |
| 532 |
clientY: center.y + 120 |
| 533 |
} ); |
| 534 |
|
| 535 |
assert.ok( item.offset().top > sortableElem.children().eq( 0 ).offset().top, |
| 536 |
"Draggable offset correct after moving into a sortable" ); |
| 537 |
} ); |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
} ); |