@@ -34,7 +34,8 @@ define(function (require, exports, module) {
34
34
"use strict" ;
35
35
36
36
// Load dependent modules
37
- var DocumentManager = require ( "document/DocumentManager" ) ,
37
+ var AppInit = require ( "utils/AppInit" ) ,
38
+ DocumentManager = require ( "document/DocumentManager" ) ,
38
39
MainViewManager = require ( "view/MainViewManager" ) ,
39
40
CommandManager = require ( "command/CommandManager" ) ,
40
41
Commands = require ( "command/Commands" ) ,
@@ -69,6 +70,12 @@ define(function (require, exports, module) {
69
70
var _classProviders = [ ] ;
70
71
71
72
73
+ /**
74
+ * #working-set-list-container
75
+ * @type {jQuery }
76
+ */
77
+ var $workingFilesContainer ;
78
+
72
79
/**
73
80
* Constants for event.which values
74
81
* @enum {number}
@@ -97,6 +104,12 @@ define(function (require, exports, module) {
97
104
BELOWVIEW = "belowview" ,
98
105
ABOVEVIEW = "aboveview" ;
99
106
107
+ /**
108
+ * Drag an item has to move 3px before dragging starts
109
+ * @constant
110
+ */
111
+ var _DRAG_MOVE_DETECTION_START = 3 ;
112
+
100
113
/**
101
114
* Refreshes all Pane View List Views
102
115
*/
@@ -129,7 +142,6 @@ define(function (require, exports, module) {
129
142
*/
130
143
function _updateListItemSelection ( listItem , selectedFile ) {
131
144
var shouldBeSelected = ( selectedFile && $ ( listItem ) . data ( _FILE_KEY ) . fullPath === selectedFile . fullPath ) ;
132
-
133
145
ViewUtils . toggleClass ( $ ( listItem ) , "selected" , shouldBeSelected ) ;
134
146
}
135
147
@@ -263,19 +275,43 @@ define(function (require, exports, module) {
263
275
dragged = false ,
264
276
startPageY = e . pageY ,
265
277
lastPageY = startPageY ,
266
- itemHeight = $el . height ( ) ,
278
+ lastHit = { where : NOMANSLAND } ,
267
279
tryClosing = $ ( e . target ) . hasClass ( "can-close" ) ,
268
- offset = $el . offset ( ) ,
269
- $copy = $el . clone ( ) ,
270
- $ghost = $ ( "<div class='open-files-container wsv-drag-ghost' style='overflow: hidden; display: inline-block;'>" ) . append ( $ ( "<ul>" ) . append ( $copy ) . css ( "padding" , "0" ) ) ,
271
- sourceView = _viewFromEl ( $el ) ,
272
280
currentFile = MainViewManager . getCurrentlyViewedFile ( ) ,
273
281
activePaneId = MainViewManager . getActivePaneId ( ) ,
274
282
activeView = _views [ activePaneId ] ,
275
- draggingCurrentFile = ( $el . hasClass ( "selected" ) && sourceView . paneId === activePaneId ) ,
276
- startingIndex = MainViewManager . findInWorkingSet ( sourceView . paneId , sourceFile . fullPath ) ,
283
+ sourceView = _viewFromEl ( $el ) ,
277
284
currentView = sourceView ,
278
- lastHit = { where : NOMANSLAND } ;
285
+ startingIndex = $el . index ( ) ,
286
+ itemHeight ,
287
+ offset ,
288
+ $copy ,
289
+ $ghost ,
290
+ draggingCurrentFile ;
291
+
292
+ function initDragging ( ) {
293
+ itemHeight = $el . height ( ) ;
294
+ offset = $el . offset ( ) ;
295
+ $copy = $el . clone ( ) ;
296
+ $ghost = $ ( "<div class='open-files-container wsv-drag-ghost' style='overflow: hidden; display: inline-block;'>" ) . append ( $ ( "<ul>" ) . append ( $copy ) . css ( "padding" , "0" ) ) ;
297
+ draggingCurrentFile = ( $el . hasClass ( "selected" ) && sourceView . paneId === activePaneId ) ;
298
+
299
+ // setup our ghost element as position absolute
300
+ // so we can put it wherever we want to while dragging
301
+ if ( draggingCurrentFile && _hasSelectionFocus ( ) ) {
302
+ $ghost . addClass ( "dragging-current-file" ) ;
303
+ }
304
+
305
+ $ghost . css ( {
306
+ top : offset . top ,
307
+ left : offset . left ,
308
+ width : $el . width ( ) + 8
309
+ } ) ;
310
+
311
+ // this will give the element the appearence that it's ghosted if the user
312
+ // drags the element out of the view and goes off into no mans land
313
+ $ghost . appendTo ( $ ( "body" ) ) ;
314
+ }
279
315
280
316
// Switches the view context to match the hit context
281
317
function updateContext ( hit ) {
@@ -294,7 +330,6 @@ define(function (require, exports, module) {
294
330
hasScroller = false ,
295
331
onTopScroller = false ,
296
332
onBottomScroller = false ,
297
- $workingFilesContainer = $ ( "#working-set-list-container" ) ,
298
333
$container ,
299
334
$hit ,
300
335
$item ,
@@ -564,7 +599,7 @@ define(function (require, exports, module) {
564
599
// The drag function
565
600
function drag ( e ) {
566
601
if ( ! dragged ) {
567
-
602
+ initDragging ( ) ;
568
603
// sort redraw and scroll shadows
569
604
// cause problems during drag so disable them
570
605
_suppressSortRedrawForAllViews ( true ) ;
@@ -576,7 +611,7 @@ define(function (require, exports, module) {
576
611
_deactivateAllViews ( true ) ;
577
612
578
613
// add a "dragging" class to the outer container
579
- $ ( "#working-set-list-container" ) . addClass ( "dragging" ) ;
614
+ $workingFilesContainer . addClass ( "dragging" ) ;
580
615
581
616
// add a class to the element we're dragging if
582
617
// it's the currently selected file so that we
@@ -654,13 +689,15 @@ define(function (require, exports, module) {
654
689
}
655
690
}
656
691
657
- // move the drag affordance
658
- $ghost . css ( "top" , $ghost . offset ( ) . top + ( e . pageY - lastPageY ) ) ;
659
-
692
+ // Reposition the drag affordance if we've started dragging
693
+ if ( $ghost ) {
694
+ $ghost . css ( "top" , $ghost . offset ( ) . top + ( e . pageY - lastPageY ) ) ;
695
+ }
696
+
660
697
// if we have't started dragging yet then we wait until
661
698
// the mouse has moved 3 pixels before we start dragging
662
699
// to avoid the item moving when clicked or double clicked
663
- if ( dragged || Math . abs ( e . pageY - startPageY ) > 3 ) {
700
+ if ( dragged || Math . abs ( e . pageY - startPageY ) > _DRAG_MOVE_DETECTION_START ) {
664
701
drag ( e ) ;
665
702
}
666
703
@@ -681,19 +718,21 @@ define(function (require, exports, module) {
681
718
682
719
// Close down the drag operation
683
720
function preDropCleanup ( ) {
684
- $ ( "#working-set-list-container" ) . removeClass ( "dragging" ) ;
685
- $ ( "#working-set-list-container .drag-show-as-selected" ) . removeClass ( "drag-show-as-selected" ) ;
686
- endScroll ( $el ) ;
687
- // re-activate the views (adds the "active" class to the view that was previously active)
688
- _deactivateAllViews ( false ) ;
689
- // turn scroll wheel back on
690
721
window . onmousewheel = window . document . onmousewheel = null ;
691
722
$ ( window ) . off ( ".wsvdragging" ) ;
692
- $ghost . remove ( ) ;
693
- $el . css ( "opacity" , "" ) ;
723
+ if ( dragged ) {
724
+ $workingFilesContainer . removeClass ( "dragging" ) ;
725
+ $workingFilesContainer . find ( ".drag-show-as-selected" ) . removeClass ( "drag-show-as-selected" ) ;
726
+ endScroll ( $el ) ;
727
+ // re-activate the views (adds the "active" class to the view that was previously active)
728
+ _deactivateAllViews ( false ) ;
729
+ // turn scroll wheel back on
730
+ $ghost . remove ( ) ;
731
+ $el . css ( "opacity" , "" ) ;
694
732
695
- if ( dragged && $el . next ( ) . length === 0 ) {
696
- scrollCurrentViewToBottom ( ) ;
733
+ if ( $el . next ( ) . length === 0 ) {
734
+ scrollCurrentViewToBottom ( ) ;
735
+ }
697
736
}
698
737
}
699
738
@@ -800,21 +839,7 @@ define(function (require, exports, module) {
800
839
return ;
801
840
}
802
841
803
- // setup our ghost element as position absolute
804
- // so we can put it wherever we want to while dragging
805
- if ( draggingCurrentFile && _hasSelectionFocus ( ) ) {
806
- $ghost . addClass ( "dragging-current-file" ) ;
807
- }
808
842
809
- $ghost . css ( {
810
- top : offset . top ,
811
- left : offset . left ,
812
- width : $el . width ( ) + 8
813
- } ) ;
814
-
815
- // this will give the element the appearence that it's ghosted if the user
816
- // drags the element out of the view and goes off into no mans land
817
- $ghost . appendTo ( $ ( "body" ) ) ;
818
843
819
844
e . stopPropagation ( ) ;
820
845
} ) ;
@@ -1435,6 +1460,11 @@ define(function (require, exports, module) {
1435
1460
refresh ( true ) ;
1436
1461
}
1437
1462
1463
+ AppInit . htmlReady ( function ( ) {
1464
+ $workingFilesContainer = $ ( "#working-set-list-container" ) ;
1465
+ } ) ;
1466
+
1467
+
1438
1468
// Public API
1439
1469
exports . createWorkingSetViewForPane = createWorkingSetViewForPane ;
1440
1470
exports . refresh = refresh ;
0 commit comments