-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscript.js
105 lines (84 loc) · 2.1 KB
/
script.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
(function ($) {
/* global jQuery */
'use strict';
var
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
svgmap = {
fn: {
size: function () {
svgmap.el.checked = svgmap.el.form.find(':checked');
var size = 0;
svgmap.el.checked.each(function (index, checkbox) {
if (checkbox.checked) {
size += parseFloat(checkbox.getAttribute('data-size')) || 0;
}
});
return size;
},
readable_size: function (size) {
var string;
if (size > 1) {
var i = Math.floor(Math.log(size) / Math.log(1000));
string = (size / Math.pow(1000, i)).toPrecision(3) + ' ' + sizes[i];
} else {
string = size + ' ' + sizes[0];
}
svgmap.fn.size.value = size;
svgmap.el.size.text(string);
},
animate_size: function (size) {
clearInterval(svgmap.fn.animate_size.interval);
var
count = 10,
lastSize = svgmap.fn.size.value || 0,
nextSize = size,
diffSize = Math.round(Math.abs(lastSize - nextSize) / count * (nextSize > lastSize ? 1 : -1));
function oninterval() {
svgmap.fn.readable_size(lastSize);
if (!--count) {
clearInterval(svgmap.fn.animate_size.interval);
svgmap.fn.readable_size(nextSize);
} else {
lastSize += diffSize;
}
}
svgmap.fn.animate_size.interval = setInterval(oninterval, 17);
}
},
el: {
form: null,
size: null,
checked: null
},
on: {
init: function () {
svgmap.el.form = $('.svg-list');
svgmap.el.size = $('.svg-filesize');
svgmap.el.url = $('.svg-url');
svgmap.el.form.on('change', svgmap.on.change);
svgmap.on.change();
svgmap.el.url.css({
width: svgmap.el.url.get(0).scrollWidth + 42
});
svgmap.el.url.on('focus', svgmap.on.focus);
},
change: function () {
var
is_change = arguments.length,
size = svgmap.fn.size();
if (is_change) {
svgmap.fn.animate_size(size);
} else {
svgmap.fn.readable_size(size);
}
},
focus: function () {
var input = this;
setTimeout(function (){
input.select();
});
}
}
};
$(svgmap.on.init);
})(jQuery);