Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Draggable: fix current JSCS violations.
  • Loading branch information
mikesherov committed Feb 18, 2014
commit 7017805745873e61b32769354a13dc697cdf3ae0
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 20 additions & 20 deletions tests/unit/draggable/draggable_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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 {
Expand All @@ -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 ) {
Expand All @@ -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 {
Expand Down Expand Up @@ -672,7 +672,7 @@ test( "helper, default, switching after initialization", function() {
});

/* jshint loopfunc: true */
(function(){
(function() {
var k, l, m,
scrollElements = {
"no elements": [],
Expand All @@ -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 );

Expand Down
26 changes: 18 additions & 8 deletions tests/unit/draggable/draggable_test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
})(),
Expand All @@ -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 );
Expand Down Expand Up @@ -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 });
},
Expand Down Expand Up @@ -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" );

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