-
Notifications
You must be signed in to change notification settings - Fork 3
/
viewer.js
62 lines (51 loc) · 1.65 KB
/
viewer.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
var filenames = {};
function buildViewer() {
$('.buttonbar').each(function() {
for (var i=0; i<=4; i++) {
var el = $('<a class="btn btn-default level'+i+'" href="#" role="button">Level '+i+'</a>');
el.click(function(i) { return function() {
changeLevel($(this).parents('.viewport'), i);
}
}(i));
$(this).append(el);
}
});
$('.viewport').data('index', 0);
$('.viewport').each(function () {
changeLevel(this, 0);
});
$('.viewport').mousewheel(function(event) {
var delta = -1 * event.deltaY;
if (delta > 1) { delta = 1; }
if (delta < -1) { delta = -1; }
changeImage(this, delta);
event.preventDefault();
});
}
function changeLevel(viewport, level) {
el = $(viewport);
el.data('level', level);
el.data('index', 0);
el.find('.buttonbar > .btn').removeClass('btn-primary').addClass('btn-default');
el.find('.level'+level).removeClass('btn-default').addClass('btn-primary');
changeImage(el, 0);
}
function changeImage(viewport, delta) {
el = $(viewport);
el.data('index', el.data('index')+delta);
console.log(el.data('level'));
if (el.data('index') < 0) el.data('index', 0);
if (el.data('index') >= filenames[el.data('level')].length) {
el.data('index', filenames[el.data('level')].length);
}
var filename = filenames[el.data('level')][el.data('index')];
el.find('img').attr('src', '../'+filename);
el.find('.filename').text(filename);
el.find('.filenumber').text('File '+el.data('index')+' of '+filenames[el.data('level')].length);
}
$( document ).ready(function() {
$.getJSON("filenames.json", function(json) {
filenames = json;
buildViewer();
});
});