-
Notifications
You must be signed in to change notification settings - Fork 1
/
stuffing.js
121 lines (106 loc) · 2.95 KB
/
stuffing.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
var forever = "forever";
function XXX_RESET_XXX(){
if(confirm("Are you sure you want to reset everything? This can't be undone.")){
ga('send', 'event', 'user', "reset");
localStorage.clear();
loadData();
}
}
function msg(id, msgTxt, delay, length){
delay = delay || 0;
length = length || 5000;
var s = span();
s.innerHTML = msgTxt;
var box = div(
{
id:id,
"class":"note"
},
linkButton({
id: id + "-dismiss-button",
onclick: function(){
hide(box);
resize();
}
}, "\u00D7"),
s);
setTimeout(function(){
notifications.appendChild(box);
resize();
}, delay);
if(length != forever){
setTimeout(function(){
notifications.removeChild(box);
resize();
}, delay + length);
}
return box;
}
function spinner(txt, lbl, min, max){
if(!max){
max = Number.MAX_VALUE;
if(!min){
min = Number.MIN_VALUE;
}
else{
max = min - 1;
min = 0;
}
}
var container = span({ id: txt.id + "-spinner-container" },
label({"for": txt.id}, lbl));
txt.parentElement.replaceChild(container, txt);
var oldGetValue = txt.getValue.bind(txt);
txt.getValue = function(){
return parseInt(oldGetValue(), 10);
};
txt.size = Math.ceil(Math.log(max) / Math.log(10)) + 2;
setStyle("textAlign", "right", txt);
container.appendChild(txt);
container.appendChild(linkButton({
onclick: function(){
var v = txt.getValue();
if(v > min){
txt.setValue(v - 1);
txt.fire("change");
}
}
}, "-"));
container.appendChild(linkButton({
onclick: function(){
var v = txt.getValue();
if(v < max){
txt.setValue(v + 1);
txt.fire("change");
}
}
}, "+"));
txt.setValue(min);
return txt;
}
function fileUpload(fup){
var browse = linkButton({
id: fup.id + "-button",
onclick: function(){
fup.click()
}
},
"Browse for files");
var container = span({}, browse);
fup.parentElement.replaceChild(container, fup);
container.appendChild(fup);
hide(fup);
fup.addEventListener("change", function (){
browse.textContent = fup.files.length == 0
? "Browse for files"
: Array.prototype.map
.call(fup.files, function(f){
return fmt("$1 ($2.00MB, $3)",
f.name,
f.size / (1024 * 1024),
f.type || "application/unkown");
})
.join(", ");
});
return fup;
}