Commit 247d715f authored by Dmitry Baranovskiy's avatar Dmitry Baranovskiy

Duck-typing fix. Less `typeof`, more casting.

parent fc10c308
var url = document.location, (function () {
var url = document.location,
linkScreen = document.querySelector('link[title=screen]'), linkScreen = document.querySelector('link[title=screen]'),
linkProjection = document.querySelector('link[title=projection]'), linkProjection = document.querySelector('link[title=projection]'),
shower = document.querySelector('div.shower'), shower = document.querySelector('div.shower'),
...@@ -6,26 +7,28 @@ var url = document.location, ...@@ -6,26 +7,28 @@ var url = document.location,
slideList = [], hashList = {}, slideList = [], hashList = {},
fullscreen = false; fullscreen = false;
for(var i = 0, slidesLength = slides.length; i < slidesLength; i++) { for(var i = 0, slidesLength = slides.length; i < slidesLength; i++) {
var id = slides[i].id; var id = slides[i].id;
slideList[i] = '#' + id; slideList[i] = '#' + id;
hashList['#' + id] = i; hashList['#' + id] = i;
} }
function toggleFull(force) { function toggleFull(force) {
fullscreen = (typeof force == 'boolean') ? force : ( fullscreen = (force != null) ? !!force : (
window.fullScreen || // Firefox window.fullScreen || // Firefox
document.webkitFullScreen || // Webkit document.webkitFullScreen || // Webkit
screen.width == window.outerWidth && screen.height == window.outerHeight screen.width == window.outerWidth && screen.height == window.outerHeight
); );
updateView(); updateView();
} }
function turnSlide(e) { function turnSlide(e) {
if(!fullscreen) return; if(!fullscreen) return;
var current = hashList[url.hash], var current = hashList[url.hash],
target; target;
if(e.type == 'keyup') { // Key-Based if(e == null) {
target = slideList[current++];
} else if(e.type == 'keyup') { // Key-Based
switch(e.which) { switch(e.which) {
case 33 : // PgUp case 33 : // PgUp
case 38 : // Up case 38 : // Up
...@@ -45,30 +48,27 @@ function turnSlide(e) { ...@@ -45,30 +48,27 @@ function turnSlide(e) {
} }
target = slideList[current]; target = slideList[current];
e.preventDefault(); e.preventDefault();
} } else { // Specific
if(typeof e == 'number') { // Specific target = slideList[+e || 0];
target = slideList[e];
}
if(typeof e == 'undefined') { // Next
target = slideList[current++];
} }
if(target) url.hash = target; if(target) url.hash = target;
} }
function updateView() { function updateView() {
linkScreen.disabled = fullscreen; linkScreen.disabled = fullscreen;
linkProjection.disabled = !fullscreen; linkProjection.disabled = !fullscreen;
if(!hashList[url.hash]) turnSlide(0); if(!hashList[url.hash]) turnSlide(0);
} }
slides[0].addEventListener('click', function(){ slides[0].addEventListener('click', function(){
toggleFull(true); toggleFull(true);
}, false); }, false);
document.addEventListener('keyup', turnSlide, false); document.addEventListener('keyup', turnSlide, false);
document.addEventListener('keyup', function(e) { document.addEventListener('keyup', function(e) {
if(e.which == 27) toggleFull(false); if(e.which == 27) toggleFull(false);
}, false); }, false);
window.addEventListener('resize', toggleFull, false); window.addEventListener('resize', toggleFull, false);
window.addEventListener('DOMContentLoaded', toggleFull, false); window.addEventListener('DOMContentLoaded', toggleFull, false);
\ No newline at end of file })();
\ 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