"Resizable": "resizable/resizable.html",
"Selectable": "selectable/selectable.html",
//"Slider": "slider/slider.html",
- //"Sortable": "sortable/sortable.html",
+ "Sortable": "sortable/sortable.html",
"Spinner": "spinner/spinner.html",
"Tabs": "tabs/tabs.html",
"Tooltip": "tooltip/tooltip.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|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
+ return !( /(all|all-active|index|test|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|sortable)\.js$/ ).test( file );
+ return !( /(mouse|datepicker)\.js$/ ).test( file );
}),
grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js"
"resizable/resizable.html",
"selectable/selectable.html",
//"slider/slider.html",
- //"sortable/sortable.html",
+ "sortable/sortable.html",
"spinner/spinner.html",
"tabs/tabs.html",
"tooltip/tooltip.html",
"resizable/resizable.html",
"selectable/selectable.html",
"slider/slider.html",
- //"sortable/sortable.html",
+ "sortable/sortable.html",
"spinner/spinner.html",
"tabs/tabs.html",
"tooltip/tooltip.html",
<script src="sortable_tickets.js"></script>
<script src="../swarminject.js"></script>
+ <style>
+ #sortable, #sortable2 {
+ position:relative;
+ top:0;
+ left:0;
+ padding: 0;
+ margin: 1px;
+ border-width: 0;
+ }
+ #sortable li{
+ padding: 0;
+ margin: 0;
+ border-width: 0;
+ height:19px;
+ }
+ </style>
</head>
<body>
cancel: "input,textarea,button,select,option",
connectWith: false,
containment: false,
+ create: null,
cursor: "auto",
cursorAt: false,
delay: 0,
(function($) {
-module("sortable: core");
+TestHelpers.sortable = {
+ sort: function(handle, dx, dy, index, msg) {
+ $(handle).simulate("drag", {
+ dx: dx || 0,
+ dy: dy || 0
+ });
+ equal($(handle).parent().children().index(handle), index, msg);
+ }
+};
-// this is here to make JSHint pass "unused", and we don't want to
-// remove the parameter for when we finally implement
-$.noop();
+module("sortable: core");
})(jQuery);
module("sortable: events");
test("start", function() {
+ expect( 7 );
var hash;
$("#sortable")
ok(hash, 'start event triggered');
ok(hash.helper, 'UI hash includes: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
- ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
+ // todo: see if these events should actually have sane values in them
+ ok('position' in hash, 'UI hash includes: position');
+ ok('offset' in hash, 'UI hash includes: offset');
+
});
test("sort", function() {
+ expect( 7 );
var hash;
$("#sortable")
ok(hash, 'sort event triggered');
ok(hash.helper, 'UI hash includes: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
+ ok(hash.position && ('top' in hash.position && 'left' in hash.position), 'UI hash includes: position');
ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
});
test("change", function() {
+ expect( 8 );
var hash;
$("#sortable")
$("#sortable")
.sortable({ change: function(e, ui) { hash = ui; } })
- .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 });
+ .find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 });
ok(hash, 'change event triggered');
ok(hash.helper, 'UI hash includes: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
+ ok(hash.position && ('top' in hash.position && 'left' in hash.position), 'UI hash includes: position');
ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
});
test("beforeStop", function() {
+ expect( 7 );
var hash;
$("#sortable")
ok(hash, 'beforeStop event triggered');
ok(hash.helper, 'UI hash includes: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
+ ok(hash.position && ('top' in hash.position && 'left' in hash.position), 'UI hash includes: position');
ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
});
test("stop", function() {
+ expect( 7 );
var hash;
$("#sortable")
ok(hash, 'stop event triggered');
ok(!hash.helper, 'UI should not include: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
+ ok(hash.position && ('top' in hash.position && 'left' in hash.position), 'UI hash includes: position');
ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
});
test("update", function() {
+ expect( 8 );
var hash;
$("#sortable")
$("#sortable")
.sortable({ update: function(e, ui) { hash = ui; } })
- .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 });
+ .find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 });
ok(hash, 'update event triggered');
ok(!hash.helper, 'UI hash should not include: helper');
ok(hash.placeholder, 'UI hash includes: placeholder');
- ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position');
+ ok(hash.position && ('top' in hash.position && 'left' in hash.position), 'UI hash includes: position');
ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset');
ok(hash.item, 'UI hash includes: item');
ok(!hash.sender, 'UI hash does not include: sender');
});
+/*
test("receive", function() {
ok(false, "missing test - untested code is broken code.");
});
test("deactivate", function() {
ok(false, "missing test - untested code is broken code.");
});
+*/
})(jQuery);
*/
(function($) {
-var el, offsetBefore, offsetAfter, dragged;
-
-function drag(handle, dx, dy) {
- offsetBefore = $(handle).offset();
- $(handle).simulate("drag", {
- dx: dx || 0,
- dy: dy || 0
- });
- dragged = { dx: dx, dy: dy };
- offsetAfter = $(handle).offset();
-}
-
-function sort(handle, dx, dy, index, msg) {
- drag(handle, dx, dy);
- equal($(handle).parent().children().index(handle), index, msg);
-}
-
module("sortable: methods");
test("init", function() {
- expect(6);
+ expect(5);
$("<div></div>").appendTo('body').sortable().remove();
ok(true, '.sortable() called on element');
$("<div></div>").sortable();
ok(true, '.sortable() called on disconnected DOMElement');
- $("<div></div>").sortable().sortable("foo");
- ok(true, 'arbitrary method called after init');
-
$("<div></div>").sortable().sortable("option", "foo");
ok(true, 'arbitrary option getter after init');
});
test("destroy", function() {
+ expect(4);
$("<div></div>").appendTo('body').sortable().sortable("destroy").remove();
ok(true, '.sortable("destroy") called on element');
$("<div></div>").sortable().sortable("destroy");
ok(true, '.sortable("destroy") called on disconnected DOMElement');
- $("<div></div>").sortable().sortable("destroy").sortable("foo");
- ok(true, 'arbitrary method called after destroy');
-
var expected = $('<div></div>').sortable(),
actual = expected.sortable('destroy');
equal(actual, expected, 'destroy is chainable');
expect(5);
el = $("#sortable").sortable({ disabled: true });
- sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, '.sortable({ disabled: true })');
el.sortable("enable");
equal(el.sortable("option", "disabled"), false, "disabled option getter");
el.sortable("option", "disabled", false);
equal(el.sortable("option", "disabled"), false, "disabled option setter");
- sort($("li", el)[0], 0, 40, 2, '.sortable("option", "disabled", false)');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, '.sortable("option", "disabled", false)');
var expected = $('<div></div>').sortable(),
actual = expected.sortable('enable');
test("disable", function() {
expect(7);
el = $("#sortable").sortable({ disabled: false });
- sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, '.sortable({ disabled: false })');
el.sortable("disable");
- sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, 'disabled.sortable getter');
el.sortable("destroy");
el.sortable({ disabled: false });
- sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, '.sortable({ disabled: false })');
el.sortable("option", "disabled", true);
equal(el.sortable("option", "disabled"), true, "disabled option setter");
ok(el.sortable("widget").is(":not(.ui-state-disabled)"), "sortable element does not get ui-state-disabled since it's an interaction");
- sort($("li", el)[0], 0, 40, 0, '.sortable("option", "disabled", true)');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, '.sortable("option", "disabled", true)');
var expected = $('<div></div>').sortable(),
actual = expected.sortable('disable');
// remove the parameter for when we finally implement
$.noop();
+/*
test("{ appendTo: 'parent' }, default", function() {
ok(false, "missing test - untested code is broken code.");
});
test("{ zIndex: false }", function() {
ok(false, "missing test - untested code is broken code.");
});
-
+*/
})(jQuery);
*/
(function($) {
-var el, offsetBefore, offsetAfter, dragged;
-
-function drag(handle, dx, dy) {
- offsetBefore = $(handle).offset();
- $(handle).simulate("drag", {
- dx: dx || 0,
- dy: dy || 0
- });
- dragged = { dx: dx, dy: dy };
- offsetAfter = $(handle).offset();
-}
-
-function sort(handle, dx, dy, index, msg) {
- drag(handle, dx, dy);
- equal($(handle).parent().children().index(handle), index, msg);
-}
-
module("sortable: tickets");
test("#3019: Stop fires too early", function() {
+ expect(2);
var helper = null;
el = $("#sortable").sortable({
}
});
- sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable');
+ TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, 'Dragging the sortable');
equal(helper, null, "helper should be false");
});
test('#4752: link event firing on sortable with connect list', function () {
+ expect( 10 );
+
var fired = {},
hasFired = function (type) { return (type in fired) && (true === fired[type]); };
$('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable');
- $('#main ul').sortable({
- connectWith: '#main ul',
+ $('#qunit-fixture ul').sortable({
+ connectWith: '#qunit-fixture ul',
change: function () {
fired.change = true;
},
}
});
- $('#main ul li').live('click.ui-sortable-test', function () {
+ $('#qunit-fixture ul').bind('click.ui-sortable-test', function () {
fired.click = true;
});
*/
(function( $, undefined ) {
+/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true, shadow: true, loopfunc: true */
$.widget("ui.sortable", $.ui.mouse, {
version: "@VERSION",
widgetEventPrefix: "sort",
this._mouseInit();
//We're ready to go
- this.ready = true
+ this.ready = true;
},
this._refreshItems(event);
//Find out if the clicked node (or one of its parents) is a actual item in this.items
- var currentItem = null, nodes = $(event.target).parents().each(function() {
+ var currentItem = null;
+
+ $(event.target).parents().each(function() {
if($.data(this, that.widgetName + '-item') == that) {
currentItem = $(this);
return false;
//Post 'activate' events to possible containers
if(!noActivation) {
- for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
+ for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
}
//Prepare possible droppables
var str = []; o = o || {};
$(items).each(function() {
- var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
+ var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[\-=_](.+)/));
if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
});
var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
- if( this.options.tolerance == "pointer"
+ if (this.options.tolerance == "pointer"
|| this.options.forcePointerForContainers
|| (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
) {
_getDragVerticalDirection: function() {
var delta = this.positionAbs.top - this.lastPositionAbs.top;
- return delta != 0 && (delta > 0 ? "down" : "up");
+ return delta !== 0 && (delta > 0 ? "down" : "up");
},
_getDragHorizontalDirection: function() {
var delta = this.positionAbs.left - this.lastPositionAbs.left;
- return delta != 0 && (delta > 0 ? "right" : "left");
+ return delta !== 0 && (delta > 0 ? "right" : "left");
},
refresh: function(event) {
if(inst && inst != this && !inst.options.disabled) {
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]);
}
- };
- };
+ }
+ }
}
queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]);
queries[i][0].each(function() {
items.push(this);
});
- };
+ }
return $(items);
for (var j=0; j < list.length; j++) {
if(list[j] == item.item[0])
return false;
- };
+ }
return true;
});
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
this.containers.push(inst);
}
- };
- };
+ }
+ }
}
for (var i = queries.length - 1; i >= 0; i--) {
width: 0, height: 0,
left: 0, top: 0
});
- };
- };
+ }
+ }
},
var p = t.offset();
item.left = p.left;
item.top = p.top;
- };
+ }
if(this.options.custom && this.options.custom.refreshContainers) {
this.options.custom.refreshContainers.call(this);
this.containers[i].containerCache.top = p.top;
this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
- };
+ }
}
return this;
if(className && !o.forcePlaceholderSize) return;
//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
- if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); };
- if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); };
+ if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); }
+ if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); }
}
};
}
if(helper[0] == this.currentItem[0])
this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") };
- if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width());
- if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height());
+ if(!helper[0].style.width || o.forceHelperSize) helper.width(this.currentItem.width());
+ if(!helper[0].style.height || o.forceHelperSize) helper.height(this.currentItem.height());
return helper;
if(!pos) pos = this.position;
var mod = d == "absolute" ? 1 : -1;
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+ var scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
return {
top: (
if(o.grid) {
var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
- pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
+ pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
- pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
+ pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
}
}
if(this.cancelHelperRemoval) {
if(!noPropagation) {
this._trigger("beforeStop", event, this._uiHash());
- for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
+ for (var i=0; i < delayedTriggers.length; i++) {
+ delayedTriggers[i].call(this, event);
+ } //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}
if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
if(!noPropagation) {
- for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
+ for (var i=0; i < delayedTriggers.length; i++) {
+ delayedTriggers[i].call(this, event);
+ } //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}