Commit e3b69b89 authored by Dmitry Baranovskiy's avatar Dmitry Baranovskiy Committed by Vadim Makeev

Touching DOM as less as possible

parent 8550d1aa
$(function() { $(function() {
var slides = $( 'section.slide' ); var domSlides = $( 'section.slide' ),
location = document.location,
slides = [],
backhash = {},
linkScreen = $( 'link[title=screen]' ),
linkProjection = $( 'link[title=projection]' );
for (var i = 0, len = domSlides.length; i < len; i++) {
var id = domSlides[i].id;
slides[i] = '#' + id;
backhash['#' + id] = i;
}
function fullScreen() { function fullScreen() {
return ( return window.screenX == 0 &&
window.screenX == 0 &&
window.screenY == 0 && window.screenY == 0 &&
screen.width == window.outerWidth && screen.width == window.outerWidth &&
screen.height == window.outerHeight screen.height == window.outerHeight;
) ? true : false;
} }
function turnSlide( e ) { function turnSlide( e ) {
if( !fullScreen() ) return; if( !fullScreen() ) return;
var current = $( document.location.hash ); var current = backhash[location.hash],
target,
command;
switch ( e.which ) { switch ( e.which ) {
case 33 : // PgUp case 33 : // PgUp
case 38 : // Up case 38 : // Up
case 37 : // Left case 37 : // Left
var target = current.prev( slides ); current--;
break; break;
case 34 : // PgDown case 34 : // PgDown
case 40 : // Down case 40 : // Down
case 39 : // Right case 39 : // Right
var target = current.next( slides ); current++;
break; break;
case 32 : // Space case 32 : // Space
var target = current[ e.shiftKey ? 'prev' : 'next' ]( slides ); current += e.shiftKey ? -1 : 1;
break; break;
default: default:
return; return;
} }
target = slides[current];
e.preventDefault(); e.preventDefault();
if( !target.length ) return; if( target ) location.hash = target;
else document.location.hash = '#' + target.attr( 'id' );
} }
function updateView() { function updateView() {
var screen = $( 'link[title=screen]' ), var fullscreen = fullScreen();
projection = $( 'link[title=projection]' ), linkScreen.attr( 'disabled', fullscreen );
fullscreen = fullScreen(); linkProjection.attr( 'disabled', !fullscreen );
screen.attr( 'disabled', fullscreen ); if( fullscreen && !backhash[location.hash]) location.hash = slides[0];
projection.attr( 'disabled', !fullscreen );
if( !fullscreen || $( document.location.hash ).length ) return;
else document.location.hash = '#' + slides.first().attr( 'id' );
} }
$( document ). $( document ).
......
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