Skip to content
Permalink
Tree: cdb69c01de
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
8 lines (8 sloc) 10.3 KB
/*!
* multiscroll.js 0.2.2
* https://github.com/alvarotrigo/multiscroll.js
* @license MIT licensed
*
* Copyright (C) 2016 alvarotrigo.com - A project by Alvaro Trigo
*/
!function(R,Y,I,W,X){R.fn.multiscroll=function(f){var o=R.fn.multiscroll;f=R.extend({verticalCentered:!0,scrollingSpeed:700,easing:"easeInQuart",menu:!1,sectionsColor:[],anchors:[],navigation:!1,navigationPosition:"right",navigationColor:"#000",navigationTooltips:[],loopBottom:!1,loopTop:!1,css3:!1,paddingTop:0,paddingBottom:0,fixedElements:null,normalScrollElements:null,keyboardScrolling:!0,touchSensitivity:5,sectionSelector:".ms-section",leftSelector:".ms-left",rightSelector:".ms-right",afterLoad:null,onLeave:null,afterRender:null,afterResize:null},f);var h=600,n=navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/),i="ontouchstart"in Y||0<navigator.msMaxTouchPoints||navigator.maxTouchPoints;".ms-right"!==f.rightSelector&&R(f.rightSelector).addClass("ms-right"),".ms-left"!==f.leftSelector&&R(f.leftSelector).addClass("ms-left");var s,a,l,u=R(".ms-left").find(".ms-section").length,p=!1,r=R(Y).height(),e=function(){var e;e=Y.PointerEvent?{down:"pointerdown",move:"pointermove"}:{down:"MSPointerDown",move:"MSPointerMove"};return e}(),t={touchmove:"ontouchmove"in Y?"touchmove":e.move,touchstart:"ontouchstart"in Y?"touchstart":e.down};function c(){var e=Y.location.hash.replace("#","");if(e.length){var t=R(".ms-left").find('[data-anchor="'+e+'"]');("undefined"==typeof lastScrolledDestiny||e!==lastScrolledDestiny)&&y(t)}}function m(e){e.preventDefault();var t=R(this).parent().index();y(R(".ms-left .ms-section").eq(t))}function d(){var e=R(this).data("tooltip");R('<div class="multiscroll-tooltip '+f.navigationPosition+'">'+e+"</div>").hide().appendTo(R(this)).fadeIn(200)}function v(){R(this).find(".multiscroll-tooltip").fadeOut(200,function(){R(this).remove()})}w(),z(),f.css3&&(f.css3=function(){var e,t=I.createElement("p"),n={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};for(var o in I.body.insertBefore(t,null),n)t.style[o]!==X&&(t.style[o]="translate3d(1px,1px,1px)",e=Y.getComputedStyle(t).getPropertyValue(n[o]));return I.body.removeChild(t),e!==X&&0<e.length&&"none"!==e}()),R("html, body").css({overflow:"hidden",height:"100%"}),".ms-section"!==f.sectionSelector&&R(f.sectionSelector).each(function(){R(this).addClass("ms-section")}),f.navigation&&(R("body").append('<div id="multiscroll-nav"><ul></ul></div>'),(s=R("#multiscroll-nav")).css("color",f.navigationColor),s.addClass(f.navigationPosition)),R(".ms-right, .ms-left").css({width:"50%",position:"absolute",height:"100%","-ms-touch-action":"none"}),R(".ms-right").css({right:"1px",top:"0","-ms-touch-action":"none","touch-action":"none"}),R(".ms-left").css({left:"0",top:"0","-ms-touch-action":"none","touch-action":"none"}),R(".ms-left .ms-section, .ms-right .ms-section").each(function(){var e,t=R(this).index();if((f.paddingTop||f.paddingBottom)&&R(this).css("padding",f.paddingTop+" 0 "+f.paddingBottom+" 0"),void 0!==f.sectionsColor[t]&&R(this).css("background-color",f.sectionsColor[t]),void 0!==f.anchors[t]&&R(this).attr("data-anchor",f.anchors[t]),f.verticalCentered&&(e=R(this)).addClass("ms-table").wrapInner('<div class="ms-tableCell" style="height: '+L(e)+'px" />'),R(this).closest(".ms-left").length&&f.navigation){var n="";f.anchors.length&&(n=f.anchors[t]);var o=f.navigationTooltips[t];void 0===o&&(o=""),f.navigation&&s.find("ul").append('<li data-tooltip="'+o+'"><a href="#'+n+'"><span></span></a></li>')}}),R(".ms-right").html(R(".ms-right").find(".ms-section").get().reverse()),R(".ms-left .ms-section, .ms-right .ms-section").each(function(){var e=R(this).index();R(this).css({height:"100%"}),!e&&f.navigation&&s.find("li").eq(e).find("a").addClass("active")}).promise().done(function(){R(".ms-left .ms-section.active").length||(R(".ms-right").find(".ms-section").last().addClass("active"),R(".ms-left").find(".ms-section").first().addClass("active")),f.navigation&&s.css("margin-top","-"+s.height()/2+"px"),R.isFunction(f.afterRender)&&f.afterRender.call(this),b(),E(),R(Y).on("load",function(){var e,t;e=Y.location.hash.replace("#",""),t=R('.ms-left .ms-section[data-anchor="'+e+'"]'),e.length&&y(t)})}),R(Y).on("hashchange",c),R(I).keydown(function(e){clearTimeout(l);var t=R(I.activeElement);if(!t.is("textarea")&&!t.is("input")&&!t.is("select")&&f.keyboardScrolling){var n=e.which;-1<R.inArray(n,[40,38,32,33,34])&&e.preventDefault(),l=setTimeout(function(){!function(e){var t=e.shiftKey;switch(e.which){case 38:case 33:o.moveSectionUp();break;case 32:if(t){o.moveSectionUp();break}case 40:case 34:o.moveSectionDown();break;case 36:o.moveTo(1);break;case 35:o.moveTo(R(".ms-left .ms-section").length);break;default:;}}(e)},150)}}),R(I).mousedown(function(e){if(1==e.button)return e.preventDefault(),!1}),R(I).on("click","#multiscroll-nav a",m),R(I).on({mouseenter:d,mouseleave:v},"#multiscroll-nav li"),f.normalScrollElements&&(R(I).on("mouseenter",f.normalScrollElements,function(){o.setMouseWheelScrolling(!1)}),R(I).on("mouseleave",f.normalScrollElements,function(){o.setMouseWheelScrolling(!0)})),R(Y).on("resize",S);var g=r;function S(){if(n){var e=R(I.activeElement);if(!e.is("textarea")&&!e.is("input")&&!e.is("select")){var t=R(Y).height();W.abs(t-g)>20*W.max(g,t)/100&&(x(!0),g=t)}}else clearTimeout(a),a=setTimeout(function(){x(!0)},350)}function x(e){r=R(Y).height(),R(".ms-tableCell").each(function(){R(this).css({height:L(R(this).parent())})}),f.scrollOverflow&&scrollBarHandler.createScrollBarForAll(),b(),R.isFunction(f.afterResize)&&f.afterResize.call(this)}function b(){f.css3?(T(R(".ms-left"),"translate3d(0px, -"+R(".ms-left").find(".ms-section.active").position().top+"px, 0px)",!1),T(R(".ms-right"),"translate3d(0px, -"+R(".ms-right").find(".ms-section.active").position().top+"px, 0px)",!1)):(R(".ms-left").css("top",-R(".ms-left").find(".ms-section.active").position().top),R(".ms-right").css("top",-R(".ms-right").find(".ms-section.active").position().top))}function y(e){var t=e.index(),n=R(".ms-right").find(".ms-section").eq(u-1-t),o=e.data("anchor"),i=R(".ms-left .ms-section.active").index()+1,s=function(e){var t=R(".ms-left .ms-section.active").index(),n=e.index();if(n<t)return"up";return"down"}(e);p=!0;var a,l,r,c=e.position().top,m=n.position().top;if(n.addClass("active").siblings().removeClass("active"),e.addClass("active").siblings().removeClass("active"),function(e){f.anchors.length&&(location.hash=e);E()}(o),f.css3){R.isFunction(f.onLeave)&&f.onLeave.call(this,i,t+1,s);var d="translate3d(0px, -"+c+"px, 0px)",v="translate3d(0px, -"+m+"px, 0px)";T(R(".ms-left"),d,!0),T(R(".ms-right"),v,!0),setTimeout(function(){R.isFunction(f.afterLoad)&&f.afterLoad.call(this,o,t+1),setTimeout(function(){p=!1},h)},f.scrollingSpeed)}else R.isFunction(f.onLeave)&&f.onLeave.call(this,i,t+1,s),R(".ms-left").animate({top:-c},f.scrollingSpeed,f.easing,function(){R.isFunction(f.afterLoad)&&f.afterLoad.call(this,o,t+1),setTimeout(function(){p=!1},h)}),R(".ms-right").animate({top:-m},f.scrollingSpeed,f.easing);lastScrolledDestiny=o,a=o,f.menu&&(R(f.menu).find(".active").removeClass("active"),R(f.menu).find('[data-menuanchor="'+a+'"]').addClass("active")),l=o,r=t,f.navigation&&(R("#multiscroll-nav").find(".active").removeClass("active"),l?R("#multiscroll-nav").find('a[href="#'+l+'"]').addClass("active"):R("#multiscroll-nav").find("li").eq(r).find("a").addClass("active"))}function w(){I.addEventListener?(I.addEventListener("mousewheel",C,!1),I.addEventListener("wheel",C,!1)):I.attachEvent("onmousewheel",C)}function C(e){e=Y.event||e;var t=W.max(-1,W.min(1,e.wheelDelta||-e.deltaY||-e.detail));return p||(t<0?o.moveSectionDown():o.moveSectionUp()),!1}function T(e,t,n){var o;e.toggleClass("ms-easing",n),e.css({"-webkit-transform":o=t,"-moz-transform":o,"-ms-transform":o,transform:o})}function E(){var e=R(".ms-left .ms-section.active"),t=e.data("anchor"),n=e.index(),o=String(n);f.anchors.length&&(o=t),o=o.replace("/","-").replace("#","");var i=new RegExp("\\b\\s?ms-viewing-[^\\s]+\\b","g");R("body")[0].className=R("body")[0].className.replace(i,""),R("body").addClass("ms-viewing-"+o)}function L(e){var t=r;if(f.paddingTop||f.paddingBottom){var n=parseInt(e.css("padding-top"))+parseInt(e.css("padding-bottom"));t=r-n}return t}o.moveSectionUp=function(){var e=R(".ms-left .ms-section.active").prev(".ms-section");!e.length&&f.loopTop&&(e=R(".ms-left .ms-section").last()),e.length&&y(e)},o.moveSectionDown=function(){var e=R(".ms-left .ms-section.active").next(".ms-section");!e.length&&f.loopBottom&&(e=R(".ms-left .ms-section").first()),e.length&&y(e)},o.moveTo=function(e){y(isNaN(e)?R('.ms-left [data-anchor="'+e+'"]'):R(".ms-left .ms-section").eq(e-1))},o.setKeyboardScrolling=function(e){f.keyboardScrolling=e},o.setMouseWheelScrolling=function(e){e?w():I.addEventListener?(I.removeEventListener("mousewheel",C,!1),I.removeEventListener("wheel",C,!1)):I.detachEvent("onmousewheel",C)},o.setScrollingSpeed=function(e){f.scrollingSpeed=e};var k=0,B=0;function D(e){if(M(e)){event.preventDefault();R(".ms-left .ms-section.active");if(!p){var t=F(e);B=t.y,t.x,W.abs(k-B)>R(Y).height()/100*f.touchSensitivity&&(B<k?o.moveSectionDown():k<B&&o.moveSectionUp())}}}function M(e){return void 0===e.pointerType||"mouse"!=e.pointerType}function P(e){if(M(e)){var t=F(e);k=t.y,t.x}}function z(){(i||n)&&(I.removeEventListener(t.touchstart,P),I.removeEventListener(t.touchmove,D,{passive:!1}),I.addEventListener(t.touchstart,P),I.addEventListener(t.touchmove,D,{passive:!1}))}function F(e){var t=[];return t.y=void 0!==e.pageY&&(e.pageY||e.pageX)?e.pageY:e.touches[0].pageY,t.x=void 0!==e.pageX&&(e.pageY||e.pageX)?e.pageX:e.touches[0].pageX,i&&M(e)&&void 0!==e.touches&&(t.y=e.touches[0].pageY,t.x=e.touches[0].pageX),t}o.destroy=function(){o.setKeyboardScrolling(!1),o.setMouseWheelScrolling(!1),(i||n)&&(I.removeEventListener(t.touchstart,P),I.removeEventListener(t.touchmove,D,{passive:!1})),R(Y).off("hashchange",c).off("resize",S),R(I).off("mouseenter","#multiscroll-nav li").off("mouseleave","#multiscroll-nav li").off("click","#multiscroll-nav a")},o.build=function(){o.setKeyboardScrolling(!0),o.setMouseWheelScrolling(!0),z(),R(Y).on("hashchange",c).on("resize",S),R(I).on("mouseenter","#multiscroll-nav li",d).on("mouseleave","#multiscroll-nav li",v).on("click","#multiscroll-nav a",m)}}}(jQuery,window,document,Math);
You can’t perform that action at this time.