1/*! 2 * multiscroll.js 0.1.8 Beta 3 * https://github.com/alvarotrigo/multiscroll.js 4 * @license MIT licensed 5 * 6 * Copyright (C) 2016 alvarotrigo.com - A project by Alvaro Trigo 7 */ 8(function(jQuery, window, document, Math, undefined) { 9 10 jQuery.fn.multiscroll = function(options) { 11 var MS = jQuery.fn.multiscroll; 12 13 // Create some defaults, extending them with any options that were provided 14 options = jQuery.extend({ 15 'verticalCentered' : true, 16 'scrollingSpeed': 700, 17 'easing': 'easeInQuart', 18 'menu': false, 19 'sectionsColor': [], 20 'anchors':[], 21 'navigation': false, 22 'navigationPosition': 'right', 23 'navigationColor': '#000', 24 'navigationTooltips': [], 25 'loopBottom': false, 26 'loopTop': false, 27 'css3': false, 28 'paddingTop': 0, 29 'paddingBottom': 0, 30 'fixedElements': null, 31 'normalScrollElements': null, 32 'keyboardScrolling': true, 33 'touchSensitivity': 5, 34 35 // Custom selectors 36 'sectionSelector': '.ms-section', 37 'leftSelector': '.ms-left', 38 'rightSelector': '.ms-right', 39 40 //events 41 'afterLoad': null, 42 'onLeave': null, 43 'afterRender': null, 44 'afterResize': null 45 }, options); 46 47 //Defines the delay to take place before being able to scroll to the next section 48 //BE CAREFUL! Not recommened to change it under 400 for a good behavior in laptops and 49 //Apple devices (laptops, mouses...) 50 var scrollDelay = 600; 51 52 var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints)); 53 54 // adding class namef for right and left blocks 55 if (options.rightSelector !== '.ms-right') { 56 jQuery(options.rightSelector).addClass('ms-right'); 57 } 58 59 if (options.leftSelector !== '.ms-left') { 60 jQuery(options.leftSelector).addClass('ms-left'); 61 } 62 63 var numberSections = jQuery('.ms-left').find('.ms-section').length; 64 var isMoving = false; 65 var nav; 66 var windowHeight = jQuery(window).height(); 67 68 69 addMouseWheelHandler(); 70 addTouchHandler(); 71 72 //if css3 is not supported, it will use jQuery animations 73 if(options.css3){ 74 options.css3 = support3d(); 75 } 76 77 jQuery('html, body').css({ 78 'overflow' : 'hidden', 79 'height' : '100%' 80 }); 81 82 //adding class names to each sections 83 if (options.sectionSelector !== '.ms-section') { 84 jQuery(options.sectionSelector).each(function(){ 85 jQuery(this).addClass('ms-section'); 86 }); 87 } 88 89 //creating the navigation dots 90 if (options.navigation) { 91 jQuery('body').append('<div id="multiscroll-nav"><ul></ul></div>'); 92 nav = jQuery('#multiscroll-nav'); 93 94 nav.css('color', options.navigationColor); 95 nav.addClass(options.navigationPosition); 96 } 97 98 jQuery('.ms-right, .ms-left').css({ 99 'width': '50%', 100 'position': 'absolute', 101 'height': '100%', 102 '-ms-touch-action': 'none' 103 }); 104 105 jQuery('.ms-right').css({ 106 'right': '1px', //http://stackoverflow.com/questions/23675457/chrome-and-opera-creating-small-padding-when-using-displaytable 107 'top': '0', 108 '-ms-touch-action': 'none', 109 'touch-action': 'none' 110 }); 111 112 jQuery('.ms-left').css({ 113 'left': '0', 114 'top': '0', 115 '-ms-touch-action': 'none', 116 'touch-action': 'none' 117 }); 118 119 120 jQuery('.ms-left .ms-section, .ms-right .ms-section').each(function(){ 121 var sectionIndex = jQuery(this).index(); 122 123 if(options.paddingTop || options.paddingBottom){ 124 jQuery(this).css('padding', options.paddingTop + ' 0 ' + options.paddingBottom + ' 0'); 125 } 126 127 if (typeof options.sectionsColor[sectionIndex] !== 'undefined') { 128 jQuery(this).css('background-color', options.sectionsColor[sectionIndex]); 129 } 130 131 if (typeof options.anchors[sectionIndex] !== 'undefined') { 132 jQuery(this).attr('data-anchor', options.anchors[sectionIndex]); 133 } 134 135 if(options.verticalCentered){ 136 addTableClass(jQuery(this)); 137 } 138 139 //only for the left panel 140 if(jQuery(this).closest('.ms-left').length && options.navigation) { 141 var link = ''; 142 if(options.anchors.length){ 143 link = options.anchors[sectionIndex]; 144 } 145 var tooltip = options.navigationTooltips[sectionIndex]; 146 if(typeof tooltip === 'undefined'){ 147 tooltip = ''; 148 } 149 if (options.navigation) { 150 nav.find('ul').append('<li data-tooltip="' + tooltip + '"><a href="#' + link + '"><span></span></a></li>'); 151 } 152 } 153 }); 154 155 //inverting the right panel 156 jQuery('.ms-right').html( jQuery('.ms-right').find('.ms-section').get().reverse()); 157 158 jQuery('.ms-left .ms-section, .ms-right .ms-section').each(function(){ 159 var sectionIndex = jQuery(this).index(); 160 161 jQuery(this).css({ 162 'height': '100%' 163 }); 164 165 166 if(!sectionIndex && options.navigation ){
167 //activating the navigation bullet 168 nav.find('li').eq(sectionIndex).find('a').addClass('active'); 169 } 170 }).promise().done(function(){ 171 172 //if no active section is defined, the 1st one will be the default one 173 if(!jQuery('.ms-left .ms-section.active').length){ 174 jQuery('.ms-right').find('.ms-section').last().addClass('active'); 175 jQuery('.ms-left').find('.ms-section').first().addClass('active'); 176 } 177 178 //vertical centered of the navigation + first bullet active 179 if(options.navigation){ 180 nav.css('margin-top', '-' + (nav.height()/2) + 'px'); 181 } 182 jQuery.isFunction( options.afterRender ) && options.afterRender.call( this); 183 184 //scrolling to the defined active section and adjusting right and left panels 185 silentScroll(); 186 187 //setting the class for the body element 188 setBodyClass(); 189 190 jQuery(window).on('load', function() { 191 scrollToAnchor(); 192 }); 193 }); 194 195 196 //detecting any change on the URL to scroll to the given anchor link 197 //(a way to detect back history button as we play with the hashes on the URL) 198 jQuery(window).on('hashchange', hashChangeHandler); 199 200 function hashChangeHandler(){ 201 var value = window.location.hash.replace('#', ''); 202 var sectionAnchor = value; 203 204 if(sectionAnchor.length){ 205 var section = jQuery('.ms-left').find('[data-anchor="'+sectionAnchor+'"]'); 206 207 var isFirstScrollMove = (typeof lastScrolledDestiny === 'undefined' ); 208 209 if (isFirstScrollMove || sectionAnchor !== lastScrolledDestiny){ 210 scrollPage(section); 211 } 212 } 213 }; 214 215 216 /** 217 * Sliding with arrow keys, both, vertical and horizontal 218 */ 219 jQuery(document).keydown(keydownHandler); 220 221 222 var keydownId; 223 function keydownHandler(e) { 224 clearTimeout(keydownId); 225 226 var activeElement = jQuery(document.activeElement); 227 228 if(!activeElement.is('textarea') && !activeElement.is('input') && !activeElement.is('select') && 229 options.keyboardScrolling){ 230 var keyCode = e.which; 231 232 //preventing the scroll with arrow keys & spacebar & Page Up & Down keys 233 var keyControls = [40, 38, 32, 33, 34]; 234 if(jQuery.inArray(keyCode, keyControls) > -1){ 235 e.preventDefault(); 236 } 237 238 keydownId = setTimeout(function(){ 239 onkeydown(e); 240 },150); 241 } 242 } 243 244 /** 245 * Sliding with arrow keys, both, vertical and horizontal 246 */ 247 function onkeydown(e){ 248 var shiftPressed = e.shiftKey; 249 250 switch (e.which) { 251 //up 252 case 38: 253 case 33: 254 MS.moveSectionUp(); 255 break; 256 257 //down 258 case 32: //spacebar 259 if(shiftPressed){ 260 MS.moveSectionUp(); 261 break; 262 } 263 case 40: 264 case 34: 265 MS.moveSectionDown(); 266 break; 267 268 //Home 269 case 36: 270 MS.moveTo(1); 271 break; 272 273 //End 274 case 35: 275 MS.moveTo( jQuery('.ms-left .ms-section').length); 276 break; 277 278 default: 279 return; // exit this handler for other keys 280 } 281 } 282 283 /** 284 * Disabling any action when pressing of the mouse wheel (Chrome, IE, Opera, Safari) 285 */ 286 jQuery(document).mousedown(function(e) { 287 if(e.button == 1){ 288 e.preventDefault(); 289 return false; 290 } 291 }); 292 293 function navClickHandler(e) { 294 e.preventDefault(); 295 var index = jQuery(this).parent().index(); 296 scrollPage(jQuery('.ms-left .ms-section').eq(index)); 297 } 298 299 //navigation action 300 jQuery(document).on('click', '#multiscroll-nav a', navClickHandler); 301 302 function navMouseEnterHandler() { 303 var tooltip = jQuery(this).data('tooltip'); 304 jQuery('<div class="multiscroll-tooltip ' + options.navigationPosition +'">' + tooltip + '</div>').hide().appendTo(jQuery(this)).fadeIn(200); 305 } 306 307 function navMouseLeaveHandler() { 308 jQuery(this).find('.multiscroll-tooltip').fadeOut(200, function() { 309 jQuery(this).remove(); 310 }); 311 } 312 313 //navigation tooltips 314 jQuery(document).on({ 315 mouseenter: navMouseEnterHandler, 316 mouseleave: navMouseLeaveHandler 317 }, '#multiscroll-nav li'); 318 319 320 if(options.normalScrollElements){ 321 jQuery(document).on('mouseenter', options.normalScrollElements, function () { 322 MS.setMouseWheelScrolling(false); 323 }); 324 325 jQuery(document).on('mouseleave', options.normalScrollElements, function(){ 326 MS.setMouseWheelScrolling(true); 327 }); 328 } 329 330 331 //when resizing the site, we adjust the heights of the sections 332 jQuery(window).on('resize', doneResizing); 333 334 /** 335 * When resizing is finished, we adjust the slides sizes and positions 336 */ 337 function doneResizing() { 338 windowHeight = jQuery(window).height(); 339 jQuery('.ms-tableCell').each(function() { 340 jQuery(this).css({ height: getTableHeight(jQuery(this).parent()) }); 341 }); 342 silentScroll(); 343 jQuery.isFunction( options.afterResize ) && options.afterResize.call( this); 344 } 345 346 function silentScroll(){ 347 //moving the right section to the bottom 348 if(options.css3){ 349 transformContainer(jQuery('.ms-left'), 'translate3d(0px, -' + jQuery('.ms-left').find('.ms-section.active').position().top + 'px, 0px)', false); 350 transformContainer(jQuery('.ms-right'), 'translate3d(0px, -' + jQuery('.ms-right').find('.ms-section.active').position().top + 'px, 0px)', false); 351 }else{ 352 jQuery('.ms-left').css('top', -jQuery('.ms-left').find('.ms-section.active').position().top ); 353 jQuery('.ms-right').css('top', -jQuery('.ms-right').find('.ms-section.active').position().top ); 354 } 355 } 356 357 MS.moveSectionUp = function(){ 358 var prev = jQuery('.ms-left .ms-section.active').prev('.ms-section'); 359
360 if(!prev.length && options.loopTop){ 361 prev = jQuery('.ms-left .ms-section').last(); 362 } 363 364 if (prev.length) { 365 scrollPage(prev); 366 } 367 }; 368 369 MS.moveSectionDown = function (){ 370 var next = jQuery('.ms-left .ms-section.active').next('.ms-section'); 371 372 if(!next.length && options.loopBottom ){ 373 next = jQuery('.ms-left .ms-section').first(); 374 } 375 376 if(next.length){ 377 scrollPage(next); 378 } 379 }; 380 381 MS.moveTo = function (section){ 382 var destiny = ''; 383 384 if(isNaN(section)){ 385 destiny = jQuery('.ms-left [data-anchor="'+section+'"]'); 386 }else{ 387 destiny = jQuery('.ms-left .ms-section').eq( (section -1) ); 388 } 389 390 scrollPage(destiny); 391 }; 392 393 function scrollPage(leftDestination){ 394 var leftDestinationIndex = leftDestination.index(); 395 var rightDestination = jQuery('.ms-right').find('.ms-section').eq( numberSections -1 - leftDestinationIndex); 396 var rightDestinationIndex = numberSections - 1 - leftDestinationIndex; 397 var anchorLink = leftDestination.data('anchor'); 398 var activeSection = jQuery('.ms-left .ms-section.active'); 399 var leavingSection = activeSection.index() + 1; 400 var yMovement = getYmovement(leftDestination); 401 402 //preventing from activating the MouseWheelHandler event 403 //more than once if the page is scrolling 404 isMoving = true; 405 406 var topPos = { 407 'left' : leftDestination.position().top, 408 'right': rightDestination.position().top 409 }; 410 411 rightDestination.addClass('active').siblings().removeClass('active'); 412 leftDestination.addClass('active').siblings().removeClass('active'); 413 414 setURLHash(anchorLink); 415 416 // Use CSS3 translate functionality or... 417 if (options.css3){ 418 //callback (onLeave) 419 jQuery.isFunction(options.onLeave) && options.onLeave.call(this, leavingSection, (leftDestinationIndex + 1), yMovement); 420 421 var translate3dLeft = 'translate3d(0px, -' + topPos['left'] + 'px, 0px)'; 422 var translate3dRight = 'translate3d(0px, -' + topPos['right'] + 'px, 0px)'; 423 424 transformContainer(jQuery('.ms-left'), translate3dLeft, true); 425 transformContainer(jQuery('.ms-right'), translate3dRight, true); 426 427 setTimeout(function () { 428 //callback (afterLoad) 429 jQuery.isFunction(options.afterLoad) && options.afterLoad.call(this, anchorLink, (leftDestinationIndex + 1)); 430 431 setTimeout(function () { 432 isMoving = false; 433 }, scrollDelay); 434 }, options.scrollingSpeed); 435 }else{ 436 //callback (onLeave) 437 jQuery.isFunction(options.onLeave) && options.onLeave.call(this, leavingSection, (leftDestinationIndex + 1), yMovement); 438 439 jQuery('.ms-left').animate({ 440 'top': -topPos['left'] 441 }, options.scrollingSpeed, options.easing, function(){ 442 jQuery.isFunction(options.afterLoad) && options.afterLoad.call(this, anchorLink, (leftDestinationIndex + 1)); 443 444 setTimeout(function () { 445 isMoving = false; 446 }, scrollDelay); 447 }); 448 449 jQuery('.ms-right').animate({ 450 'top': -topPos['right'] 451 }, options.scrollingSpeed, options.easing); 452 } 453 454 //flag to avoid callingn `scrollPage()` twice in case of using anchor links 455 lastScrolledDestiny = anchorLink; 456 457 activateMenuElement(anchorLink); 458 activateNavDots(anchorLink, leftDestinationIndex); 459 } 460 461 /** 462 * Removes the auto scrolling action fired by the mouse wheel and tackpad. 463 * After this function is called, the mousewheel and trackpad movements won't scroll through sections. 464 */ 465 function removeMouseWheelHandler(){ 466 if (document.addEventListener) { 467 document.removeEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper 468 document.removeEventListener('wheel', MouseWheelHandler, false); //Firefox 469 } else { 470 document.detachEvent("onmousewheel", MouseWheelHandler); //IE 6/7/8 471 } 472 } 473 474 /** 475 * Adds the auto scrolling action for the mouse wheel and tackpad. 476 * After this function is called, the mousewheel and trackpad movements will scroll through sections 477 */ 478 function addMouseWheelHandler(){ 479 if (document.addEventListener) { 480 document.addEventListener("mousewheel", MouseWheelHandler, false); //IE9, Chrome, Safari, Oper 481 document.addEventListener("wheel", MouseWheelHandler, false); //Firefox 482 } else { 483 document.attachEvent("onmousewheel", MouseWheelHandler); //IE 6/7/8 484 } 485 } 486 487 /** 488 * Detecting mousewheel scrolling 489 * 490 * http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html 491 * http://www.sitepoint.com/html5-javascript-mouse-wheel/ 492 */ 493 function MouseWheelHandler(e) { 494 // cross-browser wheel delta 495 e = window.event || e; 496 var delta = Math.max(-1, Math.min(1, 497 (e.wheelDelta || -e.deltaY || -e.detail))); 498 499 if (!isMoving) { //if theres any # 500 501 //scrolling down? 502 if (delta < 0) { 503 MS.moveSectionDown(); 504 } 505 506 //scrolling up? 507 else { 508 MS.moveSectionUp(); 509 } 510 } 511 512 513 return false; 514 } 515 516 /** 517 * Adds a css3 transform property to the container class with or without animation depending on the animated param. 518 */ 519 function transformContainer(container, translate3d, animated){
520 container.toggleClass('ms-easing', animated); 521 522 container.css(getTransforms(translate3d)); 523 } 524 525 526 /** 527 * Returns the transform styles for all browsers 528 */ 529 function getTransforms(translate3d){ 530 return { 531 '-webkit-transform': translate3d, 532 '-moz-transform': translate3d, 533 '-ms-transform':translate3d, 534 'transform': translate3d 535 }; 536 } 537 538 /** 539 * Activating the website navigation dots according to the given slide name. 540 */ 541 function activateNavDots(name, sectionIndex){ 542 if(options.navigation){ 543 jQuery('#multiscroll-nav').find('.active').removeClass('active'); 544 if(name){ 545 jQuery('#multiscroll-nav').find('a[href="#' + name + '"]').addClass('active'); 546 }else{ 547 jQuery('#multiscroll-nav').find('li').eq(sectionIndex).find('a').addClass('active'); 548 } 549 } 550 } 551 552 /** 553 * Activating the website main menu elements according to the given slide name. 554 */ 555 function activateMenuElement(name){ 556 if(options.menu){ 557 jQuery(options.menu).find('.active').removeClass('active'); 558 jQuery(options.menu).find('[data-menuanchor="'+name+'"]').addClass('active'); 559 } 560 } 561 562 /** 563 * Retuns `up` or `down` depending on the scrolling movement to reach its destination 564 * from the current section. 565 */ 566 function getYmovement(destiny){ 567 var fromIndex = jQuery('.ms-left .ms-section.active').index(); 568 var toIndex = destiny.index(); 569 570 if(fromIndex > toIndex){ 571 return 'up'; 572 } 573 return 'down'; 574 } 575 576 577 /** 578 * Sets the URL hash for a section with slides 579 */ 580 function setURLHash(anchorLink){ 581 if(options.anchors.length){ 582 location.hash = anchorLink; 583 } 584 585 setBodyClass(); 586 } 587 588 /** 589 * Sets a class for the body of the page depending on the active section / slide 590 */ 591 function setBodyClass(){ 592 var section = jQuery('.ms-left .ms-section.active'); 593 var sectionAnchor = section.data('anchor'); 594 var sectionIndex = section.index(); 595 596 var text = String(sectionIndex); 597 598 if(options.anchors.length){ 599 text = sectionAnchor; 600 } 601 602 //changing slash for dash to make it a valid CSS style 603 text = text.replace('/', '-').replace('#',''); 604 605 //removing previous anchor classes 606 var classRe = new RegExp('\\b\\s?' + 'ms-viewing' + '-[^\\s]+\\b', "g"); 607 jQuery('body')[0].className = jQuery('body')[0].className.replace(classRe, ''); 608 609 //adding the current anchor 610 jQuery('body').addClass('ms-viewing-' + text); 611 } 612 613 614 /** 615 * Checks for translate3d support 616 * @return boolean 617 * http://stackoverflow.com/questions/5661671/detecting-transform-translate3d-support 618 */ 619 function support3d() { 620 var el = document.createElement('p'), 621 has3d, 622 transforms = { 623 'webkitTransform':'-webkit-transform',
624 'OTransform':'-o-transform', 625 'msTransform':'-ms-transform', 626 'MozTransform':'-moz-transform', 627 'transform':'transform' 628 }; 629 630 // Add it to the body to get the computed style. 631 document.body.insertBefore(el, null); 632 633 for (var t in transforms) { 634 if (el.style[t] !== undefined) { 635 el.style[t] = "translate3d(1px,1px,1px)"; 636 has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]); 637 } 638 } 639 640 document.body.removeChild(el); 641 642 return (has3d !== undefined && has3d.length > 0 && has3d !== "none"); 643 } 644 645 /** 646 * Wraps an element in order to center it vertically by using a class style. 647 */ 648 function addTableClass(element){ 649 element.addClass('ms-table').wrapInner('<div class="ms-tableCell" style="height: ' + getTableHeight(element) + 'px" />'); 650 } 651 652 /** 653 * Gets the height of the section after removing the paddings. 654 */ 655 function getTableHeight(section){ 656 var sectionHeight = windowHeight; 657 658 if(options.paddingTop || options.paddingBottom){ 659 var paddings = parseInt(section.css('padding-top')) + parseInt(section.css('padding-bottom')); 660 sectionHeight = (windowHeight - paddings); 661 } 662 663 return sectionHeight; 664 } 665 666 667 /** 668 * Scrolls the page to the existent anchor in the URL 669 */ 670 function scrollToAnchor(){ 671 //getting the anchor link in the URL and deleting the `#` 672 var sectionAnchor = window.location.hash.replace('#', ''); 673 var section = jQuery('.ms-left .ms-section[data-anchor="'+sectionAnchor+'"]'); 674 675 if(sectionAnchor.length){ //if theres any # 676 scrollPage(section); 677 } 678 } 679 680 /** 681 * Adds or remove the possiblity of scrolling through sections by using the keyboard arrow keys 682 */ 683 MS.setKeyboardScrolling = function (value){ 684 options.keyboardScrolling = value; 685 }; 686 687 /** 688 * Adds or remove the possiblity of scrolling through sections by using the mouse wheel or the trackpad. 689 */ 690 MS.setMouseWheelScrolling = function (value){ 691 if(value){ 692 addMouseWheelHandler(); 693 }else{ 694 removeMouseWheelHandler(); 695 } 696 }; 697 698 /** 699 * Defines the scrolling speed 700 */ 701 MS.setScrollingSpeed = function(value){ 702 options.scrollingSpeed = value; 703 }; 704 705 706 707 var touchStartY = 0; 708 var touchStartX = 0; 709 var touchEndY = 0; 710 var touchEndX = 0; 711 712 /* Detecting touch events 713 714 * As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it. 715 * This way, the touchstart and the touch moves shows an small difference between them which is the 716 * used one to determine the direction. 717 */ 718 function touchMoveHandler(event){ 719 var e = event.originalEvent; 720 721 if(isReallyTouch(e)){ 722 //preventing the easing on iOS devices 723 event.preventDefault(); 724 725 var activeSection = jQuery('.ms-left .ms-section.active'); 726 727 if (!isMoving) { //if theres any # 728 var touchEvents = getEventsPage(e); 729 touchEndY = touchEvents['y']; 730 touchEndX = touchEvents['x']; 731 732 733 //is the movement greater than the minimum resistance to scroll? 734 if (Math.abs(touchStartY - touchEndY) > (jQuery(window).height() / 100 * options.touchSensitivity)) { 735 736 if (touchStartY > touchEndY) { 737 MS.moveSectionDown(); 738 739 } else if (touchEndY > touchStartY) { 740 MS.moveSectionUp(); 741 } 742 } 743 } 744 } 745 } 746 747 /** 748 * As IE >= 10 fires both touch and mouse events when using a mouse in a touchscreen 749 * this way we make sure that is really a touch event what IE is detecting. 750 */ 751 function isReallyTouch(e){ 752 //if is not IE || IE is detecting `touch` or `pen` 753 return typeof e.pointerType === 'undefined' || e.pointerType != 'mouse'; 754 } 755 756 757 /** 758 * Handler to get he coordinates of the starting touch 759 */ 760 function touchStartHandler(event){ 761 var e = event.originalEvent; 762 763 if(isReallyTouch(e)){ 764 var touchEvents = getEventsPage(e); 765 touchStartY = touchEvents['y']; 766 touchStartX = touchEvents['x']; 767 } 768 } 769 770 771 /** 772 * Adds the possibility to auto scroll through sections on touch devices. 773 */ 774 function addTouchHandler(){ 775 if(isTouch){ 776 //Microsoft pointers 777 MSPointer = getMSPointer(); 778 779 jQuery(document).off('touchstart ' + MSPointer.down).on('touchstart ' + MSPointer.down, touchStartHandler); 780 jQuery(document).off('touchmove ' + MSPointer.move).on('touchmove ' + MSPointer.move, touchMoveHandler); 781 } 782 } 783 784 /** 785 * Removes the auto scrolling for touch devices. 786 */ 787 function removeTouchHandler(){ 788 if(isTouch){ 789 //Microsoft pointers 790 MSPointer = getMSPointer(); 791 792 jQuery(document).off('touchstart ' + MSPointer.down);
793 jQuery(document).off('touchmove ' + MSPointer.move); 794 } 795 } 796 797 /* 798 * Returns and object with Microsoft pointers (for IE<11 and for IE >= 11) 799 * http://msdn.microsoft.com/en-us/library/ie/dn304886(v=vs.85).aspx 800 */ 801 function getMSPointer(){ 802 var pointer; 803 804 //IE >= 11 805 if(window.PointerEvent){ 806 pointer = { down: "pointerdown", move: "pointermove"}; 807 } 808 809 //IE < 11 810 else{ 811 pointer = { down: "MSPointerDown", move: "MSPointerMove"}; 812 } 813 814 return pointer; 815 } 816 817 /** 818 * Gets the pageX and pageY properties depending on the browser. 819 * https://github.com/alvarotrigo/fullPage.js/issues/194#issuecomment-34069854 820 */ 821 function getEventsPage(e){ 822 var events = []; 823 824 events.y = (typeof e.pageY !== 'undefined' && (e.pageY || e.pageX) ? e.pageY : e.touches[0].pageY); 825 events.x = (typeof e.pageX !== 'undefined' && (e.pageY || e.pageX) ? e.pageX : e.touches[0].pageX); 826 827 //in touch devices with scrollBar:true, e.pageY is detected, but we have to deal with touch events. #1008 828 if(isTouch && isReallyTouch(e)){ 829 events.y = e.touches[0].pageY; 830 events.x = e.touches[0].pageX; 831 } 832 833 return events; 834 } 835 836 /** 837 * Destroy multiscroll.js plugin's events 838 */ 839 MS.destroy = function() { 840 MS.setKeyboardScrolling(false); 841 MS.setMouseWheelScrolling(false); 842 removeTouchHandler(); 843 844 jQuery(window) 845 .off('hashchange', hashChangeHandler) 846 .off('resize', doneResizing); 847 848 jQuery(document) 849 .off('mouseenter', '#multiscroll-nav li') 850 .off('mouseleave', '#multiscroll-nav li') 851 .off('click', '#multiscroll-nav a'); 852 }; 853 854 /** 855 * Build multiscroll.js plugin's events after destroy 856 */ 857 MS.build = function() { 858 MS.setKeyboardScrolling(true); 859 MS.setMouseWheelScrolling(true); 860 addTouchHandler(); 861 862 jQuery(window) 863 .on('hashchange', hashChangeHandler) 864 .on('resize', doneResizing); 865 866 jQuery(document) 867 .on('mouseenter', '#multiscroll-nav li', navMouseEnterHandler) 868 .on('mouseleave', '#multiscroll-nav li', navMouseLeaveHandler) 869 .on('click', '#multiscroll-nav a', navClickHandler); 870 }; 871 872 }; 873})(jQuery, window, document, Math);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.