UNPKG

pagepiling-js-version-kostyast

Version:
11 lines (10 loc) 10.2 kB
/*! * pagepiling.js 1.5.5 * * https://github.com/alvarotrigo/pagePiling.js * @license MIT licensed * * Copyright (C) 2016 alvarotrigo.com - A project by Alvaro Trigo */ !function(e,n,t,o){"use strict";e.fn.pagepiling=function(i){function a(e){e.addClass("pp-table").wrapInner('<div class="pp-tableCell" style="height:100%" />')}function s(n){var t=e(".pp-section.active").index(".pp-section"),o=n.index(".pp-section");return t>o?"up":"down"}function c(n,t){var o={destination:n,animated:t,activeSection:e(".pp-section.active"),anchorLink:n.data("anchor"),sectionIndex:n.index(".pp-section"),toMove:n,yMovement:s(n),leavingSection:e(".pp-section.active").index(".pp-section")+1};if(!o.activeSection.is(n)){"undefined"==typeof o.animated&&(o.animated=!0),"undefined"!=typeof o.anchorLink&&v(o.anchorLink,o.sectionIndex),o.destination.addClass("active").siblings().removeClass("active"),o.sectionsToMove=p(o),"down"===o.yMovement?(o.translate3d=W(),o.scrolling="-100%",$.css3||o.sectionsToMove.each(function(n){n!=o.activeSection.index(".pp-section")&&e(this).css(u(o.scrolling))}),o.animateSection=o.activeSection):(o.translate3d="translate3d(0px, 0px, 0px)",o.scrolling="0",o.animateSection=n),e.isFunction($.onLeave)&&$.onLeave.call(this,o.leavingSection,o.sectionIndex+1,o.yMovement),r(o),O(o.anchorLink),A(o.anchorLink,o.sectionIndex),F=o.anchorLink;var i=(new Date).getTime();j=i}}function r(n){$.css3?(b(n.animateSection,n.translate3d,n.animated),n.sectionsToMove.each(function(){b(e(this),n.translate3d,n.animated)}),setTimeout(function(){l(n)},$.scrollingSpeed)):(n.scrollOptions=u(n.scrolling),n.animated?n.animateSection.animate(n.scrollOptions,$.scrollingSpeed,$.easing,function(){d(n),l(n)}):(n.animateSection.css(u(n.scrolling)),setTimeout(function(){d(n),l(n)},400)))}function l(n){e.isFunction($.afterLoad)&&$.afterLoad.call(this,n.anchorLink,n.sectionIndex+1)}function p(n){var t;return t="down"===n.yMovement?e(".pp-section").map(function(t){if(t<n.destination.index(".pp-section"))return e(this)}):e(".pp-section").map(function(t){if(t>n.destination.index(".pp-section"))return e(this)})}function d(n){"up"===n.yMovement&&n.sectionsToMove.each(function(t){e(this).css(u(n.scrolling))})}function u(e){return"vertical"===$.direction?{top:e}:{left:e}}function v(e,n){$.anchors.length?(location.hash=e,f(location.hash)):f(String(n))}function f(n){n=n.replace("#",""),e("body")[0].className=e("body")[0].className.replace(/\b\s?pp-viewing-[^\s]+\b/g,""),e("body").addClass("pp-viewing-"+n)}function h(){}function m(){var o,i=t.location.hash.replace("#","");""!==i||"/"===i?o=i:(o=$.start,console.log(o));var a=e(n).find('.pp-section[data-anchor="'+o+'"]');a.length>0&&c(a,$.animateAnchor)}function g(){var e=(new Date).getTime();return e-j<Z+$.scrollingSpeed}function S(){var o=t.location.hash.replace("#","").split("/"),i=o[0];if(i.length&&i&&i!==F){var a;a=isNaN(i)?e(n).find('[data-anchor="'+i+'"]'):e(".pp-section").eq(i-1),c(a)}}function w(e){return{"-webkit-transform":e,"-moz-transform":e,"-ms-transform":e,transform:e}}function b(e,n,t){e.toggleClass("pp-easing",t),e.css(w(n))}function y(n){var o=(new Date).getTime();n=n||t.event;var i=n.wheelDelta||-n.deltaY||-n.detail,a=Math.max(-1,Math.min(1,i)),s="undefined"!=typeof n.wheelDeltaX||"undefined"!=typeof n.deltaX,c=Math.abs(n.wheelDeltaX)<Math.abs(n.wheelDelta)||Math.abs(n.deltaX)<Math.abs(n.deltaY)||!s;J.length>149&&J.shift(),J.push(Math.abs(i));var r=o-ee;if(ee=o,r>200&&(J=[]),!g()){var l=e(".pp-section.active"),p=C(l),d=x(J,10),u=x(J,70),v=d>=u;return v&&c&&(a<0?M("down",p):a>0&&M("up",p)),!1}}function x(e,n){for(var t=0,o=e.slice(Math.max(e.length-n,1)),i=0;i<o.length;i++)t+=o[i];return Math.ceil(t/n)}function M(e,n){var t,o;if("down"==e?(t="bottom",o=Q.moveSectionDown):(t="top",o=Q.moveSectionUp),n.length>0){if(!T(t,n))return!0;o()}else o()}function T(e,n){return"top"===e?!n.scrollTop():"bottom"===e?n.scrollTop()+1+n.innerHeight()>=n[0].scrollHeight:void 0}function C(e){return e.filter(".pp-scrollable")}function k(){R.get(0).addEventListener?(R.get(0).removeEventListener("mousewheel",y,!1),R.get(0).removeEventListener("wheel",y,!1)):R.get(0).detachEvent("onmousewheel",y)}function E(){R.get(0).addEventListener?(R.get(0).addEventListener("mousewheel",y,!1),R.get(0).addEventListener("wheel",y,!1)):R.get(0).attachEvent("onmousewheel",y)}function L(){if(B){var e=I();R.off("touchstart "+e.down).on("touchstart "+e.down,Y),R.off("touchmove "+e.move).on("touchmove "+e.move,N)}}function D(){if(B){var e=I();R.off("touchstart "+e.down),R.off("touchmove "+e.move)}}function I(){var e;return e=t.PointerEvent?{down:"pointerdown",move:"pointermove",up:"pointerup"}:{down:"MSPointerDown",move:"MSPointerMove",up:"MSPointerUp"}}function X(e){var n=new Array;return n.y="undefined"!=typeof e.pageY&&(e.pageY||e.pageX)?e.pageY:e.touches[0].pageY,n.x="undefined"!=typeof e.pageX&&(e.pageY||e.pageX)?e.pageX:e.touches[0].pageX,n}function P(e){return"undefined"==typeof e.pointerType||"mouse"!=e.pointerType}function Y(e){var n=e.originalEvent;if(P(n)){var t=X(n);H=t.y,K=t.x}}function N(n){var t=n.originalEvent;if(!q(n.target)&&P(t)){var o=e(".pp-section.active"),i=C(o);if(i.length||n.preventDefault(),!g()){var a=X(t);V=a.y,G=a.x,"horizontal"===$.direction&&Math.abs(K-G)>Math.abs(H-V)?Math.abs(K-G)>R.width()/100*$.touchSensitivity&&(K>G?M("down",i):G>K&&M("up",i)):Math.abs(H-V)>R.height()/100*$.touchSensitivity&&(H>V?M("down",i):V>H&&M("up",i))}}}function q(n,t){t=t||0;var o=e(n).parent();return!!(t<$.normalScrollElementTouchThreshold&&o.is($.normalScrollElements))||t!=$.normalScrollElementTouchThreshold&&q(o,++t)}function z(){e("body").append('<div id="pp-nav"><ul></ul></div>');var n=e("#pp-nav");n.css("color",$.navigation.textColor),n.addClass($.navigation.position);for(var t=0;t<e(".pp-section").length;t++){var o="";if($.anchors.length&&(o=$.anchors[t]),"undefined"!==$.navigation.tooltips){var i=$.navigation.tooltips[t];"undefined"==typeof i&&(i="")}n.find("ul").append('<li data-tooltip="'+i+'"><a href="#'+o+'"><span></span></a></li>')}n.find("span").css("border-color",$.navigation.bulletsColor)}function A(n,t){$.navigation&&(e("#pp-nav").find(".active").removeClass("active"),n?e("#pp-nav").find('a[href="#'+n+'"]').addClass("active"):e("#pp-nav").find("li").eq(t).find("a").addClass("active"))}function O(n){$.menu&&(e($.menu).find(".active").removeClass("active"),e($.menu).find('[data-menuanchor="'+n+'"]').addClass("active"))}function U(){var e,i=n.createElement("p"),a={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};n.body.insertBefore(i,null);for(var s in a)i.style[s]!==o&&(i.style[s]="translate3d(1px,1px,1px)",e=t.getComputedStyle(i).getPropertyValue(a[s]));return n.body.removeChild(i),e!==o&&e.length>0&&"none"!==e}function W(){return"vertical"!==$.direction?"translate3d(-100%, 0px, 0px)":"translate3d(0px, -100%, 0px)"}var F,Q=e.fn.pagepiling,R=e(this),j=0,B="ontouchstart"in t||navigator.msMaxTouchPoints>0||navigator.maxTouchPoints,H=0,K=0,V=0,G=0,J=[],Z=600,$=e.extend(!0,{start:"page2",direction:"vertical",menu:null,verticalCentered:!0,sectionsColor:[],anchors:[],scrollingSpeed:700,easing:"easeInQuart",loopBottom:!1,loopTop:!1,css3:!0,navigation:{textColor:"#000",bulletsColor:"#000",position:"right",tooltips:[]},normalScrollElements:null,normalScrollElementTouchThreshold:5,touchSensitivity:5,keyboardScrolling:!0,sectionSelector:".section",animateAnchor:!1,afterLoad:null,onLeave:null,afterRender:null},i);e.extend(e.easing,{easeInQuart:function(e,n,t,o,i){return o*(n/=i)*n*n*n+t}}),Q.setScrollingSpeed=function(e){$.scrollingSpeed=e},Q.setMouseWheelScrolling=function(e){e?E():k()},Q.setAllowScrolling=function(e){e?(Q.setMouseWheelScrolling(!0),L()):(Q.setMouseWheelScrolling(!1),D())},Q.setKeyboardScrolling=function(e){$.keyboardScrolling=e},Q.moveSectionUp=function(){var n=e(".pp-section.active").prev(".pp-section");!n.length&&$.loopTop&&(n=e(".pp-section").last()),n.length&&c(n)},Q.moveSectionDown=function(){var n=e(".pp-section.active").next(".pp-section");n.length&&c(n)},Q.moveTo=function(t){var o="";o=isNaN(t)?e(n).find('[data-anchor="'+t+'"]'):e(".pp-section").eq(t-1),o.length>0&&c(o)},e($.sectionSelector).each(function(){e(this).addClass("pp-section")}),$.css3&&($.css3=U()),e(R).css({overflow:"hidden","-ms-touch-action":"none","touch-action":"none"}),Q.setAllowScrolling(!0),e.isEmptyObject($.navigation)||z();var _=e(".pp-section").length;e(".pp-section").each(function(n){e(this).data("data-index",n),e(this).css("z-index",_),n||0!==e(".pp-section.active").length||e(this).addClass("active"),"undefined"!=typeof $.anchors[n]&&e(this).attr("data-anchor",$.anchors[n]),"undefined"!=typeof $.sectionsColor[n]&&e(this).css("background-color",$.sectionsColor[n]),$.verticalCentered&&!e(this).hasClass("pp-scrollable")&&a(e(this)),_-=1}).promise().done(function(){$.navigation&&(e("#pp-nav").css("margin-top","-"+e("#pp-nav").height()/2+"px"),e("#pp-nav").find("li").eq(e(".pp-section.active").index(".pp-section")).find("a").addClass("active")),e(t).on("load",function(){h(),m()}),e.isFunction($.afterRender)&&$.afterRender.call(this)}),e(t).on("hashchange",S),e(n).keydown(function(n){if($.keyboardScrolling&&!g())switch(n.which){case 38:case 33:Q.moveSectionUp();break;case 40:case 34:Q.moveSectionDown();break;case 36:Q.moveTo(1);break;case 35:Q.moveTo(e(".pp-section").length);break;case 37:Q.moveSectionUp();break;case 39:Q.moveSectionDown();break;default:return}}),$.normalScrollElements&&(e(n).on("mouseenter",$.normalScrollElements,function(){Q.setMouseWheelScrolling(!1)}),e(n).on("mouseleave",$.normalScrollElements,function(){Q.setMouseWheelScrolling(!0)}));var ee=(new Date).getTime();e(n).on("click touchstart","#pp-nav a",function(n){n.preventDefault();var t=e(this).parent().index();c(e(".pp-section").eq(t))}),e(n).on({mouseenter:function(){var n=e(this).data("tooltip");e('<div class="pp-tooltip '+$.navigation.position+'">'+n+"</div>").hide().appendTo(e(this)).fadeIn(200)},mouseleave:function(){e(this).find(".pp-tooltip").fadeOut(200,function(){e(this).remove()})}},"#pp-nav li")}}(jQuery,document,window); //# sourceMappingURL=jquery.pagepiling.min.js.map