Skip to content

Commit 48f69f1

Browse files
author
pc-david\david.desmaisons
committed
Definitive fix issue # 33
1 parent a1244e8 commit 48f69f1

File tree

6 files changed

+53
-44
lines changed

6 files changed

+53
-44
lines changed

dist/vuedraggable.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
6262
};
6363
}
6464

65+
var eventsListened = ['Start', 'Add', 'Remove', 'Update', 'End'];
66+
var eventsToEmit = ['Choose', 'Sort', 'Filter', 'Move', 'Clone'];
67+
var readonlyProperties = eventsListened.concat(eventsToEmit).map(function (evt) {
68+
return 'on' + evt;
69+
});
70+
6571
var props = {
6672
options: Object,
6773
list: {
@@ -99,7 +105,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
99105
return h(this.element, null, this.$slots.default);
100106
},
101107
mounted: function mounted() {
102-
this._sortable = new Sortable(this.rootContainer, this.computedOptions);
108+
var _this2 = this;
109+
110+
var optionsAdded = {};
111+
eventsListened.forEach(function (elt) {
112+
optionsAdded['on' + elt] = delegateAndEmit.call(_this2, elt);
113+
});
114+
115+
eventsToEmit.forEach(function (elt) {
116+
optionsAdded['on' + elt] = emit.bind(_this2, elt);
117+
});
118+
119+
var options = merge(this.options, optionsAdded);
120+
this._sortable = new Sortable(this.rootContainer, options);
103121
this.computeIndexes();
104122
},
105123
beforeDestroy: function beforeDestroy() {
@@ -113,26 +131,16 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
113131
computed: {
114132
rootContainer: function rootContainer() {
115133
return this.transitionMode ? this.$el.children[0] : this.$el;
116-
},
117-
computedOptions: function computedOptions() {
118-
var _this2 = this;
119-
120-
var optionsAdded = {};
121-
['Start', 'Add', 'Remove', 'Update', 'End'].forEach(function (elt) {
122-
optionsAdded['on' + elt] = delegateAndEmit.call(_this2, elt);
123-
});
124-
125-
['Choose', 'Sort', 'Filter', 'Move', 'Clone'].forEach(function (elt) {
126-
optionsAdded['on' + elt] = emit.bind(_this2, elt);
127-
});
128-
129-
return merge(this.options, optionsAdded);
130134
}
131135
},
132136

133137
watch: {
134-
computedOptions: function computedOptions(newValue) {
135-
this._sortable(this.rootContainer, newValue);
138+
options: function options(newOptionValue) {
139+
for (var property in newOptionValue) {
140+
if (readonlyProperties.indexOf(property) == -1) {
141+
this._sortable.option(property, newOptionValue[property]);
142+
}
143+
}
136144
}
137145
},
138146

@@ -204,7 +212,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
204212
return draggableComponent;
205213
}
206214

207-
if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) == "object") {
215+
if (typeof exports == "object") {
208216
var Sortable = require("sortablejs");
209217
module.exports = buildDraggable(Sortable);
210218
} else if (typeof define == "function" && define.amd) {

dist/vuedraggable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/disable.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
<body>
1313

1414
<div class="container-fluid" id="app">
15-
<button @click="test">click here</button>
15+
<button @click="enableEdit">Toggle Edit</button>
16+
<div>
17+
Drag enabled: {{!edit}}
18+
</div>
1619
<div v-for="machine in machines">
1720

1821
<div class="container-fluid machine-contents">

examples/script/disable.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ var vm = new Vue({
1616
}]
1717
},
1818
methods: {
19-
removeJob: function(machineId, jobNumber, jobs, index) {
20-
// Remove job from GUI
21-
jobs.splice(index, 1);
22-
},
23-
test: function() {
19+
enableEdit: function() {
2420
this.edit = !this.edit
25-
alert(this.edit)
2621
},
2722
update: function(evt){
2823
console.log(evt);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuedraggable",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"description": "draggable component for vue",
55
"main": "dist/vuedraggable.js",
66
"files": [

src/vuedraggable.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
emit.call(this, evtName, evtData)
5252
}
5353
}
54+
55+
const eventsListened = ['Start', 'Add', 'Remove', 'Update', 'End'];
56+
const eventsToEmit = ['Choose', 'Sort', 'Filter', 'Move', 'Clone'];
57+
const readonlyProperties = eventsListened.concat(eventsToEmit).map(evt => 'on'+evt);
5458

5559
const props = {
5660
options: Object,
@@ -89,7 +93,17 @@
8993
},
9094

9195
mounted () {
92-
this._sortable = new Sortable(this.rootContainer, this.computedOptions)
96+
var optionsAdded = {};
97+
eventsListened.forEach( elt => {
98+
optionsAdded['on' + elt] = delegateAndEmit.call(this, elt)
99+
});
100+
101+
eventsToEmit.forEach( elt => {
102+
optionsAdded['on' + elt] = emit.bind(this, elt)
103+
});
104+
105+
const options = merge(this.options, optionsAdded);
106+
this._sortable = new Sortable(this.rootContainer, options)
93107
this.computeIndexes()
94108
},
95109

@@ -104,26 +118,15 @@
104118
computed : {
105119
rootContainer () {
106120
return this.transitionMode? this.$el.children[0] : this.$el;
107-
},
108-
109-
computedOptions () {
110-
var optionsAdded = {};
111-
['Start', 'Add', 'Remove', 'Update', 'End'].forEach( elt => {
112-
optionsAdded['on' + elt] = delegateAndEmit.call(this, elt)
113-
});
114-
115-
['Choose', 'Sort', 'Filter', 'Move', 'Clone'].forEach( elt => {
116-
optionsAdded['on' + elt] = emit.bind(this, elt)
117-
});
118-
119-
return merge(this.options, optionsAdded);
120121
}
121122
},
122123

123124
watch: {
124-
computedOptions (newValue){
125-
for(var property in newValue){
126-
this._sortable.option(property, newValue[property]);
125+
options (newOptionValue){
126+
for(var property in newOptionValue) {
127+
if (readonlyProperties.indexOf(property)==-1) {
128+
this._sortable.option(property, newOptionValue[property] );
129+
}
127130
}
128131
}
129132
},

0 commit comments

Comments
 (0)