2010-11-02 16:14:38 +03:00
|
|
|
var url = document.location,
|
|
|
|
domSlides = document.querySelectorAll('section.slide'),
|
|
|
|
slides = [], backhash = {},
|
2010-11-01 15:41:44 +03:00
|
|
|
linkScreen = document.querySelector('link[title=screen]'),
|
2010-11-02 16:14:38 +03:00
|
|
|
linkProjection = document.querySelector('link[title=projection]'),
|
|
|
|
fullscreen = false;
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2010-11-03 14:50:46 +03:00
|
|
|
for(var i = 0, iLength = domSlides.length; i < iLength; i++) {
|
2010-11-01 15:41:44 +03:00
|
|
|
var id = domSlides[i].id;
|
|
|
|
slides[i] = '#' + id;
|
|
|
|
backhash['#' + id] = i;
|
|
|
|
}
|
2010-11-01 07:35:25 +03:00
|
|
|
|
2010-11-02 16:14:38 +03:00
|
|
|
function enterFull() {
|
|
|
|
fullscreen = true;
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
2010-11-03 11:55:56 +03:00
|
|
|
function exitFull() {
|
|
|
|
fullscreen = false;
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleFull() {
|
|
|
|
if( window.fullScreen || // Firefox
|
|
|
|
document.webkitFullScreen || // Webkit
|
|
|
|
screen.width == window.outerWidth && screen.height == window.outerHeight ) {
|
|
|
|
enterFull();
|
|
|
|
} else {
|
|
|
|
exitFull();
|
2010-11-02 16:14:38 +03:00
|
|
|
}
|
2010-11-01 15:41:44 +03:00
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2010-11-01 15:41:44 +03:00
|
|
|
function turnSlide(e) {
|
2010-11-02 16:14:38 +03:00
|
|
|
if(!fullscreen) return;
|
2010-11-01 15:41:44 +03:00
|
|
|
var current = backhash[url.hash],
|
|
|
|
target,
|
|
|
|
command;
|
|
|
|
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 32 : // Space
|
|
|
|
current += e.shiftKey ? -1 : 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2010-10-30 04:16:19 +04:00
|
|
|
}
|
2010-11-01 15:41:44 +03:00
|
|
|
target = slides[current];
|
|
|
|
e.preventDefault();
|
|
|
|
if(target) url.hash = target;
|
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2010-11-01 15:41:44 +03:00
|
|
|
function updateView() {
|
|
|
|
linkScreen.disabled = fullscreen;
|
|
|
|
linkProjection.disabled = !fullscreen;
|
|
|
|
if(fullscreen && !backhash[url.hash]) url.hash = slides[0];
|
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2010-11-02 16:14:38 +03:00
|
|
|
domSlides[0].addEventListener('click', enterFull, false);
|
2010-11-03 11:55:56 +03:00
|
|
|
|
|
|
|
window.addEventListener('DOMContentLoaded', toggleFull, false);
|
|
|
|
window.addEventListener('resize', toggleFull, false);
|
|
|
|
|
|
|
|
document.addEventListener('keyup', turnSlide, false);
|
|
|
|
document.addEventListener('keyup', function(e) {
|
|
|
|
if(e.which == 27) exitFull();
|
|
|
|
}, false);
|