jahresbericht2016/assets/js/views/layouts/default.js

9 lines
2.9 KiB
JavaScript

/*
* Wikimedia Jahresbericht 2016
*
* Copyright (c) 2017 Atelier Disko - All rights reserved.
*
* Use of this source code is governed by the AGPL v3
* license that can be found in the LICENSE file.
*/
require(["jquery","underscore","scrollTo","modernizr","domready!"],function($,_,ScrollTo){var $body=$("body");var $imprint=$(".imprint");var $close=$(".imprint-close");var $toggle=$(".imprint-toggle");var allMods,win,throttled;function visible(element,partial){var $t=$(element),$w=$(window),viewTop=$w.scrollTop(),viewBottom=viewTop+$w.height(),_top=$t.offset().top,_bottom=_top+$t.height(),compareTop=partial===true?_bottom:_top,compareBottom=partial===true?_top:_bottom;return _top+100<=viewBottom}$toggle.on("click",function(ev){ev.preventDefault();var o=$toggle.offset();if($imprint.hasClass("invis")){ScrollTo.offsets(o.left,o.top-40)}$imprint.toggleClass("invis");$close.toggleClass("invis")});$close.on("click",function(ev){ev.preventDefault();$close.addClass("invis");$imprint.addClass("invis")});var $fb=$(".finance-banner");if($fb.length&&!Modernizr.touchevents){require(["skrollr"],function(Skrollr){var s=Skrollr.init({forceHeight:false})})}var $rl=$(".report-landing");if($rl.length&&!Modernizr.touchevents){win=$(window);allMods=$(".jb-hsplit");allMods.each(function(i,el){el=$(el);if(visible(el,true)){el.addClass("already-visible");el.addClass("come-in")}});throttled=_.throttle(function(){allMods.each(function(i,el){el=$(el);if(visible(el,true)){el.addClass("come-in")}})},100);win.scroll(throttled)}if($rl.length&&Modernizr.touchevents){allMods=$(".jb-hsplit");allMods.each(function(i,el){el=$(el);el.addClass("visible")})}var $bagel=$(".bagel");if($bagel.length&&!Modernizr.touchevents){win=$(window);allMods=$(".bagel__image img");allMods.each(function(i,el){el=$(el);if(visible(el,true)){el.addClass("already-visible");el.addClass("turn-in")}});throttled=_.throttle(function(){allMods.each(function(i,el){el=$(el);if(visible(el,true)){el.addClass("turn-in")}})},100);win.scroll(throttled)}if($bagel.length&&Modernizr.touchevents){allMods=$(".bagel__image img");allMods.each(function(i,el){el=$(el);el.addClass("turn-in")})}var $slider=$(".slider");if($slider.length){require(["swiper"],function(Swiper){$slider.each(function(){var $el=$(this);var $slides=$el.find(".swiper-slide");if($slides.length<=1){$el.removeClass("loading")}else{var swiper=new Swiper($el.get(0),{nextButton:".swiper-button-next",prevButton:".swiper-button-prev",centeredSlides:true,loop:true,slidesPerView:1,onImagesReady:function(){$el.removeClass("loading")}})}})})}var $mnTrigger=$(".mn-trigger");var $mncontainer=$(".mn-container");var $logo=$(".real-logo");var $mnClose=$(".mn-close");$mnTrigger.on("click",function(ev){$mncontainer.addClass("mn-inframe");$body.addClass("no-scroll");$logo.addClass("no-filter")});$mnClose.on("click",function(ev){$mncontainer.removeClass("mn-inframe");$body.removeClass("no-scroll");$logo.removeClass("no-filter")})});