@@ -7,12 +7,14 @@ $(document).ready(function() {
7
7
8
8
$ ( ".choice" ) . on ( "dragstart" , function ( event ) {
9
9
$dragged = $ ( this ) ;
10
+ $parentDiv = $ ( this ) . parent ( ) ;
10
11
$dragged . addClass ( "on-drag" ) ;
11
12
} ) ;
12
13
13
14
$ ( ".choice" ) . on ( "dragend" , function ( event ) {
14
15
$ ( this ) . removeClass ( "on-drag" ) ;
15
16
$dragged = null ;
17
+ $parentDiv = null ;
16
18
} ) ;
17
19
18
20
$ ( ".choice-container" ) . on ( "dragover" , function ( event ) {
@@ -21,25 +23,30 @@ $(document).ready(function() {
21
23
22
24
// making choices
23
25
$ ( ".choice-container.empty" ) . on ( "drop" , function ( event ) {
24
- choicesMade += 1 ;
25
- event . preventDefault ( ) ;
26
- $ ( this ) . append ( $dragged ) ;
27
- $dragged . attr ( "ranking" , choicesMade ) ;
26
+ if ( $parentDiv . hasClass ( "full" ) ) {
27
+ choicesMade += 1 ;
28
+ }
29
+ event . preventDefault ( ) ;
30
+ $ ( this ) . append ( $dragged ) ;
31
+ $dragged . attr ( "ranking" , choicesMade ) ;
32
+
28
33
} ) ;
29
34
30
35
// undoing choices
31
36
$ ( ".choice-container.full" ) . on ( "drop" , function ( event ) {
32
- choicesMade -= 1 ;
33
- event . preventDefault ( ) ;
34
- $ ( this ) . append ( $dragged ) ;
35
- let undoRank = Number ( $dragged . attr ( "ranking" ) ) ;
36
- $dragged . attr ( "ranking" , 0 ) ;
37
- $ ( this ) . siblings ( ".choice-container.empty" ) . children ( ".choice" ) . each ( function ( ) {
38
- let oldRank = Number ( $ ( this ) . attr ( "ranking" ) ) ;
39
- if ( oldRank > undoRank ) {
40
- $ ( this ) . attr ( "ranking" , oldRank - 1 ) ;
41
- }
42
- } ) ;
37
+ if ( $parentDiv . hasClass ( "empty" ) ) {
38
+ choicesMade -= 1 ;
39
+ }
40
+ event . preventDefault ( ) ;
41
+ $ ( this ) . append ( $dragged ) ;
42
+ let undoRank = Number ( $dragged . attr ( "ranking" ) ) ;
43
+ $dragged . attr ( "ranking" , 0 ) ;
44
+ $ ( this ) . siblings ( ".choice-container.empty" ) . children ( ".choice" ) . each ( function ( ) {
45
+ let oldRank = Number ( $ ( this ) . attr ( "ranking" ) ) ;
46
+ if ( oldRank > undoRank ) {
47
+ $ ( this ) . attr ( "ranking" , oldRank - 1 ) ;
48
+ }
49
+ } ) ;
43
50
} ) ;
44
51
45
52
$ ( ".submit-ranks-btn" ) . on ( "click" , function ( event ) {
0 commit comments