2015-04-06 16:42:49 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:59:40 +00:00
|
|
|
"ui/widgets/draggable"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var element;
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
module( "draggable: methods", {
|
|
|
|
setup: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>" ).appendTo( "#qunit-fixture" );
|
2013-01-12 05:33:45 +00:00
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
element.remove();
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
test( "init", function() {
|
|
|
|
expect( 5 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable();
|
|
|
|
ok( true, ".draggable() called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( [] ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable() called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "<div></div>" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable() called on disconnected DOMElement" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "foo" );
|
|
|
|
ok( true, "arbitrary option getter after init" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "foo", "bar" );
|
|
|
|
ok( true, "arbitrary option setter after init" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "destroy", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable().draggable( "destroy" );
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable('destroy') called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( [] ).draggable().draggable( "destroy" );
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable('destroy') called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable().draggable( "destroy" );
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2015-08-24 12:59:44 +00:00
|
|
|
actual = expected.draggable( "destroy" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "destroy is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "enable", function() {
|
2014-08-22 15:51:15 +00:00
|
|
|
expect( 11 );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( { disabled: true } );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "enable" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldMove( element, ".draggable('enable')" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "destroy" );
|
|
|
|
element.draggable( { disabled: true } );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "disabled", false );
|
2015-08-24 12:59:44 +00:00
|
|
|
equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldMove( element, ".draggable('option', 'disabled', false)" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2015-08-24 12:59:44 +00:00
|
|
|
actual = expected.draggable( "enable" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "enable is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-01-30 14:57:30 +00:00
|
|
|
test( "disable", function( assert ) {
|
2014-08-22 15:51:15 +00:00
|
|
|
expect( 14 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( { disabled: false } );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.draggable( "disable" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldNotDrag( element, ".draggable('disable')" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( { disabled: false } );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "disabled", true );
|
|
|
|
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.shouldNotDrag( element, ".draggable('option', 'disabled', true)" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.hasClasses( element.draggable( "widget" ), "ui-draggable-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2013-03-14 23:08:21 +00:00
|
|
|
actual = expected.draggable( "disable" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "disable is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-04-06 16:42:49 +00:00
|
|
|
} );
|