2009-02-01 00:25:58 +00:00
|
|
|
/*
|
|
|
|
* draggable_methods.js
|
|
|
|
*/
|
2013-01-12 05:33:45 +00:00
|
|
|
(function( $ ) {
|
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() {
|
|
|
|
element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
element.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
$([]).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable() called on empty collection" );
|
2009-02-01 00:25:58 +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" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "destroy", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
element.draggable().draggable("destroy");
|
|
|
|
ok( true, ".draggable('destroy') called on element" );
|
2009-02-01 00:25:58 +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
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable().draggable("destroy");
|
|
|
|
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(),
|
2012-12-26 13:08:48 +00:00
|
|
|
actual = expected.draggable("destroy");
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "destroy is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "enable", function() {
|
|
|
|
expect( 7 );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable({ disabled: true });
|
|
|
|
TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("enable");
|
|
|
|
TestHelpers.draggable.shouldMove( element, ".draggable('enable')" );
|
|
|
|
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("destroy");
|
|
|
|
element.draggable({ disabled: true });
|
|
|
|
TestHelpers.draggable.shouldNotMove( 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 );
|
|
|
|
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
|
|
|
TestHelpers.draggable.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(),
|
|
|
|
actual = expected.draggable("enable");
|
|
|
|
equal( actual, expected, "enable is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "disable", function() {
|
|
|
|
expect( 7 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element = $("#draggable2").draggable({ disabled: false });
|
|
|
|
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("disable");
|
|
|
|
TestHelpers.draggable.shouldNotMove( element, ".draggable('disable')" );
|
|
|
|
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("destroy");
|
|
|
|
element.draggable({ disabled: false });
|
|
|
|
TestHelpers.draggable.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" );
|
|
|
|
TestHelpers.draggable.shouldNotMove( element, ".draggable('option', 'disabled', true)" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
|
|
|
actual = expected.draggable("disable");
|
|
|
|
equal( actual, expected, "disable is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
})( jQuery );
|