Skip to content

Commit 8b5361b

Browse files
author
pc-david\david.desmaisons
committed
Including complex example
1 parent 236c002 commit 8b5361b

File tree

5 files changed

+95
-8
lines changed

5 files changed

+95
-8
lines changed

examples/complex.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
10+
<!-- Place favicon.ico in the root directory -->
11+
12+
<link rel="stylesheet" href="css/main.css">
13+
</head>
14+
<body>
15+
16+
<div id="main">
17+
<h1>Vue Dragable For</h1>
18+
19+
<a href="index.html">See basic example</a>
20+
21+
<h2>Dragable list 1</h2>
22+
<div>
23+
<div v-dragable-for="element in list1" options='{"group":"people"}'>{{element.name}}</div>
24+
</div>
25+
26+
<h2>Dragable list 2</h2>
27+
<div>
28+
<div v-dragable-for="element in list2" options='{"group":"people"}'>{{element.name}}</div>
29+
</div>
30+
31+
<button @click="add">Add</button>
32+
<button @click="replace">Replace</button>
33+
34+
<script type="text/javascript" src="..\libs\vue\dist\vue.js"></script>
35+
<script type="text/javascript" src="..\libs\lodash\lodash.js"></script>
36+
<script type="text/javascript" src="..\libs\Sortable\Sortable.js"></script>
37+
<script type="text/javascript" src="src\vuedragablefor.js"></script>
38+
<script type="text/javascript" src="script\complex.js"></script>
39+
40+
</div>
41+
</body>
42+
</html>

examples/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
<div id="main">
1717
<h1>Vue Dragable For</h1>
18+
19+
<a href="complex.html">See other example</a>
1820

1921
<h2>Dragable</h2>
2022
<div>

examples/script/complex.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var vm = new Vue({
2+
el: "#main",
3+
data: {
4+
list1:[{name:"John"},
5+
{name:"Joao"},
6+
{name:"Jean"} ],
7+
list2:[{name:"Juan"},
8+
{name:"Edgard"},
9+
{name:"Johnson"} ]
10+
},
11+
methods:{
12+
add: function(){
13+
this.list.push({name:'Juan'});
14+
},
15+
replace: function(){
16+
this.list=[{name:'Edgard'}]
17+
}
18+
}
19+
});

examples/src/vuedragablefor.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@
1717
mix(dragableForDirective, {
1818
bind : function () {
1919
var ctx = this;
20-
var option ={
21-
onEnd: function (evt) {
20+
var options = this.params.options;
21+
if (typeof options === "string")
22+
options = JSON.parse(options);
23+
console.log(options);
24+
options = _.merge(options,{
25+
onUpdate: function (evt) {
2226
console.log(evt.oldIndex, evt.newIndex);
2327
var collection = ctx.collection;
2428
if (!!collection)
2529
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
30+
},
31+
onAdd: function (evt) {
32+
var itemEl = evt.item; // dragged HTMLElement
33+
evt.from; // previous list
34+
},
35+
onRemove: function (evt) {
2636
}
27-
};
28-
this.sortable = new Sortable(this.el.parentElement, option);
37+
});
38+
console.log(options);
39+
//var option =
40+
this.sortable = new Sortable(this.el.parentElement, options);
2941
},
3042
update : function (value){
3143

src/vuedragablefor.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@
1717
mix(dragableForDirective, {
1818
bind : function () {
1919
var ctx = this;
20-
var option ={
21-
onEnd: function (evt) {
20+
var options = this.params.options;
21+
if (typeof options === "string")
22+
options = JSON.parse(options);
23+
console.log(options);
24+
options = _.merge(options,{
25+
onUpdate: function (evt) {
2226
console.log(evt.oldIndex, evt.newIndex);
2327
var collection = ctx.collection;
2428
if (!!collection)
2529
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
30+
},
31+
onAdd: function (evt) {
32+
var itemEl = evt.item; // dragged HTMLElement
33+
evt.from; // previous list
34+
},
35+
onRemove: function (evt) {
2636
}
27-
};
28-
this.sortable = new Sortable(this.el.parentElement, option);
37+
});
38+
console.log(options);
39+
//var option =
40+
this.sortable = new Sortable(this.el.parentElement, options);
2941
},
3042
update : function (value){
3143

0 commit comments

Comments
 (0)