Skip to content

Commit c25e7ed

Browse files
author
pc-david\david.desmaisons
committed
Update pakage.son + make lodash a dependency
1 parent b0ad997 commit c25e7ed

File tree

3 files changed

+81
-63
lines changed

3 files changed

+81
-63
lines changed

dist/vuedragablefor.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.

package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
"version": "1.0.0",
44
"description": "vue dragable for directive",
55
"main": "src\\vuedragablefor.js",
6+
"files": [
7+
"src\\vuedragablefor.js"
8+
],
9+
"keywords": [
10+
"vue",
11+
"vuejs",
12+
"drag and drop",
13+
"Sortable.js"
14+
],
615
"directories": {
716
"example": "examples",
817
"test": "test"
918
},
1019
"dependencies": {
11-
"bower": "^1.7.9",
12-
"gulp": "^3.9.1"
20+
"lodash": "^4.13.1"
1321
},
14-
"devDependencies": {
22+
"devDependencies": {
23+
"bower": "^1.7.9",
24+
"gulp": "^3.9.1",
1525
"connect": "^3.4.1",
1626
"connect-livereload": "^0.5.4",
1727
"gulp-clean": "^0.3.2",
@@ -36,6 +46,10 @@
3646
"scripts": {
3747
"test": "gulp test"
3848
},
39-
"author": "[email protected]",
40-
"license": "MIT"
49+
"author": "David Desmaisons",
50+
"bugs": {
51+
"url": "https://github.com/David-Desmaisons/Vue.Dragable.For/issues"
52+
},
53+
"license": "MIT",
54+
"homepage": "https://github.com/David-Desmaisons/Vue.Dragable.For#readme"
4155
}

src/vuedragablefor.js

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,71 @@
11
(function(){
2+
function buildVueDragFor(_){
23

3-
function mix(source, functions){
4-
_.forEach(['bind', 'update', 'unbind'],function(value){
5-
var original = source[value];
6-
source[value] = function(){
7-
functions[value].apply(this, arguments);
8-
return original.apply(this, arguments);
9-
};
10-
});
11-
}
4+
function mix(source, functions){
5+
_.forEach(['bind', 'update', 'unbind'],function(value){
6+
var original = source[value];
7+
source[value] = function(){
8+
functions[value].apply(this, arguments);
9+
return original.apply(this, arguments);
10+
};
11+
});
12+
}
13+
14+
var vueDragFor = {
15+
install : function(Vue) {
16+
var forDirective = Vue.directive('for');
17+
var dragableForDirective = _.clone(forDirective);
18+
dragableForDirective.params = dragableForDirective.params.concat('root', 'options');
1219

13-
var vueDragFor = {
14-
install : function(Vue) {
15-
var forDirective = Vue.directive('for');
16-
var dragableForDirective = _.clone(forDirective);
17-
dragableForDirective.params = dragableForDirective.params.concat('root', 'options');
20+
mix(dragableForDirective, {
21+
bind : function () {
22+
var ctx = this;
23+
var options = this.params.options;
24+
options = (typeof options === "string") ? JSON.parse(options) : options;
25+
options = _.merge(options,{
26+
onUpdate: function (evt) {
27+
var collection = ctx.collection;
28+
if (!!collection)
29+
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
30+
},
31+
onAdd: function (evt) {
32+
var directive = evt.from.__directive;
33+
if ((!!directive) && (!!ctx.collection))
34+
ctx.collection.splice(evt.newIndex, 0, directive.collection[evt.oldIndex]);
35+
},
36+
onRemove: function (evt) {
37+
if (!!ctx.collection)
38+
ctx.collection.splice(evt.oldIndex, 1);
39+
}
40+
});
41+
var parent = (!!this.params.root) ? document.getElementById(this.params.root) : this.el.parentElement;
42+
parent.__directive = this;
43+
this.sortable = new Sortable(parent, options);
44+
},
45+
update : function (value){
46+
if ((!!value) && (!Array.isArray(value)))
47+
throw new Error('should received an Array');
1848

19-
mix(dragableForDirective, {
20-
bind : function () {
21-
var ctx = this;
22-
var options = this.params.options;
23-
options = (typeof options === "string") ? JSON.parse(options) : options;
24-
options = _.merge(options,{
25-
onUpdate: function (evt) {
26-
var collection = ctx.collection;
27-
if (!!collection)
28-
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
29-
},
30-
onAdd: function (evt) {
31-
var directive = evt.from.__directive;
32-
if ((!!directive) && (!!ctx.collection))
33-
ctx.collection.splice(evt.newIndex, 0, directive.collection[evt.oldIndex]);
34-
},
35-
onRemove: function (evt) {
36-
if (!!ctx.collection)
37-
ctx.collection.splice(evt.oldIndex, 1);
38-
}
39-
});
40-
var parent = (!!this.params.root) ? document.getElementById(this.params.root) : this.el.parentElement;
41-
parent.__directive = this;
42-
this.sortable = new Sortable(parent, options);
43-
},
44-
update : function (value){
45-
if ((!!value) && (!Array.isArray(value)))
46-
throw new Error('should received an Array');
49+
this.collection = value;
50+
},
51+
unbind : function (){
52+
this.sortable.destroy();
53+
}
54+
});
4755

48-
this.collection = value;
49-
},
50-
unbind : function (){
51-
this.sortable.destroy();
52-
}
53-
});
54-
55-
Vue.directive('dragable-for', dragableForDirective);
56-
}
57-
};
56+
Vue.directive('dragable-for', dragableForDirective);
57+
}
58+
};
59+
return vueDragFor;
60+
}
5861

5962
if (typeof exports == "object") {
60-
module.exports = vueDragFor;
63+
var _ = require("lodash.js");
64+
module.exports = buildVueDragFor(_);
6165
} else if (typeof define == "function" && define.amd) {
62-
define([], function(){ return vueDragFor; });
63-
} else if (window.Vue) {
64-
window.vueDragFor = vueDragFor;
65-
Vue.use(vueDragFor);
66+
define(['lodash'], function(_){ return buildVueDragFor(_); });
67+
} else if ((window.Vue) && (window._)) {
68+
window.vueDragFor = buildVueDragFor(window._);
69+
Vue.use(window.vueDragFor);
6670
}
6771
})();

0 commit comments

Comments
 (0)