var Slideshow = {}; /************************************ * lets you define your own "global" transition function * passes in a reference to from and to slide wrapped in jQuery wrapper */ Slideshow.transition = function( $from, $to ) { $from.hide(); $to.show(); } /*********************** * sample custom transition using scrollUp effect * inspired by Karl Swedberg's Scroll Up Headline Reader jQuery Tutorial[1] * [1] http://docs.jquery.com/Tutorials:Scroll_Up_Headline_Reader */ function transitionSlideUpSlideDown( $from, $to ) { $from.slideUp( 500, function() { $to.slideDown( 1000 ); } ); } function transitionFadeOutFadeIn( $from, $to ) { $from.fadeOut( 500 ); $to.fadeIn( 500 ); } function transitionScrollUp( $from, $to ) { var cheight = $from.outerHeight(); // hide scrollbar during animation $( 'body' ).css( 'overflow-y', 'hidden' ); $to.css( 'top', cheight+'px' ); $to.show(); $from.animate( {top: -cheight}, 'slow' ); $to.animate( {top: 0}, 'slow', function() { $from.hide().css( 'top', '0px'); // restore possible scrollbar $( 'body' ).css( 'overflow-y', 'auto' ); }); } Slideshow.init = function( options ) { var settings = $.extend({ mode : 'slideshow', // slideshow | outline | autoplay projectionStyleId : '#styleProjection', screenStyleId : '#styleScreen', titleSelector : 'h1', slideSelector : '.slide', // dummy (not yet working) stepSelector : '.step', // dummy (not yet working) debug : false }, options || {}); settings.isProjection = true; // are we in projection (slideshow) mode (in contrast to screen (outline) mode)? settings.snum = 1; // current slide # (non-zero based index e.g. starting with 1) settings.smax = 1; // max number of slides settings.incpos = 0; // current step in slide settings.steps = null; settings.autoplayInterval = null; function debug( msg ) { if( window.console && window.console.log ) window.console.log( '[debug] ' + msg ); } function showHide( action ) { var $navLinks = $( '#navLinks' ) switch( action ) { case 's': $navLinks.css( 'visibility', 'visible' ); break; case 'h': $navLinks.css( 'visibility', 'hidden' ); break; case 'c': /* toggle control panel */ if( $navLinks.css( 'visibility' ) != 'visible' ) $navLinks.css( 'visibility', 'visible' ); else $navLinks.css( 'visibility', 'hidden' ); break; } } function updateCurrentSlideCounter() { $( '#currentSlide' ).html( settings.snum + '/' + settings.smax ); } function updateJumpList() { $('#jumplist').get(0).selectedIndex = (settings.snum-1); } function updatePermaLink() { // todo: unify hash marks??; use #1 for div ids instead of #slide1? window.location.hash = '#'+settings.snum; } function goTo( target ) { if( target > settings.smax || target == settings.snum ) return; go( target - settings.snum ); } function go( dir ) { debug( 'go: ' + dir ); if( dir == 0 ) return; /* same slide; nothing to do */ var cid = '#slide' + settings.snum; /* current slide (selector) id */ var csteps = settings.steps[settings.snum-1]; /* current slide steps array */ /* remove all step and stepcurrent classes from current slide */ if( csteps.length > 0) { $( csteps ).each( function() { $(this).removeClass( 'step' ).removeClass( 'stepcurrent' ); } ); } /* set snum to next slide */ settings.snum += dir; if( settings.snum > settings.smax ) settings.snum = settings.smax; if( settings.snum < 1 ) settings.snum = 1; var nid = '#slide' + settings.snum; /* next slide (selector) id */ var nsteps = settings.steps[settings.snum-1]; /* next slide steps array */ if( dir < 0 ) /* go backwards? */ { settings.incpos = nsteps.length; /* mark last step as current step */ if( nsteps.length > 0 ) $( nsteps[settings.incpos-1] ).addClass( 'stepcurrent' ); } else /* go forwards? */ { settings.incpos = 0; if( nsteps.length > 0 ) { $( nsteps ).each( function() { $(this).addClass( 'step' ).removeClass( 'stepcurrent' ); } ); } } if( !(cid == nid) ) { debug( "transition from " + cid + " to " + nid ); Slideshow.transition( $( cid ), $( nid ) ); } updateJumpList(); updateCurrentSlideCounter(); updatePermaLink(); } function subgo( dir ) { debug( 'subgo: ' + dir + ', incpos before: ' + settings.incpos + ', after: ' + (settings.incpos+dir) ); var csteps = settings.steps[settings.snum-1]; /* current slide steps array */ if( dir > 0) { /* go forward? */ if( settings.incpos > 0 ) $( csteps[settings.incpos-1] ).removeClass( 'stepcurrent' ); $( csteps[settings.incpos] ).removeClass( 'step').addClass( 'stepcurrent' ); settings.incpos++; } else { /* go backwards? */ settings.incpos--; $( csteps[settings.incpos] ).removeClass( 'stepcurrent' ).addClass( 'step' ); if( settings.incpos > 0 ) $( csteps[settings.incpos-1] ).addClass( 'stepcurrent' ); } } function notOperaFix() { $( settings.projectionStyleId ).attr( 'media','screen' ); var styleScreen = $( settings.screenStyleId ).get(0); styleScreen.disabled = true; } function toggle() { // toggle between projection (slide show) mode // and screen (outline) mode // get stylesheets var styleProjection = $( settings.projectionStyleId ).get(0); var styleScreen = $( settings.screenStyleId ).get(0); if( !styleProjection.disabled ) { styleProjection.disabled = true; styleScreen.disabled = false; settings.isProjection = false; $('.slide').each( function() { $(this).show(); } ); } else { styleProjection.disabled = false; styleScreen.disabled = true; settings.isProjection = true; $('.slide').each( function(i) { if( i == (settings.snum-1) ) $(this).show(); else $(this).hide(); }); } } function populateJumpList() { var list = $('#jumplist').get(0); $( '.slide' ).each( function(i) { var text = $(this).find( settings.titleSelector ).text(); list.options[list.length] = new Option( (i+1)+' : '+ text, (i+1) ); }); } function createControls() { // todo: make layout into an id (not class?) // do we need or allow more than one element? // if no div.layout exists, create one if( $( '.layout' ).length == 0 ) $( "
").appendTo( 'body' ); $( '.layout' ) .append( "