|
1 | 1 | /* =========================================================== |
2 | | - * pagepiling.js 0.0.9 (Beta) |
| 2 | + * pagepiling.js 1.0 |
3 | 3 | * |
4 | 4 | * https://github.com/alvarotrigo/pagePiling.js |
5 | 5 | * MIT licensed |
|
13 | 13 | var container = $(this); |
14 | 14 | var lastScrolledDestiny; |
15 | 15 | var lastAnimation = 0; |
16 | | - var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0)); |
| 16 | + var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints)); |
17 | 17 | var touchStartY = touchStartX = touchEndY = touchEndX = 0; |
18 | 18 |
|
19 | 19 | //Defines the delay to take place before being able to scroll to the next section |
|
29 | 29 | sectionsColor: [], |
30 | 30 | anchors: [], |
31 | 31 | scrollingSpeed: 700, |
32 | | - easing: 'swing', |
| 32 | + easing: 'easeInQuart', |
33 | 33 | loopBottom: false, |
34 | 34 | loopTop: false, |
35 | 35 | css3: true, |
|
53 | 53 | }, options); |
54 | 54 |
|
55 | 55 |
|
| 56 | + //easeInQuart animation included in the plugin |
| 57 | + $.extend($.easing,{ easeInQuart: function (x, t, b, c, d) { return c*(t/=d)*t*t*t + b; }}); |
| 58 | + |
56 | 59 | /** |
57 | 60 | * Defines the scrolling speed |
58 | 61 | */ |
|
249 | 252 | } |
250 | 253 |
|
251 | 254 | if(typeof v.anchorLink !== 'undefined'){ |
252 | | - setURLHash(v.anchorLink); |
| 255 | + setURLHash(v.anchorLink, v.sectionIndex); |
253 | 256 | } |
254 | 257 |
|
255 | 258 | v.destination.addClass('active').siblings().removeClass('active'); |
|
396 | 399 | /** |
397 | 400 | * Sets the URL hash for a section with slides |
398 | 401 | */ |
399 | | - function setURLHash(anchorLink){ |
| 402 | + function setURLHash(anchorLink, sectionIndex){ |
400 | 403 | if(options.anchors.length){ |
401 | 404 | location.hash = anchorLink; |
| 405 | + |
| 406 | + setBodyClass(location.hash); |
| 407 | + }else{ |
| 408 | + setBodyClass(String(sectionIndex)); |
402 | 409 | } |
403 | 410 | } |
404 | 411 |
|
| 412 | + /** |
| 413 | + * Sets a class for the body of the page depending on the active section / slide |
| 414 | + */ |
| 415 | + function setBodyClass(text){ |
| 416 | + //removing the # |
| 417 | + text = text.replace('#',''); |
| 418 | + |
| 419 | + //removing previous anchor classes |
| 420 | + $("body")[0].className = $("body")[0].className.replace(/\b\s?pp-viewing-[^\s]+\b/g, ''); |
| 421 | + |
| 422 | + //adding the current anchor |
| 423 | + $("body").addClass("pp-viewing-" + text); |
| 424 | + } |
| 425 | + |
405 | 426 | //TO DO |
406 | 427 | function scrollToAnchor(){ |
407 | 428 | //getting the anchor link in the URL and deleting the `#` |
|
662 | 683 | function getMSPointer(){ |
663 | 684 | var pointer; |
664 | 685 |
|
665 | | - //IE >= 11 |
| 686 | + //IE >= 11 & rest of browsers |
666 | 687 | if(window.PointerEvent){ |
667 | 688 | pointer = { down: "pointerdown", move: "pointermove", up: "pointerup"}; |
668 | 689 | } |
|
681 | 702 | */ |
682 | 703 | function getEventsPage(e){ |
683 | 704 | var events = new Array(); |
684 | | - if (window.navigator.msPointerEnabled){ |
685 | | - events['y'] = e.pageY; |
686 | | - events['x'] = e.pageX; |
687 | | - }else{ |
688 | | - events['y'] = e.touches[0].pageY; |
689 | | - events['x'] = e.touches[0].pageX; |
690 | | - } |
| 705 | + |
| 706 | + events['y'] = (typeof e.pageY !== 'undefined' && (e.pageY || e.pageX) ? e.pageY : e.touches[0].pageY); |
| 707 | + events['x'] = (typeof e.pageX !== 'undefined' && (e.pageY || e.pageX) ? e.pageX : e.touches[0].pageX); |
691 | 708 |
|
692 | 709 | return events; |
693 | 710 | } |
|
0 commit comments