Skip to content
Permalink
Browse files

Draggable: fix current JSCS violations.

  • Loading branch information
mikesherov committed Feb 18, 2014
1 parent 39ef4af commit 7017805745873e61b32769354a13dc697cdf3ae0
Showing with 108 additions and 101 deletions.
  1. +1 −1 Gruntfile.js
  2. +20 −20 tests/unit/draggable/draggable_options.js
  3. +18 −8 tests/unit/draggable/draggable_test_helpers.js
  4. +69 −72 ui/draggable.js
@@ -157,7 +157,7 @@ grunt.initConfig({
},
jscs: {
// datepicker, sortable, resizable and draggable are getting rewritten, ignore until that's done
ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js", "!ui/resizable.js", "!ui/draggable.js" ],
ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js", "!ui/resizable.js" ],
// TODO enable this once we have a tool that can help with fixing formatting of existing files
// tests: "tests/unit/**/*.js",
grunt: "Gruntfile.js"
@@ -85,7 +85,7 @@ test( "{ appendTo: Selector }", function() {
test( "appendTo, default, switching after initialization", function() {
expect( 2 );

var element = $( "#draggable1" ).draggable({ helper : "clone" });
var element = $( "#draggable1" ).draggable({ helper: "clone" });

TestHelpers.draggable.trackAppendedParent( element );

@@ -140,7 +140,7 @@ test( "{ axis: ? }, unexpected", function() {
test( "axis, default, switching after initialization", function() {
expect( 6 );

var element = $( "#draggable1" ).draggable({ axis : false });
var element = $( "#draggable1" ).draggable({ axis: false });

// Any Direction
TestHelpers.draggable.shouldMove( element, "axis: default" );
@@ -504,23 +504,23 @@ test( "cursorAt", function() {
var deltaX = -3,
deltaY = -3,
tests = {
"false": { cursorAt : false },
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
"[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } },
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
"false": { cursorAt: false },
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
};

$.each( tests, function( testName, testData ) {
$.each( [ "relative", "absolute" ], function( i, position ) {
var element = $( "#draggable" + ( i + 1 ) ).draggable({
cursorAt: testData.cursorAt,
drag: function( event, ui ) {
if( !testData.cursorAt ) {
if ( !testData.cursorAt ) {
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
} else if( testData.cursorAt.right ) {
} else if ( testData.cursorAt.right ) {
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
} else {
@@ -545,12 +545,12 @@ test( "cursorAt, switching after initialization", function() {
var deltaX = -3,
deltaY = -3,
tests = {
"false": { cursorAt : false },
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
"[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } },
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
"false": { cursorAt: false },
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
};

$.each( tests, function( testName, testData ) {
@@ -559,10 +559,10 @@ test( "cursorAt, switching after initialization", function() {

element.draggable({
drag: function( event, ui ) {
if( !testData.cursorAt ) {
if ( !testData.cursorAt ) {
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
} else if( testData.cursorAt.right ) {
} else if ( testData.cursorAt.right ) {
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
} else {
@@ -672,7 +672,7 @@ test( "helper, default, switching after initialization", function() {
});

/* jshint loopfunc: true */
(function(){
(function() {
var k, l, m,
scrollElements = {
"no elements": [],
@@ -689,7 +689,7 @@ test( "helper, default, switching after initialization", function() {
for ( m = 0 ; m < helpers.length; m++ ) {
for ( l = 0; l < positions.length; l++ ) {
for ( k in scrollElements ) {
(function( position, helper, scrollElements, scrollElementsTitle ){
(function( position, helper, scrollElements, scrollElementsTitle ) {
test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() {
expect( scrollPositions.length * 2 );

@@ -2,7 +2,7 @@ TestHelpers.draggable = {
// TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
unreliableContains: (function(){
unreliableContains: (function() {
var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(),
@@ -12,17 +12,27 @@ TestHelpers.draggable = {
$( el ).one( "dragstop", function( event, ui ) {
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
} );
});
},
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";

var offsetBefore = el.offset(),
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };

$( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
});
},
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";

var offsetBefore = el.offset(),
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };

$( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
} );
});
},
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
TestHelpers.draggable.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
@@ -55,14 +65,14 @@ TestHelpers.draggable = {
handle = handle || el;
$( el ).bind( "dragstop", function() {
ok( false, "should not drag " + msg );
} );
});
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
});
$( el ).unbind( "dragstop" );
},
setScrollable: function ( what, isScrollable ) {
setScrollable: function( what, isScrollable ) {
var overflow = isScrollable ? "scroll" : "hidden";
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow });
},
@@ -90,12 +100,12 @@ TestHelpers.draggable = {
dy: y
});
},
trackMouseCss : function( el ) {
trackMouseCss: function( el ) {
el.bind( "drag", function() {
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
});
},
trackAppendedParent : function( el ) {
trackAppendedParent: function( el ) {
// TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" );

@@ -104,4 +114,4 @@ TestHelpers.draggable = {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
});
}
};
};

0 comments on commit 7017805

Please sign in to comment.
You can’t perform that action at this time.