-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.js
More file actions
147 lines (130 loc) · 4.05 KB
/
master.js
File metadata and controls
147 lines (130 loc) · 4.05 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
$(document).ready(function() {
let welcome = $('div.welcome')
$('#send').click(function() {
if (selectedDeviceId == null) {
$('#chooseCamera').attr('open', 'true')
$('html').addClass('modal-is-open')
return
}
welcome.add('div.section[section="receive"]').hide()
$('div.section[section="send"]').show()
$('div.section[section="send"] article.preview').hide().html("")
$('div.start').hide()
count = -1
total = 0
images = []
send_info = {
count: 0,
size: 0
}
operation = "send"
})
$('#receive').click(function() {
if (selectedDeviceId == null) {
$('#chooseCamera').attr('open', 'true')
$('html').addClass('modal-is-open')
return
}
welcome.add('div.section[section="send"]').hide()
$('div.section[section="receive"]').show()
operation = "receive"
initalQRSizeUpdate("receive")
})
$('img.back').click(function() {
welcome.show()
fullReset()
})
$('#start').click(function() {
if (operation == "send") {
let content = $('div.section[section="send"] div.sub-content')
content.children('div.button').hide()
content.children('div.section[section="send"] article.preview').hide()
content.children('article.send').show()
try {
content.children('footer').children('progress')[0].indeterminate = true
} catch (e) {}
$(this).hide()
initalQRSizeUpdate("send")
}
})
})
$(document).ready(function() {
$('#select_files').click(function() {
$('#images').click()
})
$('#images').click(function() {
$(this).val(null)
})
$('#images').change(function(e) {
$('#select_files').attr('disabled', '')
$('#select_files').attr('aria-busy', 'true')
try {
let files = e.target.files
let grid = `<div class="grid">`
$('div.section[section="send"] article.preview').hide().html("")
$('div.start').hide()
count = -1
total = 0
images = []
send_info = {
count: 0,
size: 0
}
for (var i = 0; i < files.length; i++) {
let file = files[i]
new Compressor(file, {
quality: ImagesQuality / 100,
// The compression process is asynchronous,
// which means you have to access the `result` in the `success` hook function.
success(result) {
let reader = new FileReader()
reader.onload = async function(e) {
let image = `<img src="${e.target.result}" alt="${result.name}">`
++count
total += result.size
grid += `<div class="image">
${image}<br />
<div class="size">
${formatBytes(result.size)}
</div>
</div>`
if ((count % 5 == 0 && count != 0) || count + 1 == files.length) {
grid += `</div>`
$('div.section[section="send"] article.preview').show().append(grid)
grid = `<div class="grid">`
}
let image_compresses = e.target.result
images.push(image_compresses)
if (i == files.length) {
images.sort((a, b) => {
return a.length - b.length
})
send_info.count = images.length
let size = 0
images.forEach((image) => {
size += image.length
})
send_info.size = size
$('div.start').fadeIn()
}
}
reader.readAsDataURL(result)
},
error(err) {
console.log(err.message);
},
});
}
} catch (_e) {} finally {
setTimeout(function() {
$('#select_files').removeAttr('disabled')
$('#select_files').removeAttr('aria-busy')
}, 100)
}
})
$('#imgQuality').on('input', function() {
let quality = parseInt($(this).val())
$('div.imagesQuality sup').text(`${quality}%`)
ImagesQuality = quality
})
})