File tree Expand file tree Collapse file tree 4 files changed +77
-10
lines changed Expand file tree Collapse file tree 4 files changed +77
-10
lines changed Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < meta http-equiv ="x-ua-compatible " content ="ie=edge ">
6
+ < title > Example two lists clone</ title >
7
+ < meta name ="description " content ="">
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
9
+
10
+ < link rel ="stylesheet " href ="css/main.css ">
11
+ </ head >
12
+ < body >
13
+
14
+ < div id ="main ">
15
+ < h1 > Vue Dragable For</ h1 >
16
+
17
+ < div class ="drag ">
18
+ < h2 > List 1 v-dragable-for</ h2 >
19
+ < div id ="list1 " class ="dragArea " >
20
+ < div v-dragable-for ="element in list1 " options ='{"group":{ "name":"people", "pull":"clone", "put":false }} ' track-by ="$index ">
21
+ {{element.name}}
22
+ </ div >
23
+ </ div >
24
+
25
+ < h2 > List 2 v-dragable-for</ h2 >
26
+ < div id ="list2 " class ="dragArea ">
27
+ < div v-dragable-for ="element in list2 " options ='{"group":"people"} ' track-by ="$index "> {{element.name}}</ div >
28
+ </ div >
29
+ </ div >
30
+
31
+ < div class ="normal ">
32
+ < h2 > List 1 v-for</ h2 >
33
+ < div >
34
+ < div v-for ="element in list1 " track-by ="$index "> {{element.name}}</ div >
35
+ </ div >
36
+
37
+ < h2 > List 2 v-for</ h2 >
38
+ < div >
39
+ < div v-for ="element in list2 " track-by ="$index "> {{element.name}}</ div >
40
+ </ div >
41
+ </ div >
42
+
43
+ < a href ="index.html "> See basic example</ a >
44
+ < a href ="complex.html "> See 2 lists example</ a >
45
+
46
+ < script type ="text/javascript " src ="..\libs\vue\dist\vue.js "> </ script >
47
+ < script type ="text/javascript " src ="..\libs\lodash\lodash.js "> </ script >
48
+ < script type ="text/javascript " src ="..\libs\Sortable\Sortable.js "> </ script >
49
+ < script type ="text/javascript " src ="src\vuedragablefor.js "> </ script >
50
+ < script type ="text/javascript " src ="script\complex.js "> </ script >
51
+
52
+ </ div >
53
+ </ body >
54
+ </ html >
Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="utf-8 ">
5
5
< meta http-equiv ="x-ua-compatible " content ="ie=edge ">
6
- < title > Example</ title >
6
+ < title > Example two lists </ title >
7
7
< meta name ="description " content ="">
8
8
< meta name ="viewport " content ="width=device-width, initial-scale=1 ">
9
9
@@ -17,9 +17,9 @@ <h1>Vue Dragable For</h1>
17
17
< div class ="drag ">
18
18
< h2 > List 1 v-dragable-for</ h2 >
19
19
< div class ="dragArea " >
20
- < template v-dragable-for ="element in list1 " options ='{"group":"people"} '>
21
- < p > {{element.name}}</ p >
22
- </ template >
20
+ < div v-dragable-for ="element in list1 " options ='{"group":"people"} '>
21
+ {{element.name}}
22
+ </ div >
23
23
</ div >
24
24
25
25
< h2 > List 2 v-dragable-for</ h2 >
@@ -31,16 +31,17 @@ <h2>List 2 v-dragable-for</h2>
31
31
< div class ="normal ">
32
32
< h2 > List 1 v-for</ h2 >
33
33
< div >
34
- < div v-for ="element in list1 " options =' {"group":"people"} ' > {{element.name}}</ div >
34
+ < div v-for ="element in list1 " > {{element.name}}</ div >
35
35
</ div >
36
36
37
37
< h2 > List 2 v-for</ h2 >
38
38
< div >
39
- < div v-for ="element in list2 " options =' {"group":"people"} ' > {{element.name}}</ div >
39
+ < div v-for ="element in list2 " > {{element.name}}</ div >
40
40
</ div >
41
41
</ div >
42
42
43
43
< a href ="index.html "> See basic example</ a >
44
+ < a href ="complex-clone.html "> See clone element example</ a >
44
45
45
46
< script type ="text/javascript " src ="..\libs\vue\dist\vue.js "> </ script >
46
47
< script type ="text/javascript " src ="..\libs\lodash\lodash.js "> </ script >
Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="utf-8 ">
5
5
< meta http-equiv ="x-ua-compatible " content ="ie=edge ">
6
- < title > Example </ title >
6
+ < title > Basic example </ title >
7
7
< meta name ="description " content ="">
8
8
< meta name ="viewport " content ="width=device-width, initial-scale=1 ">
9
9
@@ -34,6 +34,7 @@ <h2>Normal v-for</h2>
34
34
< br >
35
35
36
36
< a href ="complex.html "> See 2 lists example</ a >
37
+ < a href ="complex-clone.html "> See clone element example</ a >
37
38
38
39
< script type ="text/javascript " src ="..\libs\vue\dist\vue.js "> </ script >
39
40
< script type ="text/javascript " src ="..\libs\lodash\lodash.js "> </ script >
Original file line number Diff line number Diff line change 28
28
if ( ! ! collection )
29
29
collection . splice ( evt . newIndex , 0 , collection . splice ( evt . oldIndex , 1 ) [ 0 ] ) ;
30
30
} ,
31
- onAdd : function ( evt ) {
31
+ onAdd : function ( evt ) {
32
32
var directive = evt . from . __directive ;
33
33
if ( ( ! ! directive ) && ( ! ! ctx . collection ) )
34
34
ctx . collection . splice ( evt . newIndex , 0 , directive . collection [ evt . oldIndex ] ) ;
35
35
} ,
36
36
onRemove : function ( evt ) {
37
- if ( ! ! ctx . collection )
38
- ctx . collection . splice ( evt . oldIndex , 1 ) ;
37
+ var collection = ctx . collection ;
38
+ if ( ! ! collection && ! evt . clone )
39
+ collection . splice ( evt . oldIndex , 1 ) ;
40
+ if ( ! ! evt . clone ) {
41
+ //if cloning mode: replace cloned element by orginal element (with original vue binding information)+
42
+ //re-order element as sortablejs may re-order without sending events
43
+ var newIndex = Array . prototype . indexOf . call ( evt . from . children , evt . clone ) , oldIndex = evt . oldIndex ;
44
+ evt . from . replaceChild ( evt . item , evt . clone ) ;
45
+ if ( ! ! collection && ( newIndex != oldIndex ) ) {
46
+ var item = collection . splice ( oldIndex , 1 ) ;
47
+ collection . splice ( newIndex , 0 , item [ 0 ] ) ;
48
+ }
49
+ }
39
50
}
40
51
} ) ;
41
52
var parent = ( ! ! this . params . root ) ? document . getElementById ( this . params . root ) : this . el . parentElement ;
You can’t perform that action at this time.
0 commit comments