|
1 | 1 | /*!
|
2 |
| - * fullPage 2.9.3 |
| 2 | + * fullPage 2.9.4 |
3 | 3 | * https://github.com/alvarotrigo/fullPage.js
|
4 | 4 | * @license MIT licensed
|
5 | 5 | *
|
|
108 | 108 |
|
109 | 109 | var FP = $.fn.fullpage;
|
110 | 110 |
|
111 |
| - // Create some defaults, extending them with any options that were provided |
| 111 | + // Creating some defaults, extending them with any options that were provided |
112 | 112 | options = $.extend({
|
113 | 113 | //navigation
|
114 | 114 | menu: false,
|
|
206 | 206 | var canScroll = true;
|
207 | 207 | var scrollings = [];
|
208 | 208 | var controlPressed;
|
| 209 | + var startingSection; |
209 | 210 | var isScrollAllowed = {};
|
210 | 211 | isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
|
211 | 212 | isScrollAllowed.k = $.extend(true,{}, isScrollAllowed.m);
|
|
534 | 535 | FP.moveTo = moveTo;
|
535 | 536 | FP.moveSlideRight = moveSlideRight;
|
536 | 537 | FP.moveSlideLeft = moveSlideLeft;
|
| 538 | + FP.fitToSection = fitToSection; |
537 | 539 | FP.reBuild = reBuild;
|
538 | 540 | FP.setResponsive = setResponsive;
|
539 | 541 | FP.destroy = destroy;
|
|
552 | 554 | options.scrollBar = options.scrollBar || options.hybrid;
|
553 | 555 |
|
554 | 556 | setOptionsFromDOM();
|
555 |
| - |
556 | 557 | prepareDom();
|
557 | 558 | setAllowScrolling(true);
|
558 |
| - |
559 | 559 | setAutoScrolling(options.autoScrolling, 'internal');
|
560 |
| - |
561 |
| - //the starting point is a slide? |
562 |
| - var activeSlide = $(SECTION_ACTIVE_SEL).find(SLIDE_ACTIVE_SEL); |
563 |
| - |
564 |
| - //the active section isn't the first one? Is not the first slide of the first section? Then we load that section/slide by default. |
565 |
| - if( activeSlide.length && ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) !== 0 || ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) === 0 && activeSlide.index() !== 0))){ |
566 |
| - silentLandscapeScroll(activeSlide); |
567 |
| - } |
568 |
| - |
569 | 560 | responsive();
|
570 | 561 |
|
571 | 562 | //setting the class for the body element
|
|
743 | 734 | //if the slide won't be an starting point, the default will be the first one
|
744 | 735 | //the active section isn't the first one? Is not the first slide of the first section? Then we load that section/slide by default.
|
745 | 736 | if( startingSlide.length && ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) !== 0 || ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) === 0 && startingSlide.index() !== 0))){
|
746 |
| - silentLandscapeScroll(startingSlide); |
| 737 | + silentLandscapeScroll(startingSlide, 'internal'); |
747 | 738 | }else{
|
748 | 739 | slides.eq(0).addClass(ACTIVE);
|
749 | 740 | }
|
|
757 | 748 | if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
|
758 | 749 | section.addClass(ACTIVE);
|
759 | 750 | }
|
| 751 | + startingSection = $(SECTION_ACTIVE_SEL); |
760 | 752 |
|
761 | 753 | section.css('height', windowsHeight + 'px');
|
762 | 754 |
|
|
916 | 908 | lazyLoad(section);
|
917 | 909 | playMedia(section);
|
918 | 910 | options.scrollOverflowHandler.afterLoad();
|
| 911 | + |
| 912 | + if(isDestinyTheStartingSection()){ |
| 913 | + $.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1)); |
| 914 | + } |
919 | 915 |
|
920 |
| - $.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1)); |
921 | 916 | $.isFunction( options.afterRender ) && options.afterRender.call(container);
|
922 | 917 | }
|
923 | 918 |
|
| 919 | + /** |
| 920 | + * Determines if the URL anchor destiny is the starting section (the one using 'active' class before initialization) |
| 921 | + */ |
| 922 | + function isDestinyTheStartingSection(){ |
| 923 | + var anchors = window.location.hash.replace('#', '').split('/'); |
| 924 | + var destinationSection = getSectionByAnchor(decodeURIComponent(anchors[0])); |
| 925 | + |
| 926 | + return !destinationSection.length || destinationSection.length && destinationSection.index() === startingSection.index(); |
| 927 | + } |
| 928 | + |
924 | 929 |
|
925 | 930 | var isScrolling = false;
|
926 | 931 | var lastScroll = 0;
|
|
1017 | 1022 | clearTimeout(scrollId2);
|
1018 | 1023 |
|
1019 | 1024 | scrollId2 = setTimeout(function(){
|
1020 |
| - //checking fitToSection again in case it was set to false before the timeout delay |
1021 |
| - if(canScroll && options.fitToSection){ |
1022 |
| - //allows to scroll to an active section and |
1023 |
| - //if the section is already active, we prevent firing callbacks |
1024 |
| - if($(SECTION_ACTIVE_SEL).is(currentSection)){ |
1025 |
| - isResizing = true; |
1026 |
| - } |
1027 |
| - scrollPage($(SECTION_ACTIVE_SEL)); |
1028 |
| - |
1029 |
| - isResizing = false; |
| 1025 | + //checking it again in case it changed during the delay |
| 1026 | + if(options.fitToSection){ |
| 1027 | + fitToSection(); |
1030 | 1028 | }
|
1031 | 1029 | }, options.fitToSectionDelay);
|
1032 | 1030 | }
|
1033 | 1031 | }
|
1034 | 1032 | }
|
1035 | 1033 |
|
| 1034 | + /** |
| 1035 | + * Fits the site to the nearest active section |
| 1036 | + */ |
| 1037 | + function fitToSection(){ |
| 1038 | + //checking fitToSection again in case it was set to false before the timeout delay |
| 1039 | + if(canScroll){ |
| 1040 | + //allows to scroll to an active section and |
| 1041 | + //if the section is already active, we prevent firing callbacks |
| 1042 | + isResizing = true; |
| 1043 | + |
| 1044 | + scrollPage($(SECTION_ACTIVE_SEL)); |
| 1045 | + isResizing = false; |
| 1046 | + } |
| 1047 | + } |
| 1048 | + |
1036 | 1049 | /**
|
1037 | 1050 | * Determines whether the active section has seen in its whole or not.
|
1038 | 1051 | */
|
|
1435 | 1448 | }
|
1436 | 1449 | }
|
1437 | 1450 |
|
1438 |
| - stopMedia(v.activeSection); |
| 1451 | + //pausing media of the leaving section (if we are not just resizing, as destinatino will be the same one) |
| 1452 | + if(!v.localIsResizing){ |
| 1453 | + stopMedia(v.activeSection); |
| 1454 | + } |
1439 | 1455 |
|
1440 | 1456 | options.scrollOverflowHandler.beforeLeave();
|
1441 | 1457 | element.addClass(ACTIVE).siblings().removeClass(ACTIVE);
|
|
1599 | 1615 | $.isFunction(v.callback) && v.callback.call(this);
|
1600 | 1616 | }
|
1601 | 1617 |
|
| 1618 | + /** |
| 1619 | + * Sets the value for the given attribute from the `data-` attribute with the same suffix |
| 1620 | + * ie: data-srcset ==> srcset | data-src ==> src |
| 1621 | + */ |
| 1622 | + function setSrc(element, attribute){ |
| 1623 | + element |
| 1624 | + .attr(attribute, element.data(attribute)) |
| 1625 | + .removeAttr('data-' + attribute); |
| 1626 | + } |
| 1627 | + |
1602 | 1628 | /**
|
1603 | 1629 | * Lazy loads image, video and audio elements.
|
1604 | 1630 | */
|
|
1609 | 1635 |
|
1610 | 1636 | var panel = getSlideOrSection(destiny);
|
1611 | 1637 | var element;
|
1612 |
| - |
1613 |
| - panel.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){ |
| 1638 | + |
| 1639 | + panel.find('img[data-src], img[data-srcset], source[data-src], audio[data-src], iframe[data-src]').each(function(){ |
1614 | 1640 | element = $(this);
|
1615 |
| - element.attr('src', element.data('src')); |
1616 |
| - element.removeAttr('data-src'); |
| 1641 | + |
| 1642 | + $.each(['src', 'srcset'], function(index, type){ |
| 1643 | + var attribute = element.attr('data-' + type); |
| 1644 | + if(typeof attribute !== 'undefined' && attribute){ |
| 1645 | + setSrc(element, type); |
| 1646 | + } |
| 1647 | + }); |
1617 | 1648 |
|
1618 | 1649 | if(element.is('source')){
|
1619 | 1650 | element.closest('video').get(0).load();
|
|
1979 | 2010 | }
|
1980 | 2011 |
|
1981 | 2012 | //only changing the URL if the slides are in the current section (not for resize re-adjusting)
|
1982 |
| - if(section.hasClass(ACTIVE)){ |
| 2013 | + if(section.hasClass(ACTIVE) && !v.localIsResizing){ |
1983 | 2014 | setState(v.slideIndex, v.slideAnchor, v.anchorLink, v.sectionIndex);
|
1984 | 2015 | }
|
1985 | 2016 |
|
|
2278 | 2309 | * Gets a section by its anchor / index
|
2279 | 2310 | */
|
2280 | 2311 | function getSectionByAnchor(sectionAnchor){
|
2281 |
| - //section |
| 2312 | + if(!sectionAnchor) return []; |
| 2313 | + |
2282 | 2314 | var section = container.find(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]');
|
2283 | 2315 | if(!section.length){
|
2284 |
| - section = $(SECTION_SEL).eq( (sectionAnchor -1) ); |
| 2316 | + section = $(SECTION_SEL).eq( sectionAnchor -1); |
2285 | 2317 | }
|
2286 | 2318 |
|
2287 | 2319 | return section;
|
|
2740 | 2772 |
|
2741 | 2773 | //loading all the lazy load content
|
2742 | 2774 | container.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){
|
2743 |
| - $(this).attr('src', $(this).data('src')); |
2744 |
| - $(this).removeAttr('data-src'); |
| 2775 | + setSrc($(this), 'src'); |
| 2776 | + }); |
| 2777 | + |
| 2778 | + container.find('img[data-srcset]').each(function(){ |
| 2779 | + setSrc($(this), 'srcset'); |
2745 | 2780 | });
|
2746 | 2781 |
|
2747 | 2782 | $(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL).remove();
|
|
0 commit comments