-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
98 lines (85 loc) · 2.13 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
/** How long to show image (in seconds) */
var TIMEOUT = 20;
/** under what ratio should images be skipped */
var BADRATIO = 0.3;
/** holds the list of images */
var THE_LIST = [];
/** preloader image object */
var THE_IMAGE = {};
/** image display div */
var $THE_IMAGE = {};
/**
* Start processing the list
*/
function start() {
// preloader image thisent
THE_IMAGE = document.createElement('IMG');
THE_IMAGE.id = 'top_image';
THE_IMAGE.onload = switcher;
// div to display the images
$THE_IMAGE = $('div');
// start showing images
window.setInterval(next, 1000 * TIMEOUT);
next();
// refresh the list
window.setInterval(load, 1000 * 60 * 60);
}
/**
* Switch between images
*
* does fadeout/in once the image has been loaded
*/
function switcher() {
var w = THE_IMAGE.naturalWidth;
var h = THE_IMAGE.naturalHeight;
if (w / h < BADRATIO || h / w < BADRATIO) {
// we don't want that image
next();
return;
}
$THE_IMAGE.fadeOut('medium', function () {
$THE_IMAGE.css('background-image', 'url(' + THE_IMAGE.src + ')');
$THE_IMAGE.fadeIn('medium');
});
}
/**
* Switch to the next image
*
* preloads the image
*/
function next() {
var next = Math.floor(Math.random() * (THE_LIST.length));
THE_IMAGE.src = THE_LIST[next];
$THE_IMAGE.text(next + '/' + THE_LIST.length);
}
/**
* (Re)load the list of images
*/
function load() {
$.ajax(
'index.txt',
{
cache: false,
success: function (data) {
var first = (THE_LIST.length === 0);
THE_LIST = data.split("\n");
if (first) start();
}
}
)
}
/* Main */
$(function () {
load();
$('body').click(function () {
if (this.requestFullscreen) {
this.requestFullscreen();
} else if (this.msRequestFullscreen) {
this.msRequestFullscreen();
} else if (this.mozRequestFullScreen) {
this.mozRequestFullScreen();
} else if (this.webkitRequestFullscreen) {
this.webkitRequestFullscreen();
}
});
});