var __slide_data = { slidestacks : [], slidestackidx : -1, jump_to_slide : true } function push_slide_stack(ident) { var slidedata = { ident : ident, slides : $(ident), index : -1 } slidedata.count = slidedata.slides.length; console.log(slidedata); __slide_data.slidestacks.push(slidedata); __slide_data.slidestackidx++; } function current_slidestack() { return __slide_data.slidestacks[__slide_data.slidestackidx]; } /*slides.each(function() { $(this).hide(); $(this).fadeIn(0, function(){$(this).trigger('fadeInCompleted')}); })*/ // https://stackoverflow.com/questions/5685589/scroll-to-element-only-if-not-in-view-jquery /*function scrollIntoViewIfNeeded($target) { if ($target.offset()) { if ($target.offset().top < jQuery(window).scrollTop()){ //scroll up $('html,body').scrollTop($target.offset().top-20); //$('html,body').animate({scrollTop: $target.position().top-20}); } else if ($target.offset().top + $target.height() > $(window).scrollTop() + ( window.innerHeight || document.documentElement.clientHeight )) { //scroll down $('html,body').scrollTop($target.offset().top - (window.innerHeight || document.documentElement.clientHeight) + $target.height() + 20); } } }*/ function scrollIntoViewIfNeeded(target) { if(__slide_data.jump_to_slide === false) return; var rect = target.getBoundingClientRect(); if (rect.bottom > window.innerHeight-10) { target.scrollIntoView(false); window.scrollTo(0, window.pageYOffset+20); } if (rect.top < 0) { target.scrollIntoView(); //window.scrollTo(0, target.bottom+20); window.scrollTo(0, window.pageYOffset-25); } } function slide_key_up() { var stack = current_slidestack(); console.log(stack); console.log('up'); while(stack.index < 0 && __slide_data.slidestackidx > 0) { console.log('return to lower in stack UP') __slide_data.slidestackidx--; __slide_data.slidestacks.pop(); stack=current_slidestack(); console.log(stack); } if(stack.index>=0) { var slideslave = $(stack.slides[stack.index]).data('slideslave'); if(typeof slideslave !== 'undefined' && slideslave !== '') { $(slideslave).fadeOut(0); } $(stack.slides[stack.index]).fadeOut(500, function() { $(this).trigger('fadeOutCompleted') var slidefunc = $(this).data('slidefunc'); if(typeof slidefunc !== 'undefined' && slidefunc !== '') { window[slidefunc](false); } }); var subslides = $(stack.slides[stack.index]).data('prev-subslides'); stack.index--; if(typeof subslides !== 'undefined' && subslides !== '') { console.log('prev-subslides: ', subslides) push_slide_stack(subslides); stack = current_slidestack(); stack.index = stack.slides.length-1; } } /*else { // we look if we can go up if(__slide_data.slidestackidx > 0) { __slide_data.slidestackidx--; __slide_data.slidestacks.pop(); } }*/ } function slide_key_down() { var stack = current_slidestack(); console.log(stack); console.log('down'); while(stack.index+1>=stack.count && __slide_data.slidestackidx > 0) { console.log('return to lower in stack') __slide_data.slidestackidx--; __slide_data.slidestacks.pop(); stack=current_slidestack(); } if(stack.index<(stack.count-1)) { stack.index++; if($(stack.slides[stack.index]).hasClass('nodisplay')) { $(stack.slides[stack.index]).removeClass('nodisplay'); $(stack.slides[stack.index]).addClass('HASnodisplay'); } if($(stack.slides[stack.index]).parent().hasClass('nodisplay')) { $(stack.slides[stack.index]).parent().removeClass('nodisplay'); $(stack.slides[stack.index]).parent().addClass('HASnodisplay'); } var subslides = $(stack.slides[stack.index]).data('subslides'); console.log('subslides: ', subslides); if(typeof subslides !== 'undefined' && subslides !== '') { console.log('have one'); if(stack.index < (stack.slides.length)) { $(stack.slides[stack.index+1]).data('prev-subslides',subslides) console.log('ABC',$(stack.slides[stack.index+1]).data('prev-subslides')); } push_slide_stack(subslides); } //scrollIntoViewIfNeeded($(stack.slides[stack.index])); $(stack.slides[stack.index]).css('visibility','visible').hide().fadeIn(500, function() { scrollIntoViewIfNeeded(this); var slideslave = $(this).data('slideslave'); if(typeof slideslave !== 'undefined' && slideslave !== '') { console.log('sslave', $(slideslave)); if($(slideslave).parent().hasClass("nodisplay")) { $(slideslave).parent().removeClass('nodisplay'); $(slideslave).parent().addClass('HASnodisplay'); } $(slideslave).css('visibility','visible').hide().fadeIn(500); } $(this).trigger('fadeInCompleted'); var slidefunc = $(this).data('slidefunc'); if(typeof slidefunc !== 'undefined' && slidefunc !== '') { window[slidefunc](true); } }); } } $(document).keydown(function(e) { switch(e.which) { case 37: slide_key_up(); break; case 39: slide_key_down(); break; } }); function jump_to_slide_true() { __slide_data.jump_to_slide = true; console.log("SET TO TRUE"); } function show_next_slide() { if(__slide_data.slidestacks[0].index != __slide_data.slidestacks[0].slides.length-1) { slide_key_down(); setTimeout(show_next_slide, 0); } else setTimeout(jump_to_slide_true, 2000); } function show_all_slides() { __slide_data.jump_to_slide = false; show_next_slide(); /* while(__slide_data.slidestacks[0].index != __slide_data.slidestacks[0].slides.length-1) { console.log(__slide_data.slidestacks[0].index); console.log(__slide_data.slidestacks[0].slides.length-1); slide_key_down(); }*/ }