2009-02-01 00:25:58 +00:00
|
|
|
/*
|
|
|
|
* draggable_methods.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
function shouldmove(why) {
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50, why);
|
|
|
|
}
|
|
|
|
|
|
|
|
function shouldnotmove(why) {
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(0, 0, why);
|
|
|
|
}
|
|
|
|
|
|
|
|
module("draggable: methods");
|
|
|
|
|
|
|
|
test("init", function() {
|
|
|
|
expect(6);
|
|
|
|
|
|
|
|
$("<div></div>").appendTo('body').draggable().remove();
|
|
|
|
ok(true, '.draggable() called on element');
|
|
|
|
|
|
|
|
$([]).draggable();
|
|
|
|
ok(true, '.draggable() called on empty collection');
|
|
|
|
|
|
|
|
$("<div></div>").draggable();
|
|
|
|
ok(true, '.draggable() called on disconnected DOMElement');
|
|
|
|
|
|
|
|
$("<div></div>").draggable().draggable("foo");
|
|
|
|
ok(true, 'arbitrary method called after init');
|
|
|
|
|
2009-11-09 01:50:23 +00:00
|
|
|
$("<div></div>").draggable().draggable("option", "foo");
|
2009-02-01 00:25:58 +00:00
|
|
|
ok(true, 'arbitrary option getter after init');
|
|
|
|
|
2009-11-09 01:50:23 +00:00
|
|
|
$("<div></div>").draggable().draggable("option", "foo", "bar");
|
2009-02-01 00:25:58 +00:00
|
|
|
ok(true, 'arbitrary option setter after init');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
|
|
|
$("<div></div>").appendTo('body').draggable().draggable("destroy").remove();
|
|
|
|
ok(true, '.draggable("destroy") called on element');
|
|
|
|
|
|
|
|
$([]).draggable().draggable("destroy");
|
|
|
|
ok(true, '.draggable("destroy") called on empty collection');
|
|
|
|
|
|
|
|
$("<div></div>").draggable().draggable("destroy");
|
|
|
|
ok(true, '.draggable("destroy") called on disconnected DOMElement');
|
|
|
|
|
|
|
|
$("<div></div>").draggable().draggable("destroy").draggable("foo");
|
|
|
|
ok(true, 'arbitrary method called after destroy');
|
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
var expected = $('<div></div>').draggable(),
|
|
|
|
actual = expected.draggable('destroy');
|
|
|
|
equals(actual, expected, 'destroy is chainable');
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("enable", function() {
|
2009-04-15 02:33:28 +00:00
|
|
|
expect(7);
|
2009-02-01 00:25:58 +00:00
|
|
|
el = $("#draggable2").draggable({ disabled: true });
|
|
|
|
shouldnotmove('.draggable({ disabled: true })');
|
|
|
|
el.draggable("enable");
|
|
|
|
shouldmove('.draggable("enable")');
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.draggable("option", "disabled"), false, "disabled option getter");
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
el.draggable("destroy");
|
|
|
|
el.draggable({ disabled: true });
|
|
|
|
shouldnotmove('.draggable({ disabled: true })');
|
2009-11-09 01:50:23 +00:00
|
|
|
el.draggable("option", "disabled", false);
|
|
|
|
equals(el.draggable("option", "disabled"), false, "disabled option setter");
|
|
|
|
shouldmove('.draggable("option", "disabled", false)');
|
2009-04-15 02:33:28 +00:00
|
|
|
|
|
|
|
var expected = $('<div></div>').draggable(),
|
|
|
|
actual = expected.draggable('enable');
|
|
|
|
equals(actual, expected, 'enable is chainable');
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("disable", function() {
|
2009-04-15 02:33:28 +00:00
|
|
|
expect(7);
|
2009-02-01 00:25:58 +00:00
|
|
|
el = $("#draggable2").draggable({ disabled: false });
|
|
|
|
shouldmove('.draggable({ disabled: false })');
|
|
|
|
el.draggable("disable");
|
|
|
|
shouldnotmove('.draggable("disable")');
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.draggable("option", "disabled"), true, "disabled option getter");
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
el.draggable("destroy");
|
|
|
|
|
|
|
|
el.draggable({ disabled: false });
|
|
|
|
shouldmove('.draggable({ disabled: false })');
|
2009-11-09 01:50:23 +00:00
|
|
|
el.draggable("option", "disabled", true);
|
|
|
|
equals(el.draggable("option", "disabled"), true, "disabled option setter");
|
|
|
|
shouldnotmove('.draggable("option", "disabled", true)');
|
2009-04-15 02:33:28 +00:00
|
|
|
|
|
|
|
var expected = $('<div></div>').draggable(),
|
|
|
|
actual = expected.draggable('disable');
|
|
|
|
equals(actual, expected, 'disable is chainable');
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|