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

This commit is contained in:
Dmitry Baranovskiy 2010-11-08 12:34:56 +11:00
parent fc10c30822
commit 247d715ff0
1 changed files with 65 additions and 65 deletions

View File

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