Skip to content

Update for Vue 2.0 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ module.exports = function (config) {
exclude: /node_modules/
},
]
}
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.js'
}
}
},

webpackMiddleware: {
noInfo: true
}
});
};
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^1.7.0",
"phantomjs-prebuilt": "^2.1.7",
"vue": "^1.0.26",
"vue": "^2.1.0",
"vue-hot-reload-api": "^2.0.5",
"vue-html-loader": "^1.2.3",
"vue-loader": "^8.5.3",
"vue-loader": "^10.0.0",
"vue-style-loader": "^1.0.0",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
"webpack": "^1.13.2",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2",
"webpack-merge": "^0.14.1"
}
}
5 changes: 2 additions & 3 deletions test/Sortable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe('vue-sortable', () => {
const vm = new Vue({
template: '<div><ul></ul></div>',
}).$mount()

expect(typeof vm.$options.directives['sortable']).toEqual('function')
expect(typeof vm.$options.directives['sortable'].bind).toEqual('function')
})

it('does not set vm.sortable unless a directive argument is passed', () => {
Expand Down Expand Up @@ -62,4 +61,4 @@ describe('vue-sortable', () => {
expect(vm.sortable.foo.options.foo).toEqual('bar')
})

})
})
31 changes: 17 additions & 14 deletions vue-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
vSortable.config = {}

vSortable.install = function (Vue) {
Vue.directive('sortable', function (options) {
options = options || {}

var sortable = new Sortable(this.el, options)

if (this.arg && !this.vm.sortable) {
this.vm.sortable = {}
}

// Throw an error if the given ID is not unique
if (this.arg && this.vm.sortable[this.arg]) {
console.warn('[vue-sortable] cannot set already defined sortable id: \'' + this.arg + '\'')
} else if( this.arg ) {
this.vm.sortable[this.arg] = sortable
Vue.directive('sortable', {
bind: function (el, binding, vnode) {
options = binding.value || {}

var sortable = new Sortable(el, options)

const vm = vnode.context;
if (binding.arg && !vm.sortable) {
vm.sortable = {}
}

// Throw an error if the given ID is not unique
if (binding.arg && vm.sortable[binding.arg]) {
console.warn('[vue-sortable] cannot set already defined sortable id: \'' + binding.arg + '\'')
} else if( binding.arg ) {
vm.sortable[binding.arg] = sortable
}
}
})
}
Expand Down