var __slide_data = { slides : [], index : -1, jump_to_slide : true, fade_in_time: 500 } function push_slide_stack(ident) { console.log("push_slide_slides: ", ident); $(ident).each(function() { __slide_data.slides.push($(this)); $(this).hide(); var subslides = $(this).data('subslides'); if(typeof subslides !== 'undefined' && subslides !== '') { push_slide_stack(subslides); } }); console.log("push_slide_slides: ", ident, "; completet: count: ", __slide_data.slides.length) } // https://slidesoverflow.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(); console.log(rect); console.log(window.innerHeight); if (rect.bottom > window.innerHeight-10) { target.scrollIntoView(false); if(rect.height < window.innerHeight-20) { console.log("additional scroll"); window.scrollTo(0, window.pageYOffset+20); } else { var position = window.pageYOffset - (rect.height - window.innerHeight); console.log("position ", position); window.scrollTo(0, position); } } if (rect.top < 0) { target.scrollIntoView(); //window.scrollTo(0, target.bottom+20); window.scrollTo(0, window.pageYOffset-25); } } function slide_key_up() { var slides = __slide_data.slides; console.log('up'); if(__slide_data.index>=0) { var slideslave = $(slides[__slide_data.index]).data('slideslave'); if(typeof slideslave !== 'undefined' && slideslave !== '') { $(slideslave).fadeOut(0); } $(slides[__slide_data.index]).fadeOut(__slide_data.fade_in_time, function() { $(this).trigger('fadeOutCompleted') var slidefunc = $(this).data('slidefunc'); if(typeof slidefunc !== 'undefined' && slidefunc !== '') { window[slidefunc](false); } }); __slide_data.index--; } /*else { // we look if we can go up if(__slide_data.slideslidesidx > 0) { __slide_data.slideslidesidx--; __slide_data.slideslidess.pop(); } }*/ } function slide_key_down() { console.log('down; index: ', __slide_data.index); var slides = __slide_data.slides; if(__slide_data.index<(slides.length-1)) { console.log('bin drin'); __slide_data.index++; if($(slides[__slide_data.index]).hasClass('nodisplay')) { $(slides[__slide_data.index]).removeClass('nodisplay'); $(slides[__slide_data.index]).addClass('HASnodisplay'); } if($(slides[__slide_data.index]).parent().hasClass('nodisplay')) { $(slides[__slide_data.index]).parent().removeClass('nodisplay'); $(slides[__slide_data.index]).parent().addClass('HASnodisplay'); } //scrollIntoViewIfNeeded($(slides.slides[slides.index])); $(slides[__slide_data.index]).css('visibility','visible').hide().fadeIn(__slide_data.fade_in_time, 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(__slide_data.fade_in_time); } $(this).trigger('fadeInCompleted'); var slidefunc = $(this).data('slidefunc'); if(typeof slidefunc !== 'undefined' && slidefunc !== '') { window[slidefunc](true); } }); } } function register_presentationkeys () { console.log("registering keys ...") $(document).keydown(function(e) { console.log('Keydown: ', e.which) switch(e.which) { case 37: slide_key_up(); break; case 39: slide_key_down(); break; case 33: console.log('Nächster Punkt ...'); var i = $(".nav-pills:not(.pill-sub-1) > .nav-item > .nav-link.active").parent(); console.log(i); var n = i.next(); if(n.length >= 1) { console.log(n); var a = n.find('a.nav-link'); console.log(a); if(a.length >= 1) a[0].click(); else console.log("Kein nächster Punkt [FEHLER!]"); } else { console.log('Kein nächster Punkt!'); } break; case 36: console.log('Vorheriger Punkt ...'); var i = $(".nav-pills:not(.pill-sub-1) > .nav-item > .nav-link.active").parent(); console.log(i); var n = i.prev(); console.log(n); if(n.length >= 1) { console.log(n); var a = n.find('a.nav-link'); console.log(a); if(a.length >= 1) a[0].click(); else console.log("Kein vorheriger Punkt [FEHLER!]"); } else { console.log('Kein vorheriger Punkt!'); } break; case 34: console.log('Nächster Unter-Punkt ...'); var i = $(".nav-pills.pill-sub-1 > .nav-item > .nav-link.active").parent(); console.log(i); var n = i.next(); if(n.length >= 1) { console.log(n); var a = n.find('a.nav-link'); console.log(a); if(a.length >= 1) a[0].click(); else console.log("Kein nächster Punkt [FEHLER!]"); } else { console.log('Kein nächster Punkt!'); } break; case 35: console.log('Vorheriger Unter-Punkt ...'); var i = $(".nav-pills.pill-sub-1 > .nav-item > .nav-link.active").parent(); console.log(i); var n = i.prev(); console.log(n); if(n.length >= 1) { console.log(n); var a = n.find('a.nav-link'); console.log(a); if(a.length >= 1) a[0].click(); else console.log("Kein vorheriger Punkt [FEHLER!]"); } else { console.log('Kein vorheriger Punkt!'); } break; } }); } function jump_to_slide_true() { __slide_data.jump_to_slide = true; console.log("SET TO TRUE"); } function show_next_slide() { if(__slide_data.index != __slide_data.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; __slide_data.fade_in_time = 0; show_next_slide(); /* while(__slide_data.slideslidess[0].index != __slide_data.slideslidess[0].slides.length-1) { console.log(__slide_data.slideslidess[0].index); console.log(__slide_data.slideslidess[0].slides.length-1); slide_key_down(); }*/ }