-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathindex.js
122 lines (118 loc) · 2.84 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import Croppie from 'croppie';
import 'croppie/croppie.css';
const VueCroppie = {
install(Vue, options) {
const comp = Vue.extend({
render(h){
return h('div', {
class: this.customClass,
ref: 'croppieContainer',
id: 'croppieContainer',
})
},
mounted() {
this.initCroppie();
},
props: {
boundary: {
type: Object,
default: function() {
return {
width: 400,
height: 400
}
}
},
customClass: String,
enableExif: Boolean,
enableOrientation: Boolean,
enableResize: {
type: Boolean,
default: true
},
enableZoom: {
type: Boolean,
default: true
},
enforceBoundary: {
type: Boolean,
default: true
},
mouseWheelZoom: {
type: Boolean,
default: true
},
showZoomer: {
type: Boolean,
default: true
},
viewport: {
type: Object,
default: function() {
return {
width: 200,
height: 200,
type: 'square'
}
}
},
},
data() {
return {
croppie: null
}
},
methods: {
initCroppie() {
let el = this.$refs.croppieContainer;
el.addEventListener('update', (ev) => {
this.$emit('update', ev.detail);
});
this.croppie = new Croppie(el, {
boundary: this.boundary,
enableExif: this.enableExif,
enableOrientation: this.enableOrientation,
enableZoom: this.enableZoom,
enableResize: this.enableResize,
enforceBoundary: this.enforceBoundary,
mouseWheelZoom: this.mouseWheelZoom,
viewport: this.viewport,
showZoomer: this.showZoomer
});
},
bind(options) {
this.croppie.bind(options)
},
destroy() {
this.croppie.destroy();
},
get(cb) {
cb(this.croppie.get())
},
rotate(angle) {
this.croppie.rotate(angle);
},
setZoom(value) {
this.croppie.setZoom(value);
},
result(options, cb) {
if(!options) options = {type: 'base64'}
this.croppie.result(options).then(output => {
if(!cb) {
this.$emit('result', output);
} else {
cb(output);
}
this.refresh();
});
},
refresh() {
this.croppie.destroy();
this.initCroppie();
}
}
});
Vue.component('vue-croppie', comp)
}
};
export default VueCroppie;