2015-04-06 18:50:39 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 02:08:51 +00:00
|
|
|
"ui/widgets/sortable"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
|
|
|
module("sortable: methods");
|
|
|
|
|
2009-02-03 00:33:00 +00:00
|
|
|
test("init", function() {
|
2012-11-02 00:54:52 +00:00
|
|
|
expect(5);
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").appendTo("body").sortable().remove();
|
|
|
|
ok(true, ".sortable() called on element");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
$([]).sortable();
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, ".sortable() called on empty collection");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
$("<div></div>").sortable();
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, ".sortable() called on disconnected DOMElement");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2009-11-09 01:50:23 +00:00
|
|
|
$("<div></div>").sortable().sortable("option", "foo");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, "arbitrary option getter after init");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2009-11-09 01:50:23 +00:00
|
|
|
$("<div></div>").sortable().sortable("option", "foo", "bar");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, "arbitrary option setter after init");
|
2009-02-03 00:33:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
2012-11-02 00:54:52 +00:00
|
|
|
expect(4);
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").appendTo("body").sortable().sortable("destroy").remove();
|
|
|
|
ok(true, ".sortable('destroy') called on element");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
$([]).sortable().sortable("destroy");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, ".sortable('destroy') called on empty collection");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
$("<div></div>").sortable().sortable("destroy");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, ".sortable('destroy') called on disconnected DOMElement");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
var expected = $("<div></div>").sortable(),
|
|
|
|
actual = expected.sortable("destroy");
|
|
|
|
equal(actual, expected, "destroy is chainable");
|
2009-02-03 00:33:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("enable", function() {
|
2009-04-15 02:33:28 +00:00
|
|
|
expect(5);
|
2012-11-03 20:17:16 +00:00
|
|
|
|
|
|
|
var el, actual, expected;
|
|
|
|
|
2009-02-03 00:33:00 +00:00
|
|
|
el = $("#sortable").sortable({ disabled: true });
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort($("li", el)[0], 0, 44, 0, ".sortable({ disabled: true })");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
el.sortable("enable");
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.sortable("option", "disabled"), false, "disabled option getter");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
|
|
|
el.sortable("destroy");
|
|
|
|
el.sortable({ disabled: true });
|
2009-11-09 01:50:23 +00:00
|
|
|
el.sortable("option", "disabled", false);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.sortable("option", "disabled"), false, "disabled option setter");
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort($("li", el)[0], 0, 44, 2, ".sortable('option', 'disabled', false)");
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
expected = $("<div></div>").sortable(),
|
|
|
|
actual = expected.sortable("enable");
|
|
|
|
equal(actual, expected, "enable is chainable");
|
2009-02-03 00:33:00 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:37:32 +00:00
|
|
|
test( "disable", function( assert ) {
|
2013-03-14 23:08:21 +00:00
|
|
|
expect( 9 );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
var chainable,
|
|
|
|
element = $( "#sortable" ).sortable({ disabled: false });
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" );
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
chainable = element.sortable( "disable" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 0, "disabled.sortable getter" );
|
2009-02-03 00:33:00 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.sortable( "destroy" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.sortable({ disabled: false });
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" );
|
2013-03-14 23:08:21 +00:00
|
|
|
element.sortable( "option", "disabled", true);
|
|
|
|
equal( element.sortable( "option", "disabled" ), true, "disabled option setter" );
|
2013-03-12 01:28:51 +00:00
|
|
|
|
2015-02-03 00:37:32 +00:00
|
|
|
assert.lacksClasses( element.sortable( "widget" ), "ui-state-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
ok( !element.sortable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
2015-02-03 00:37:32 +00:00
|
|
|
assert.hasClasses( element.sortable( "widget" ), "ui-sortable-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.sort($( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" );
|
2013-03-14 23:08:21 +00:00
|
|
|
equal( chainable, element, "disable is chainable" );
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2014-10-31 13:46:41 +00:00
|
|
|
test( "refresh() should update the positions of initially empty lists (see #7498)", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var changeCount = 0,
|
|
|
|
element = $( "#qunit-fixture" ).html( "<ul></ul>" ).find( "ul" );
|
|
|
|
|
|
|
|
element
|
|
|
|
.css({
|
|
|
|
"float": "left",
|
|
|
|
width: "100px"
|
|
|
|
})
|
|
|
|
.sortable({
|
|
|
|
change: function() {
|
|
|
|
changeCount++;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.append( "<li>a</li><li>a</li>" )
|
|
|
|
.find( "li" )
|
|
|
|
.css({
|
|
|
|
"float": "left",
|
|
|
|
width: "50px",
|
|
|
|
height: "50px"
|
|
|
|
});
|
|
|
|
|
|
|
|
element.sortable( "refresh" );
|
|
|
|
|
|
|
|
// Switch the order of the two li elements
|
|
|
|
element.find( "li" ).eq( 0 ).simulate( "drag", {
|
|
|
|
dx: 55,
|
|
|
|
moves: 15
|
|
|
|
});
|
|
|
|
|
|
|
|
equal( changeCount, 1 );
|
|
|
|
});
|
|
|
|
|
2015-04-06 18:50:39 +00:00
|
|
|
} );
|