'use strict'; var WR = WR || {}; (function(win, $) { WR.scrollTo = function(target,container){ var $target = $(target); var offset = 10; var $container, container; if($target.length > 0){ if(container == undefined || $(container).length <= 0){ $container = $("html"); } else { $container = $(container); } $container.stop().animate({ scrollTop: ($target.offset().top - $container.offset().top + $container.scrollTop()) - offset },function(){ //console.log('complete'); }); } }; WR.smoothscroll = { passive : function(){ var supportsPassive = false; try { document.addEventListener("test", null, { get passive() { supportsPassive = true }}); } catch(e) {} return supportsPassive; }, init : function(){ if($('html').hasClass('mobile') || $('html').hasClass('mac')) return; var $window = $(window); var scrollTime = 1; var distance_offset = 2.5; var scrollDistance = $window.height() / distance_offset; if(this.passive()){ window.addEventListener("wheel",this.scrolling,{passive: false}); }else{ $window.on("mousewheel DOMMouseScroll", this.scrolling); } }, destroy : function(){ if(this.passive()){ window.removeEventListener("wheel",this.scrolling); }else{ $(window).off("mousewheel DOMMouseScroll", this.scrolling); } gsap.killTweensOf($(window),{scrollTo:true}); }, scrolling : function(event){ event.preventDefault(); var $window = $(window); var scrollTime = 1; var distance_offset = 2.5; var scrollDistance = $window.height() / distance_offset; var delta = 0; if(WR.smoothscroll.passive()){ delta = event.wheelDelta/120 || -event.deltaY/3; }else{ if(typeof event.originalEvent.deltaY != "undefined"){ delta = -event.originalEvent.deltaY/120; }else{ delta = event.originalEvent.wheelDelta/120 || -event.originalEvent.detail/3; } } var scrollTop = $window.scrollTop(); var finalScroll = scrollTop - parseInt(delta*scrollDistance); gsap.to($window, scrollTime, { scrollTo : { y: finalScroll, autoKill:true }, ease: Power3.easeOut, overwrite: 5 }); } }; WR.scroll = { // window scroll event on/off destroy : function(){ WR.smoothscroll.destroy(); if(this.support_passive()){ window.addEventListener("wheel",this.prevent_default,{passive: false}); }else{ $(window).on("mousewheel DOMMouseScroll", this.prevent_default); } }, restore : function(){ WR.smoothscroll.init(); if(this.support_passive()){ window.removeEventListener("wheel", this.prevent_default); }else{ $(window).off("mousewheel DOMMouseScroll", this.prevent_default); } }, // scroll passive mode check support_passive : function(){ var supportsPassive = false; try { document.addEventListener("test", null, { get passive() { supportsPassive = true }}); } catch(e) {} return supportsPassive; }, // disabled scroll prevent_default : function(event){ event.preventDefault(); } }; WR.is_screen = function(max_width){ if(win.matchMedia){ return win.matchMedia('(max-width:'+ max_width +'px)').matches; }else{ return win.innerWidth <= max_width; } }; WR.win_height = function(){ var win_height = 0; if(window.screen.height === window.innerHeight){ // WITHOUT Address bar (fullscreen) win_height = window.screen.height; }else{ win_height = window.innerHeight; } return win_height; }; WR.ui = { list: {}, init: function () { try { for ( var func_name in this.list ) { if ( typeof this.list[ func_name ] === 'function' ) { this.list[ func_name ].call(); } } } catch ( e ) { console.log( e ); } }, add: function ( func, exec_flag ) { try { if ( typeof func === 'function' ) { var func_name = ( ! func.name ? 'func_' + ( new Date() ).getTime() : func.name ); this.list[ func_name ] = func; if ( typeof exec_flag !== 'undefined' && exec_flag === true ) { func.call(); } } } catch ( e ) { console.log( e ); } }, del: function ( func_name ) { try { delete this.list[ func_name ]; } catch ( e ) { console.log( e ); } }, replace: function ( func_name, func ) { try { if ( typeof func === 'function' ) { this.list[ func_name ] = func; } } catch ( e ) { console.log( e ); } }, get: function ( func_name ) { try { return this.list[ func_name ]; } catch ( e ) { console.log( e ); return null; } }, call: function ( func_name ) { try { this.list[ func_name ].call(); } catch ( e ) { console.log( e ); } } }; })(window, jQuery);