bmstu-mt-wp/scripts/script.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2010-10-30 04:16:19 +04:00
$(function() {
2010-11-01 07:35:25 +03:00
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;
}
2010-10-30 04:16:19 +04:00
function fullScreen() {
2010-11-01 07:35:25 +03:00
return window.screenX == 0 &&
2010-10-30 04:16:19 +04:00
window.screenY == 0 &&
screen.width == window.outerWidth &&
2010-11-01 07:35:25 +03:00
screen.height == window.outerHeight;
2010-10-30 04:16:19 +04:00
}
function turnSlide( e ) {
if( !fullScreen() ) return;
2010-11-01 07:35:25 +03:00
var current = backhash[location.hash],
target,
command;
2010-10-30 04:16:19 +04:00
switch ( e.which ) {
case 33 : // PgUp
case 38 : // Up
case 37 : // Left
2010-11-01 07:35:25 +03:00
current--;
2010-10-30 04:16:19 +04:00
break;
case 34 : // PgDown
case 40 : // Down
case 39 : // Right
2010-11-01 07:35:25 +03:00
current++;
2010-10-30 04:16:19 +04:00
break;
2010-10-31 08:57:17 +03:00
case 32 : // Space
2010-11-01 07:35:25 +03:00
current += e.shiftKey ? -1 : 1;
2010-10-31 08:57:17 +03:00
break;
2010-10-30 04:16:19 +04:00
default:
return;
}
2010-11-01 07:35:25 +03:00
target = slides[current];
2010-10-30 04:16:19 +04:00
e.preventDefault();
2010-11-01 07:35:25 +03:00
if( target ) location.hash = target;
2010-10-30 04:16:19 +04:00
}
function updateView() {
2010-11-01 07:35:25 +03:00
var fullscreen = fullScreen();
linkScreen.attr( 'disabled', fullscreen );
linkProjection.attr( 'disabled', !fullscreen );
if( fullscreen && !backhash[location.hash]) location.hash = slides[0];
2010-10-30 04:16:19 +04:00
}
$( document ).
keyup( turnSlide );
$( window ).
ready( updateView ).
resize( updateView );
2010-11-01 07:35:25 +03:00
});