-
Notifications
You must be signed in to change notification settings - Fork 0
/
big.js
54 lines (53 loc) · 1.94 KB
/
big.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
window.onload = function() {
document.body.style.display = 'block';
var s = document.getElementsByTagName('div'), cur = 0;
if (!s) return;
function go(n) {
cur = n;
var idealTextSize = 14;
var i = Math.pow(1.618, 8)*idealTextSize;
var e = s[n];
for (var k = 0; k < s.length; k++) s[k].style.display = 'none';
e.style.display = 'inline';
e.style.fontSize = i + 'px';
if (e.firstChild.firstChild.nodeName.toLowerCase() === 'img') {
if ( e.firstChild.firstChild.title == "background" ) {
document.body.style.background = 'url(' + e.firstChild.firstChild.src + ') no-repeat';
document.body.style.backgroundSize = 'cover';
e.firstChild.firstChild.style.display = 'none';
} else {
if ( e.firstChild.firstChild.title == "border" ) {
e.firstChild.firstChild.className = "border";
}
document.body.style.backgroundImage = '';
}
} else {
document.body.style.backgroundImage = '';
}
while ( e.offsetWidth > window.innerWidth/1.1 || e.offsetHeight > window.innerHeight/1.5 ) {
e.style.fontSize = (i -= i/1.6180339887498948482045868343656381177203091798057628) + 'px';
// console.log(e.style.fontSize);
e.style.left = ( window.innerWidth - e.offsetWidth )/2 + 'px';
e.style.top = ( window.innerHeight - e.offsetHeight )/2 + 'px';
}
e.style.fontSize = Math.round(e.style.fontSize); // Round to nearest whole number
if (window.location.hash !== n) window.location.hash = n;
document.title = e.textContent || e.innerText;
}
document.onclick = function() {
go(++cur % (s.length));
};
document.onkeydown = function(e) {
(e.which === 39) && go(Math.min(s.length - 1, ++cur));
(e.which === 37) && go(Math.max(0, --cur));
};
function parse_hash() {
return Math.max( Math.min( s.length - 1, parseInt(window.location.hash.substring(1), 10)), 0);
};
if (window.location.hash) cur = parse_hash() || cur;
window.onhashchange = function() {
var c = parse_hash();
if (c !== cur) go(c);
};
go(cur);
};