Commit fc10c308 authored by Vadim Makeev's avatar Vadim Makeev

script refactoring

parent 53f357cb
var url = document.location,
domSlides = document.querySelectorAll('section.slide'),
slides = [], backhash = {},
linkScreen = document.querySelector('link[title=screen]'),
linkProjection = document.querySelector('link[title=projection]'),
shower = document.querySelector('div.shower'),
slides = document.querySelectorAll('section.slide'),
slideList = [], hashList = {},
fullscreen = false;
for(var i = 0, iLength = domSlides.length; i < iLength; i++) {
var id = domSlides[i].id;
slides[i] = '#' + id;
backhash['#' + id] = i;
for(var i = 0, slidesLength = slides.length; i < slidesLength; i++) {
var id = slides[i].id;
slideList[i] = '#' + id;
hashList['#' + id] = i;
}
function enterFull() {
fullscreen = true;
updateView();
}
function exitFull() {
fullscreen = false;
updateView();
}
function toggleFull() {
if( window.fullScreen || // Firefox
function toggleFull(force) {
fullscreen = (typeof force == 'boolean') ? force : (
window.fullScreen || // Firefox
document.webkitFullScreen || // Webkit
screen.width == window.outerWidth && screen.height == window.outerHeight ) {
enterFull();
} else {
exitFull();
}
screen.width == window.outerWidth && screen.height == window.outerHeight
);
updateView();
}
function turnSlide(e) {
if(!fullscreen) return;
var current = backhash[url.hash],
target,
command;
var current = hashList[url.hash],
target;
if(e.type == 'keyup') { // Key-Based
switch(e.which) {
case 33 : // PgUp
case 38 : // Up
......@@ -53,23 +43,32 @@ function turnSlide(e) {
default:
return;
}
target = slides[current];
target = slideList[current];
e.preventDefault();
}
if(typeof e == 'number') { // Specific
target = slideList[e];
}
if(typeof e == 'undefined') { // Next
target = slideList[current++];
}
if(target) url.hash = target;
}
function updateView() {
linkScreen.disabled = fullscreen;
linkProjection.disabled = !fullscreen;
if(fullscreen && !backhash[url.hash]) url.hash = slides[0];
if(!hashList[url.hash]) turnSlide(0);
}
domSlides[0].addEventListener('click', enterFull, false);
window.addEventListener('DOMContentLoaded', toggleFull, false);
window.addEventListener('resize', toggleFull, false);
slides[0].addEventListener('click', function(){
toggleFull(true);
}, false);
document.addEventListener('keyup', turnSlide, false);
document.addEventListener('keyup', function(e) {
if(e.which == 27) exitFull();
if(e.which == 27) toggleFull(false);
}, false);
window.addEventListener('resize', toggleFull, false);
window.addEventListener('DOMContentLoaded', toggleFull, false);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment