mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dev: Standardized the selectable test suite. Fixed #8752 - Dev: Get selectable test suite to pass
This commit is contained in:
parent
f0daa220d6
commit
b49e071d39
@ -22,7 +22,7 @@ var versions = {
|
|||||||
"Position": "position/position.html",
|
"Position": "position/position.html",
|
||||||
"Progressbar": "progressbar/progressbar.html",
|
"Progressbar": "progressbar/progressbar.html",
|
||||||
//"Resizable": "resizable/resizable.html",
|
//"Resizable": "resizable/resizable.html",
|
||||||
//"Selectable": "selectable/selectable.html",
|
"Selectable": "selectable/selectable.html",
|
||||||
//"Slider": "slider/slider.html",
|
//"Slider": "slider/slider.html",
|
||||||
//"Sortable": "sortable/sortable.html",
|
//"Sortable": "sortable/sortable.html",
|
||||||
"Spinner": "spinner/spinner.html",
|
"Spinner": "spinner/spinner.html",
|
||||||
|
4
grunt.js
4
grunt.js
@ -281,13 +281,13 @@ grunt.initConfig({
|
|||||||
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
|
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
|
||||||
// disabling everything that doesn't (quite) work with PhantomJS for now
|
// disabling everything that doesn't (quite) work with PhantomJS for now
|
||||||
// TODO except for all|index|test, try to include more as we go
|
// 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: {
|
lint: {
|
||||||
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
|
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
|
||||||
// TODO remove items from this list once rewritten
|
// 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" ],
|
grunt: [ "grunt.js", "build/**/*.js" ],
|
||||||
tests: "tests/unit/**/*.js"
|
tests: "tests/unit/**/*.js"
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
"position/position.html",
|
"position/position.html",
|
||||||
"progressbar/progressbar.html",
|
"progressbar/progressbar.html",
|
||||||
//"resizable/resizable.html",
|
//"resizable/resizable.html",
|
||||||
//"selectable/selectable.html",
|
"selectable/selectable.html",
|
||||||
//"slider/slider.html",
|
//"slider/slider.html",
|
||||||
//"sortable/sortable.html",
|
//"sortable/sortable.html",
|
||||||
"spinner/spinner.html",
|
"spinner/spinner.html",
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
"position/position.html",
|
"position/position.html",
|
||||||
"progressbar/progressbar.html",
|
"progressbar/progressbar.html",
|
||||||
//"resizable/resizable.html",
|
//"resizable/resizable.html",
|
||||||
//"selectable/selectable.html",
|
"selectable/selectable.html",
|
||||||
"slider/slider.html",
|
"slider/slider.html",
|
||||||
//"sortable/sortable.html",
|
//"sortable/sortable.html",
|
||||||
"spinner/spinner.html",
|
"spinner/spinner.html",
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests('selectable', {
|
|||||||
appendTo: 'body',
|
appendTo: 'body',
|
||||||
autoRefresh: true,
|
autoRefresh: true,
|
||||||
cancel: 'input,textarea,button,select,option',
|
cancel: 'input,textarea,button,select,option',
|
||||||
|
create: null,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
|
@ -2,15 +2,15 @@
|
|||||||
* selectable_core.js
|
* selectable_core.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var el;
|
TestHelpers.selectable = {
|
||||||
|
drag: function drag(el, dx, dy) {
|
||||||
TestHelpers.selectableDrag = function drag(dx, dy) {
|
var off = el.offset(),
|
||||||
var off = el.offset(), pos = { clientX: off.left, clientY: off.top };
|
pos = { clientX: off.left, clientY: off.top };
|
||||||
el.simulate("mousedown", pos);
|
el.simulate("mousedown", pos);
|
||||||
$(document).simulate("mousemove", pos);
|
$(document).simulate("mousemove", pos);
|
||||||
pos.clientX += dx;
|
pos.clientX += dx;
|
||||||
pos.clientY += dy;
|
pos.clientY += dy;
|
||||||
$(document).simulate("mousemove", pos);
|
$(document).simulate("mousemove", pos);
|
||||||
$(document).simulate("mouseup", pos);
|
$(document).simulate("mouseup", pos);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ module("selectable: events");
|
|||||||
|
|
||||||
test("start", function() {
|
test("start", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
el = $("#selectable1");
|
var el = $("#selectable1");
|
||||||
el.selectable({
|
el.selectable({
|
||||||
start: function() {
|
start: function() {
|
||||||
ok(true, "drag fired start callback");
|
ok(true, "drag fired start callback");
|
||||||
@ -19,7 +19,7 @@ test("start", function() {
|
|||||||
|
|
||||||
test("stop", function() {
|
test("stop", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
el = $("#selectable1");
|
var el = $("#selectable1");
|
||||||
el.selectable({
|
el.selectable({
|
||||||
start: function() {
|
start: function() {
|
||||||
ok(true, "drag fired stop callback");
|
ok(true, "drag fired stop callback");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
module("selectable: methods");
|
module("selectable: methods");
|
||||||
|
|
||||||
test("init", function() {
|
test("init", function() {
|
||||||
expect(6);
|
expect( 5 );
|
||||||
|
|
||||||
$("<div></div>").appendTo('body').selectable().remove();
|
$("<div></div>").appendTo('body').selectable().remove();
|
||||||
ok(true, '.selectable() called on element');
|
ok(true, '.selectable() called on element');
|
||||||
@ -17,10 +17,7 @@ test("init", function() {
|
|||||||
$("<div></div>").selectable().remove();
|
$("<div></div>").selectable().remove();
|
||||||
ok(true, '.selectable() called on disconnected DOMElement');
|
ok(true, '.selectable() called on disconnected DOMElement');
|
||||||
|
|
||||||
$("<div></div>").selectable().selectable("foo").remove();
|
var el = $("<div></div>").selectable();
|
||||||
ok(true, 'arbitrary method called after init');
|
|
||||||
|
|
||||||
el = $("<div></div>").selectable();
|
|
||||||
el.selectable("option", "foo");
|
el.selectable("option", "foo");
|
||||||
el.remove();
|
el.remove();
|
||||||
ok(true, 'arbitrary option getter after init');
|
ok(true, 'arbitrary option getter after init');
|
||||||
@ -30,6 +27,8 @@ test("init", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("destroy", function() {
|
test("destroy", function() {
|
||||||
|
expect( 4 );
|
||||||
|
|
||||||
$("<div></div>").appendTo('body').selectable().selectable("destroy").remove();
|
$("<div></div>").appendTo('body').selectable().selectable("destroy").remove();
|
||||||
ok(true, '.selectable("destroy") called on element');
|
ok(true, '.selectable("destroy") called on element');
|
||||||
|
|
||||||
@ -39,9 +38,6 @@ test("destroy", function() {
|
|||||||
$("<div></div>").selectable().selectable("destroy").remove();
|
$("<div></div>").selectable().selectable("destroy").remove();
|
||||||
ok(true, '.selectable("destroy") called on disconnected DOMElement');
|
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(),
|
var expected = $('<div></div>').selectable(),
|
||||||
actual = expected.selectable('destroy');
|
actual = expected.selectable('destroy');
|
||||||
equal(actual, expected, 'destroy is chainable');
|
equal(actual, expected, 'destroy is chainable');
|
||||||
@ -50,9 +46,9 @@ test("destroy", function() {
|
|||||||
test("enable", function() {
|
test("enable", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
var expected, actual,
|
var expected, actual,
|
||||||
fired = false;
|
fired = false,
|
||||||
|
el = $("#selectable1");
|
||||||
|
|
||||||
el = $("#selectable1");
|
|
||||||
el.selectable({
|
el.selectable({
|
||||||
disabled: true,
|
disabled: true,
|
||||||
start: function() { fired = true; }
|
start: function() { fired = true; }
|
||||||
@ -72,9 +68,9 @@ test("enable", function() {
|
|||||||
test("disable", function() {
|
test("disable", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
var expected, actual,
|
var expected, actual,
|
||||||
fired = false;
|
fired = false,
|
||||||
|
el = $("#selectable1");
|
||||||
|
|
||||||
el = $("#selectable1");
|
|
||||||
el.selectable({
|
el.selectable({
|
||||||
disabled: false,
|
disabled: false,
|
||||||
start: function() { fired = true; }
|
start: function() { fired = true; }
|
||||||
|
@ -7,13 +7,15 @@ module("selectable: options");
|
|||||||
|
|
||||||
test("autoRefresh", function() {
|
test("autoRefresh", function() {
|
||||||
expect(3);
|
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 });
|
el = $("#selectable1").selectable({ autoRefresh: false, selected: selected });
|
||||||
sel.hide();
|
sel.hide();
|
||||||
TestHelpers.selectableDrag(1000, 1000);
|
TestHelpers.selectable.drag(el, 1000, 1000);
|
||||||
equal(actual, sel.length);
|
equal(actual, sel.length);
|
||||||
el.selectable("destroy");
|
el.selectable("destroy");
|
||||||
|
|
||||||
@ -21,10 +23,10 @@ test("autoRefresh", function() {
|
|||||||
sel.show();
|
sel.show();
|
||||||
el = $("#selectable1").selectable({ autoRefresh: true, selected: selected });
|
el = $("#selectable1").selectable({ autoRefresh: true, selected: selected });
|
||||||
sel.hide();
|
sel.hide();
|
||||||
TestHelpers.selectableDrag(1000, 1000);
|
TestHelpers.selectable.drag(el, 1000, 1000);
|
||||||
equal(actual, 0);
|
equal(actual, 0);
|
||||||
sel.show();
|
sel.show();
|
||||||
TestHelpers.selectableDrag(1000, 1000);
|
TestHelpers.selectable.drag(el, 1000, 1000);
|
||||||
equal(actual, sel.length);
|
equal(actual, sel.length);
|
||||||
el.selectable("destroy");
|
el.selectable("destroy");
|
||||||
sel.show();
|
sel.show();
|
||||||
@ -32,12 +34,15 @@ test("autoRefresh", function() {
|
|||||||
|
|
||||||
test("filter", function() {
|
test("filter", function() {
|
||||||
expect(2);
|
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 });
|
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");
|
ok(sel.length !== 1, "this test assumes more than 1 selectee");
|
||||||
equal(actual, 1);
|
equal(actual, 1);
|
||||||
el.selectable("destroy");
|
el.selectable("destroy");
|
||||||
|
54
ui/jquery.ui.selectable.js
vendored
54
ui/jquery.ui.selectable.js
vendored
@ -25,20 +25,20 @@ $.widget("ui.selectable", $.ui.mouse, {
|
|||||||
tolerance: 'touch'
|
tolerance: 'touch'
|
||||||
},
|
},
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var that = this;
|
var selectees,
|
||||||
|
that = this;
|
||||||
|
|
||||||
this.element.addClass("ui-selectable");
|
this.element.addClass("ui-selectable");
|
||||||
|
|
||||||
this.dragged = false;
|
this.dragged = false;
|
||||||
|
|
||||||
// cache selectee children based on filter
|
// cache selectee children based on filter
|
||||||
var selectees;
|
|
||||||
this.refresh = function() {
|
this.refresh = function() {
|
||||||
selectees = $(that.options.filter, that.element[0]);
|
selectees = $(that.options.filter, that.element[0]);
|
||||||
selectees.addClass("ui-selectee");
|
selectees.addClass("ui-selectee");
|
||||||
selectees.each(function() {
|
selectees.each(function() {
|
||||||
var $this = $(this);
|
var $this = $(this),
|
||||||
var pos = $this.offset();
|
pos = $this.offset();
|
||||||
$.data(this, "selectable-item", {
|
$.data(this, "selectable-item", {
|
||||||
element: this,
|
element: this,
|
||||||
$element: $this,
|
$element: $this,
|
||||||
@ -72,14 +72,14 @@ $.widget("ui.selectable", $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_mouseStart: function(event) {
|
_mouseStart: function(event) {
|
||||||
var that = this;
|
var that = this,
|
||||||
|
options = this.options;
|
||||||
|
|
||||||
this.opos = [event.pageX, event.pageY];
|
this.opos = [event.pageX, event.pageY];
|
||||||
|
|
||||||
if (this.options.disabled)
|
if (this.options.disabled) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
var options = this.options;
|
|
||||||
|
|
||||||
this.selectees = $(options.filter, this.element[0]);
|
this.selectees = $(options.filter, this.element[0]);
|
||||||
|
|
||||||
@ -114,9 +114,10 @@ $.widget("ui.selectable", $.ui.mouse, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(event.target).parents().andSelf().each(function() {
|
$(event.target).parents().andSelf().each(function() {
|
||||||
var selectee = $.data(this, "selectable-item");
|
var doSelect,
|
||||||
|
selectee = $.data(this, "selectable-item");
|
||||||
if (selectee) {
|
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
|
selectee.$element
|
||||||
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
|
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
|
||||||
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
|
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
|
||||||
@ -140,28 +141,37 @@ $.widget("ui.selectable", $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_mouseDrag: function(event) {
|
_mouseDrag: function(event) {
|
||||||
var that = this;
|
|
||||||
this.dragged = true;
|
this.dragged = true;
|
||||||
|
|
||||||
if (this.options.disabled)
|
if (this.options.disabled) {
|
||||||
return;
|
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) { tmp = x2; x2 = x1; x1 = tmp; }
|
||||||
if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
|
if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
|
||||||
if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
|
|
||||||
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
|
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
|
||||||
|
|
||||||
this.selectees.each(function() {
|
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
|
//prevent helper from being selected if appendTo: selectable
|
||||||
if (!selectee || selectee.element == that.element[0])
|
if (!selectee || selectee.element === that.element[0]) {
|
||||||
return;
|
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) );
|
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);
|
hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,8 +238,6 @@ $.widget("ui.selectable", $.ui.mouse, {
|
|||||||
|
|
||||||
this.dragged = false;
|
this.dragged = false;
|
||||||
|
|
||||||
var options = this.options;
|
|
||||||
|
|
||||||
$('.ui-unselecting', this.element[0]).each(function() {
|
$('.ui-unselecting', this.element[0]).each(function() {
|
||||||
var selectee = $.data(this, "selectable-item");
|
var selectee = $.data(this, "selectable-item");
|
||||||
selectee.$element.removeClass('ui-unselecting');
|
selectee.$element.removeClass('ui-unselecting');
|
||||||
|
Loading…
Reference in New Issue
Block a user