forked from Darylxyx/JavaScript-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (55 loc) · 1.48 KB
/
index.js
File metadata and controls
65 lines (55 loc) · 1.48 KB
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
window.onload = function() {
function SubType() {
var doc = document;
this.containerDom = doc.querySelector('.container');
this.pageListDom = Array.prototype.slice.apply(doc.querySelectorAll('.page'));
this.fileDom = doc.querySelector('#files');
this.picAreaDom = doc.querySelector('.pic-area');
this.submitBtnDom = doc.querySelector('.submit-btn');
this.showAreaDom = doc.querySelector('.show-area');
}
SubType.prototype = {
init: function() {
this.turnPage(0);
},
handleUpload: function(files) {
var reader = new FileReader(),
_this = this;
reader.readAsDataURL(files);
reader.onload = function() {
_this.chooseComplete(reader.result);
};
},
chooseComplete: function(url) {
var _this = this;
this.cutter = new Cutter(this.picAreaDom, {
imgUrl: url,
conWidth: this.containerDom.offsetWidth,
conHeight: this.containerDom.offsetWidth * 1.2,
speed: 2,
callback: function() {
_this.turnPage(1);
}
});
},
cutImage: function() {
var result = this.cutter.cut();
this.showAreaDom.style.backgroundImage = 'url('+result+')';
this.turnPage(2);
},
turnPage: function(pageIndex) {
this.pageListDom.forEach(function(item, index) {
item.style.display = 'none';
});
this.pageListDom[pageIndex].style.display = 'block';
}
}
var a = new SubType();
a.init();
a.fileDom.onchange = function(e) {
a.handleUpload(e.target.files[0]);
};
a.submitBtnDom.onclick = function() {
a.cutImage();
};
};