Skip to content

Commit 7017805

Browse files
committed
Draggable: fix current JSCS violations.
1 parent 39ef4af commit 7017805

File tree

4 files changed

+108
-101
lines changed

4 files changed

+108
-101
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ grunt.initConfig({
157157
},
158158
jscs: {
159159
// datepicker, sortable, resizable and draggable are getting rewritten, ignore until that's done
160-
ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js", "!ui/resizable.js", "!ui/draggable.js" ],
160+
ui: [ "ui/*.js", "!ui/datepicker.js", "!ui/sortable.js", "!ui/resizable.js" ],
161161
// TODO enable this once we have a tool that can help with fixing formatting of existing files
162162
// tests: "tests/unit/**/*.js",
163163
grunt: "Gruntfile.js"

tests/unit/draggable/draggable_options.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test( "{ appendTo: Selector }", function() {
8585
test( "appendTo, default, switching after initialization", function() {
8686
expect( 2 );
8787

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

9090
TestHelpers.draggable.trackAppendedParent( element );
9191

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

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

145145
// Any Direction
146146
TestHelpers.draggable.shouldMove( element, "axis: default" );
@@ -504,23 +504,23 @@ test( "cursorAt", function() {
504504
var deltaX = -3,
505505
deltaY = -3,
506506
tests = {
507-
"false": { cursorAt : false },
508-
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
509-
"[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
510-
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
511-
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } },
512-
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
507+
"false": { cursorAt: false },
508+
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
509+
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
510+
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
511+
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
512+
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
513513
};
514514

515515
$.each( tests, function( testName, testData ) {
516516
$.each( [ "relative", "absolute" ], function( i, position ) {
517517
var element = $( "#draggable" + ( i + 1 ) ).draggable({
518518
cursorAt: testData.cursorAt,
519519
drag: function( event, ui ) {
520-
if( !testData.cursorAt ) {
520+
if ( !testData.cursorAt ) {
521521
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
522522
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
523-
} else if( testData.cursorAt.right ) {
523+
} else if ( testData.cursorAt.right ) {
524524
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
525525
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
526526
} else {
@@ -545,12 +545,12 @@ test( "cursorAt, switching after initialization", function() {
545545
var deltaX = -3,
546546
deltaY = -3,
547547
tests = {
548-
"false": { cursorAt : false },
549-
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
550-
"[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
551-
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
552-
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } },
553-
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
548+
"false": { cursorAt: false },
549+
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
550+
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
551+
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
552+
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
553+
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
554554
};
555555

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

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

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

tests/unit/draggable/draggable_test_helpers.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TestHelpers.draggable = {
22
// TODO: remove the unreliable offset hacks
33
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
44
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
5-
unreliableContains: (function(){
5+
unreliableContains: (function() {
66
var element = $( "<div>" );
77
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
88
})(),
@@ -12,17 +12,27 @@ TestHelpers.draggable = {
1212
$( el ).one( "dragstop", function( event, ui ) {
1313
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
1414
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
15-
} );
15+
});
1616
},
1717
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
1818
msg = msg ? msg + "." : "";
1919

20+
var offsetBefore = el.offset(),
21+
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
22+
23+
$( el ).one( "dragstop", function( event, ui ) {
24+
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
25+
});
26+
},
27+
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
28+
msg = msg ? msg + "." : "";
29+
2030
var offsetBefore = el.offset(),
2131
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
2232

2333
$( el ).one( "dragstop", function( event, ui ) {
2434
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
25-
} );
35+
});
2636
},
2737
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
2838
TestHelpers.draggable.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
@@ -55,14 +65,14 @@ TestHelpers.draggable = {
5565
handle = handle || el;
5666
$( el ).bind( "dragstop", function() {
5767
ok( false, "should not drag " + msg );
58-
} );
68+
});
5969
$( handle ).simulate( "drag", {
6070
dx: 100,
6171
dy: 100
6272
});
6373
$( el ).unbind( "dragstop" );
6474
},
65-
setScrollable: function ( what, isScrollable ) {
75+
setScrollable: function( what, isScrollable ) {
6676
var overflow = isScrollable ? "scroll" : "hidden";
6777
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow });
6878
},
@@ -90,12 +100,12 @@ TestHelpers.draggable = {
90100
dy: y
91101
});
92102
},
93-
trackMouseCss : function( el ) {
103+
trackMouseCss: function( el ) {
94104
el.bind( "drag", function() {
95105
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
96106
});
97107
},
98-
trackAppendedParent : function( el ) {
108+
trackAppendedParent: function( el ) {
99109
// TODO: appendTo is currently ignored if helper is original (see #7044)
100110
el.draggable( "option", "helper", "clone" );
101111

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

0 commit comments

Comments
 (0)