bmstu-mt-wp/scripts/script.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

2010-11-15 16:45:40 +03:00
(function() {
var url = document.location,
linkScreen = document.querySelector('link[title=screen]'),
linkProjection = document.querySelector('link[title=projection]'),
shower = document.querySelector('div.shower'),
slides = document.querySelectorAll('section.slide'),
slideList = [], hashList = {},
2010-11-15 16:45:40 +03:00
progress = document.querySelector('div.progress div'),
fullscreen = false;
2010-10-30 04:16:19 +04:00
for(var i = 0, slidesLength = slides.length; i < slidesLength; i++) {
var id = slides[i].id;
slideList[i] = '#' + id;
hashList['#' + id] = i;
}
2010-11-01 07:35:25 +03:00
function toggleFull(force) {
fullscreen = (typeof force == 'boolean') ? force : (
window.fullScreen || // Firefox
document.webkitFullScreen || // Webkit
screen.width == window.outerWidth && screen.height == window.outerHeight
);
updateView();
2010-11-15 16:45:40 +03:00
updateProgress();
}
2010-10-30 04:16:19 +04:00
function turnSlide(e) {
if(!fullscreen) return;
var current = hashList[url.hash],
target;
if(e == null) {
target = slideList[current++];
} else if(e.type == 'keyup') { // Key-Based
switch(e.which) {
case 33 : // PgUp
case 38 : // Up
case 37 : // Left
current--;
break;
case 34 : // PgDown
case 40 : // Down
case 39 : // Right
current++;
break;
case 36 : // Home
current = 0;
break;
case 35 : // End
current = slideList.length-1;
break;
case 32 : // Space
current += e.shiftKey ? -1 : 1;
break;
}
target = slideList[current];
e.preventDefault();
} else { // Specific
target = slideList[+e || 0];
2010-11-08 02:26:01 +03:00
}
if(target) url.hash = target;
2010-11-15 16:45:40 +03:00
updateProgress();
2010-11-08 02:26:01 +03:00
}
2010-10-30 04:16:19 +04:00
function updateView() {
linkScreen.disabled = fullscreen;
linkProjection.disabled = !fullscreen;
if(!hashList[url.hash]) turnSlide(0);
}
2010-11-15 16:45:40 +03:00
function updateProgress() {
2010-11-16 00:39:10 +03:00
if(!progress) return;
2010-11-15 16:45:40 +03:00
progress.style.width = (100/(slideList.length-1) * hashList[url.hash]).toFixed(2) + '%';
}
2010-10-30 04:16:19 +04:00
slides[0].addEventListener('click', function(){
toggleFull(true);
}, false);
2010-11-03 11:55:56 +03:00
document.addEventListener('keyup', turnSlide, false);
document.addEventListener('keyup', function(e) {
if(e.which == 27) toggleFull(false);
}, false);
2010-11-08 02:26:01 +03:00
window.addEventListener('resize', toggleFull, false);
window.addEventListener('DOMContentLoaded', toggleFull, false);
})();