Skip to content

Commit

Permalink
Definitive fix issue # 33
Browse files Browse the repository at this point in the history
  • Loading branch information
pc-david\david.desmaisons committed Nov 30, 2016
1 parent a1244e8 commit 48f69f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 44 deletions.
44 changes: 26 additions & 18 deletions dist/vuedraggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
};
}

var eventsListened = ['Start', 'Add', 'Remove', 'Update', 'End'];
var eventsToEmit = ['Choose', 'Sort', 'Filter', 'Move', 'Clone'];
var readonlyProperties = eventsListened.concat(eventsToEmit).map(function (evt) {
return 'on' + evt;
});

var props = {
options: Object,
list: {
Expand Down Expand Up @@ -99,7 +105,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return h(this.element, null, this.$slots.default);
},
mounted: function mounted() {
this._sortable = new Sortable(this.rootContainer, this.computedOptions);
var _this2 = this;

var optionsAdded = {};
eventsListened.forEach(function (elt) {
optionsAdded['on' + elt] = delegateAndEmit.call(_this2, elt);
});

eventsToEmit.forEach(function (elt) {
optionsAdded['on' + elt] = emit.bind(_this2, elt);
});

var options = merge(this.options, optionsAdded);
this._sortable = new Sortable(this.rootContainer, options);
this.computeIndexes();
},
beforeDestroy: function beforeDestroy() {
Expand All @@ -113,26 +131,16 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
computed: {
rootContainer: function rootContainer() {
return this.transitionMode ? this.$el.children[0] : this.$el;
},
computedOptions: function computedOptions() {
var _this2 = this;

var optionsAdded = {};
['Start', 'Add', 'Remove', 'Update', 'End'].forEach(function (elt) {
optionsAdded['on' + elt] = delegateAndEmit.call(_this2, elt);
});

['Choose', 'Sort', 'Filter', 'Move', 'Clone'].forEach(function (elt) {
optionsAdded['on' + elt] = emit.bind(_this2, elt);
});

return merge(this.options, optionsAdded);
}
},

watch: {
computedOptions: function computedOptions(newValue) {
this._sortable(this.rootContainer, newValue);
options: function options(newOptionValue) {
for (var property in newOptionValue) {
if (readonlyProperties.indexOf(property) == -1) {
this._sortable.option(property, newOptionValue[property]);
}
}
}
},

Expand Down Expand Up @@ -204,7 +212,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return draggableComponent;
}

if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) == "object") {
if (typeof exports == "object") {
var Sortable = require("sortablejs");
module.exports = buildDraggable(Sortable);
} else if (typeof define == "function" && define.amd) {
Expand Down
2 changes: 1 addition & 1 deletion dist/vuedraggable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion examples/disable.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<body>

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

<div class="container-fluid machine-contents">
Expand Down
7 changes: 1 addition & 6 deletions examples/script/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ var vm = new Vue({
}]
},
methods: {
removeJob: function(machineId, jobNumber, jobs, index) {
// Remove job from GUI
jobs.splice(index, 1);
},
test: function() {
enableEdit: function() {
this.edit = !this.edit
alert(this.edit)
},
update: function(evt){
console.log(evt);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuedraggable",
"version": "2.3.1",
"version": "2.4.0",
"description": "draggable component for vue",
"main": "dist/vuedraggable.js",
"files": [
Expand Down
37 changes: 20 additions & 17 deletions src/vuedraggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
emit.call(this, evtName, evtData)
}
}

const eventsListened = ['Start', 'Add', 'Remove', 'Update', 'End'];
const eventsToEmit = ['Choose', 'Sort', 'Filter', 'Move', 'Clone'];
const readonlyProperties = eventsListened.concat(eventsToEmit).map(evt => 'on'+evt);

const props = {
options: Object,
Expand Down Expand Up @@ -89,7 +93,17 @@
},

mounted () {
this._sortable = new Sortable(this.rootContainer, this.computedOptions)
var optionsAdded = {};
eventsListened.forEach( elt => {
optionsAdded['on' + elt] = delegateAndEmit.call(this, elt)
});

eventsToEmit.forEach( elt => {
optionsAdded['on' + elt] = emit.bind(this, elt)
});

const options = merge(this.options, optionsAdded);
this._sortable = new Sortable(this.rootContainer, options)
this.computeIndexes()
},

Expand All @@ -104,26 +118,15 @@
computed : {
rootContainer () {
return this.transitionMode? this.$el.children[0] : this.$el;
},

computedOptions () {
var optionsAdded = {};
['Start', 'Add', 'Remove', 'Update', 'End'].forEach( elt => {
optionsAdded['on' + elt] = delegateAndEmit.call(this, elt)
});

['Choose', 'Sort', 'Filter', 'Move', 'Clone'].forEach( elt => {
optionsAdded['on' + elt] = emit.bind(this, elt)
});

return merge(this.options, optionsAdded);
}
},

watch: {
computedOptions (newValue){
for(var property in newValue){
this._sortable.option(property, newValue[property]);
options (newOptionValue){
for(var property in newOptionValue) {
if (readonlyProperties.indexOf(property)==-1) {
this._sortable.option(property, newOptionValue[property] );
}
}
}
},
Expand Down

0 comments on commit 48f69f1

Please sign in to comment.