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,3 +1,4 @@
(function () {
var url = document.location, 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]'),
@ -13,7 +14,7 @@ for(var i = 0, slidesLength = slides.length; i < slidesLength; 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
@ -25,7 +26,9 @@ 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,12 +48,8 @@ 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;
} }
@ -72,3 +71,4 @@ document.addEventListener('keyup', function(e) {
window.addEventListener('resize', toggleFull, false); window.addEventListener('resize', toggleFull, false);
window.addEventListener('DOMContentLoaded', toggleFull, false); window.addEventListener('DOMContentLoaded', toggleFull, false);
})();