"Position": "position/position.html",
"Progressbar": "progressbar/progressbar.html",
//"Resizable": "resizable/resizable.html",
- //"Selectable": "selectable/selectable.html",
+ "Selectable": "selectable/selectable.html",
//"Slider": "slider/slider.html",
//"Sortable": "sortable/sortable.html",
"Spinner": "spinner/spinner.html",
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
- return !( /(all|all-active|index|test|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
+ return !( /(all|all-active|index|test|droppable|resizable|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
})
},
lint: {
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
// TODO remove items from this list once rewritten
- return !( /(mouse|datepicker|droppable|resizable|selectable|sortable)\.js$/ ).test( file );
+ return !( /(mouse|datepicker|droppable|resizable|sortable)\.js$/ ).test( file );
}),
grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js"
"position/position.html",
"progressbar/progressbar.html",
//"resizable/resizable.html",
- //"selectable/selectable.html",
+ "selectable/selectable.html",
//"slider/slider.html",
//"sortable/sortable.html",
"spinner/spinner.html",
"position/position.html",
"progressbar/progressbar.html",
//"resizable/resizable.html",
- //"selectable/selectable.html",
+ "selectable/selectable.html",
"slider/slider.html",
//"sortable/sortable.html",
"spinner/spinner.html",
appendTo: 'body',
autoRefresh: true,
cancel: 'input,textarea,button,select,option',
+ create: null,
delay: 0,
disabled: false,
distance: 0,
* selectable_core.js
*/
-var el;
-
-TestHelpers.selectableDrag = function drag(dx, dy) {
- var off = el.offset(), pos = { clientX: off.left, clientY: off.top };
- el.simulate("mousedown", pos);
- $(document).simulate("mousemove", pos);
- pos.clientX += dx;
- pos.clientY += dy;
- $(document).simulate("mousemove", pos);
- $(document).simulate("mouseup", pos);
-};
-
+TestHelpers.selectable = {
+ drag: function drag(el, dx, dy) {
+ var off = el.offset(),
+ pos = { clientX: off.left, clientY: off.top };
+ el.simulate("mousedown", pos);
+ $(document).simulate("mousemove", pos);
+ pos.clientX += dx;
+ pos.clientY += dy;
+ $(document).simulate("mousemove", pos);
+ $(document).simulate("mouseup", pos);
+ }
+};
\ No newline at end of file
test("start", function() {
expect(2);
- el = $("#selectable1");
+ var el = $("#selectable1");
el.selectable({
start: function() {
ok(true, "drag fired start callback");
test("stop", function() {
expect(2);
- el = $("#selectable1");
+ var el = $("#selectable1");
el.selectable({
start: function() {
ok(true, "drag fired stop callback");
module("selectable: methods");
test("init", function() {
- expect(6);
+ expect( 5 );
$("<div></div>").appendTo('body').selectable().remove();
ok(true, '.selectable() called on element');
$("<div></div>").selectable().remove();
ok(true, '.selectable() called on disconnected DOMElement');
- $("<div></div>").selectable().selectable("foo").remove();
- ok(true, 'arbitrary method called after init');
-
- el = $("<div></div>").selectable();
+ var el = $("<div></div>").selectable();
el.selectable("option", "foo");
el.remove();
ok(true, 'arbitrary option getter after init');
});
test("destroy", function() {
+ expect( 4 );
+
$("<div></div>").appendTo('body').selectable().selectable("destroy").remove();
ok(true, '.selectable("destroy") called on element');
$("<div></div>").selectable().selectable("destroy").remove();
ok(true, '.selectable("destroy") called on disconnected DOMElement');
- $("<div></div>").selectable().selectable("destroy").selectable("foo").remove();
- ok(true, 'arbitrary method called after destroy');
-
var expected = $('<div></div>').selectable(),
actual = expected.selectable('destroy');
equal(actual, expected, 'destroy is chainable');
test("enable", function() {
expect(3);
var expected, actual,
- fired = false;
+ fired = false,
+ el = $("#selectable1");
- el = $("#selectable1");
el.selectable({
disabled: true,
start: function() { fired = true; }
test("disable", function() {
expect(3);
var expected, actual,
- fired = false;
+ fired = false,
+ el = $("#selectable1");
- el = $("#selectable1");
el.selectable({
disabled: false,
start: function() { fired = true; }
test("autoRefresh", function() {
expect(3);
- el = $("#selectable1");
- var actual, sel = $("*", el), selected = function() { actual += 1; };
- actual = 0;
+ var actual = 0,
+ el = $("#selectable1"),
+ sel = $("*", el),
+ selected = function() { actual += 1; };
+
el = $("#selectable1").selectable({ autoRefresh: false, selected: selected });
sel.hide();
- TestHelpers.selectableDrag(1000, 1000);
+ TestHelpers.selectable.drag(el, 1000, 1000);
equal(actual, sel.length);
el.selectable("destroy");
sel.show();
el = $("#selectable1").selectable({ autoRefresh: true, selected: selected });
sel.hide();
- TestHelpers.selectableDrag(1000, 1000);
+ TestHelpers.selectable.drag(el, 1000, 1000);
equal(actual, 0);
sel.show();
- TestHelpers.selectableDrag(1000, 1000);
+ TestHelpers.selectable.drag(el, 1000, 1000);
equal(actual, sel.length);
el.selectable("destroy");
sel.show();
test("filter", function() {
expect(2);
- el = $("#selectable1");
- var actual, sel = $("*", el), selected = function() { actual += 1; };
- actual = 0;
+ var actual =0,
+ el = $("#selectable1"),
+ sel = $("*", el),
+ selected = function() { actual += 1; };
+
+
el = $("#selectable1").selectable({ filter: '.special', selected: selected });
- TestHelpers.selectableDrag(1000, 1000);
+ TestHelpers.selectable.drag(el, 1000, 1000);
ok(sel.length !== 1, "this test assumes more than 1 selectee");
equal(actual, 1);
el.selectable("destroy");
tolerance: 'touch'
},
_create: function() {
- var that = this;
+ var selectees,
+ that = this;
this.element.addClass("ui-selectable");
this.dragged = false;
// cache selectee children based on filter
- var selectees;
this.refresh = function() {
selectees = $(that.options.filter, that.element[0]);
selectees.addClass("ui-selectee");
selectees.each(function() {
- var $this = $(this);
- var pos = $this.offset();
+ var $this = $(this),
+ pos = $this.offset();
$.data(this, "selectable-item", {
element: this,
$element: $this,
},
_mouseStart: function(event) {
- var that = this;
+ var that = this,
+ options = this.options;
this.opos = [event.pageX, event.pageY];
- if (this.options.disabled)
+ if (this.options.disabled) {
return;
-
- var options = this.options;
+ }
this.selectees = $(options.filter, this.element[0]);
});
$(event.target).parents().andSelf().each(function() {
- var selectee = $.data(this, "selectable-item");
+ var doSelect,
+ selectee = $.data(this, "selectable-item");
if (selectee) {
- var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
+ doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
selectee.$element
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
},
_mouseDrag: function(event) {
- var that = this;
+
this.dragged = true;
- if (this.options.disabled)
+ if (this.options.disabled) {
return;
+ }
- var options = this.options;
+ var tmp,
+ that = this,
+ options = this.options,
+ x1 = this.opos[0],
+ y1 = this.opos[1],
+ x2 = event.pageX,
+ y2 = event.pageY;
- var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
- if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
- if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
+ if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
+ if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
this.selectees.each(function() {
- var selectee = $.data(this, "selectable-item");
+ var selectee = $.data(this, "selectable-item"),
+ hit = false;
+
//prevent helper from being selected if appendTo: selectable
- if (!selectee || selectee.element == that.element[0])
+ if (!selectee || selectee.element === that.element[0]) {
return;
- var hit = false;
- if (options.tolerance == 'touch') {
+ }
+
+ if (options.tolerance === 'touch') {
hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
- } else if (options.tolerance == 'fit') {
+ } else if (options.tolerance === 'fit') {
hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
}
this.dragged = false;
- var options = this.options;
-
$('.ui-unselecting', this.element[0]).each(function() {
var selectee = $.data(this, "selectable-item");
selectee.$element.removeClass('ui-unselecting');