Skip to content

Commit 87098ee

Browse files
committed
- Fixed bug: afterLoad always fires first index=1 even accessing the page on any other section alvarotrigo#2519
1 parent 21fd796 commit 87098ee

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

jquery.fullPage.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* fullPage 2.9.3
2+
* fullPage 2.9.4
33
* https://github.com/alvarotrigo/fullPage.js
44
* @license MIT licensed
55
*
@@ -206,6 +206,7 @@
206206
var canScroll = true;
207207
var scrollings = [];
208208
var controlPressed;
209+
var startingSection;
209210
var isScrollAllowed = {};
210211
isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
211212
isScrollAllowed.k = $.extend(true,{}, isScrollAllowed.m);
@@ -552,20 +553,9 @@
552553
options.scrollBar = options.scrollBar || options.hybrid;
553554

554555
setOptionsFromDOM();
555-
556556
prepareDom();
557557
setAllowScrolling(true);
558-
559558
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-
569559
responsive();
570560

571561
//setting the class for the body element
@@ -757,6 +747,7 @@
757747
if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
758748
section.addClass(ACTIVE);
759749
}
750+
startingSection = $(SECTION_ACTIVE_SEL);
760751

761752
section.css('height', windowsHeight + 'px');
762753

@@ -916,11 +907,21 @@
916907
lazyLoad(section);
917908
playMedia(section);
918909
options.scrollOverflowHandler.afterLoad();
910+
911+
if(isDestinyTheStartingSection()){
912+
$.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
913+
}
919914

920-
$.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
921915
$.isFunction( options.afterRender ) && options.afterRender.call(container);
922916
}
923917

918+
function isDestinyTheStartingSection(){
919+
var anchors = window.location.hash.replace('#', '').split('/');
920+
var destinationSection = getSectionByAnchor(decodeURIComponent(anchors[0]));
921+
922+
return !destinationSection.length || destinationSection.length && destinationSection.index() === startingSection.index();
923+
}
924+
924925

925926
var isScrolling = false;
926927
var lastScroll = 0;
@@ -2278,10 +2279,12 @@
22782279
* Gets a section by its anchor / index
22792280
*/
22802281
function getSectionByAnchor(sectionAnchor){
2282+
if(!sectionAnchor) return [];
2283+
22812284
//section
22822285
var section = container.find(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]');
22832286
if(!section.length){
2284-
section = $(SECTION_SEL).eq( (sectionAnchor -1) );
2287+
section = $(SECTION_SEL).eq( sectionAnchor -1);
22852288
}
22862289

22872290
return section;

0 commit comments

Comments
 (0)