forked from pespantelis/vue-crop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-crop.js
67 lines (49 loc) · 1.2 KB
/
vue-crop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
;$(function() {
if (!$.Jcrop) {
console.error('Uncaught ReferenceError: Jcrop is not defined')
return
}
var vueCrop = {}
var options = {}
var events = [
'create',
'start',
'move',
'end',
'focus',
'blur',
'remove'
]
vueCrop.install = function(Vue) {
Vue.directive('crop', {
acceptStatement: true,
bind: function() {
var event = this.arg
if ($.inArray(event, events) == -1) {
console.warn('Invalid v-crop event: ' + event)
return
}
if (this.el.jcrop) return
var $wrapper = $(this.el).wrap('<div/>').parent()
$wrapper.width(this.el.width).height(this.el.height)
this.el.jcrop = $.Jcrop.attach($wrapper, options)
},
update: function(callback) {
this.el.jcrop.container.on('crop' + this.arg, callback)
},
unbind: function() {
this.el.jcrop.container.off('crop' + this.arg)
if (this._watcher.id != 1) return
this.el.jcrop.destroy()
this.el.jcrop = null
}
})
}
vueCrop.setOptions = function(opts) {
options = opts
}
if (window.Vue) {
window.VueCrop = vueCrop
Vue.use(vueCrop)
}
}());