Skip to content

Commit c2d3fb5

Browse files
authored
Merge pull request alvarotrigo#2607 from alvarotrigo/dev
Merging dev branch 2.9.4
2 parents 83997c2 + 37bfeb7 commit c2d3fb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+423
-101
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<p align="center">
66
<a href="https://github.com/alvarotrigo/fullPage.js"><img src="https://raw.githubusercontent.com/alvarotrigo/fullPage.js/dev/examples/imgs/en-language.png" /></a><a href="https://github.com/alvarotrigo/fullPage.js/blob/dev/README_SPANISH.md#fullpagejs"><img src="https://raw.githubusercontent.com/alvarotrigo/fullPage.js/dev/examples/imgs/es-language-inactive.png" /></a>
77
</p>
8-
![fullPage.js version](http://img.shields.io/badge/fullPage.js-v2.9.3-brightgreen.svg)
8+
![fullPage.js version](http://img.shields.io/badge/fullPage.js-v2.9.4-brightgreen.svg)
99
[![License](http://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
1010
[![PayPal Donate](https://img.shields.io/badge/donate-PayPal.me-ff69b4.svg)](https://www.paypal.me/alvarotrigo/9.95)
1111
&nbsp;&nbsp; **|**&nbsp;&nbsp; *7Kb gziped* &nbsp;&nbsp;**|**&nbsp;&nbsp; *Created by [@imac2](https://twitter.com/imac2)*
@@ -545,6 +545,14 @@ Sets the value for the option `fitToSection` determining whether to fit the sect
545545
$.fn.fullpage.setFitToSection(false);
546546
```
547547
---
548+
### fitToSection()
549+
[Demo](http://codepen.io/alvarotrigo/pen/JWWagj)
550+
Scrolls to the nearest active section fitting it in the viewport.
551+
552+
```javascript
553+
$.fn.fullpage.fitToSection();
554+
```
555+
---
548556
### setLockAnchors(boolean)
549557
[Demo](http://codepen.io/alvarotrigo/pen/yNxVRQ)
550558
Sets the value for the option `lockAnchors` determining whether anchors will have any effect in the URL or not.

README_SPANISH.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<p align="center">
77
<a href="https://github.com/alvarotrigo/fullPage.js"><img src="https://raw.githubusercontent.com/alvarotrigo/fullPage.js/dev/examples/imgs/en-language-inactive.png" /></a><a href="https://github.com/alvarotrigo/fullPage.js/blob/dev/README_SPANISH.md#fullpagejs"><img src="https://raw.githubusercontent.com/alvarotrigo/fullPage.js/dev/examples/imgs/es-language.png?v=2" /></a>
88
</p>
9-
![fullPage.js version](http://img.shields.io/badge/fullPage.js-v2.9.3-brightgreen.svg)
9+
![fullPage.js version](http://img.shields.io/badge/fullPage.js-v2.9.4-brightgreen.svg)
1010
[![License](http://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
1111
[![PayPal Donate](https://img.shields.io/badge/donate-PayPal.me-ff69b4.svg)](https://www.paypal.me/alvarotrigo/9.95)
1212
&nbsp;&nbsp; **|**&nbsp;&nbsp; *7Kb gziped* &nbsp;&nbsp;**|**&nbsp;&nbsp; *Created by [@imac2](https://twitter.com/imac2)*
@@ -532,12 +532,20 @@ $.fn.fullpage.setAutoScrolling(false);
532532
---
533533
### setFitToSection(boolean)
534534
[demostración](http://codepen.io/alvarotrigo/pen/GJXNYm)
535-
Sets the value for the option `fitToSection` determining whether to fit the section in the screen or not.
535+
Determina el valor para la opción `fitToSection` definiendo si ajustar la sección más cercana a la pantalla o no.
536536

537537
```javascript
538538
$.fn.fullpage.setFitToSection(false);
539539
```
540540
---
541+
### fitToSection()
542+
[demostración](http://codepen.io/alvarotrigo/pen/JWWagj)
543+
Desplaza la página hacia la sección activa más cercana encajándola en la pantalla.
544+
545+
```javascript
546+
$.fn.fullpage.fitToSection();
547+
```
548+
---
541549
### setLockAnchors(boolean)
542550
[demostración](http://codepen.io/alvarotrigo/pen/yNxVRQ)
543551
Define el valor para la opción `lockAnchors` determinando si los links de anclaje tendrán algún efecto en la URL o no.

dist/jquery.fullpage.css

+1-1
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
* MIT licensed
55
*

dist/jquery.fullpage.extensions.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.fullpage.js

+70-35
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
*
@@ -108,7 +108,7 @@
108108

109109
var FP = $.fn.fullpage;
110110

111-
// Create some defaults, extending them with any options that were provided
111+
// Creating some defaults, extending them with any options that were provided
112112
options = $.extend({
113113
//navigation
114114
menu: false,
@@ -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);
@@ -534,6 +535,7 @@
534535
FP.moveTo = moveTo;
535536
FP.moveSlideRight = moveSlideRight;
536537
FP.moveSlideLeft = moveSlideLeft;
538+
FP.fitToSection = fitToSection;
537539
FP.reBuild = reBuild;
538540
FP.setResponsive = setResponsive;
539541
FP.destroy = destroy;
@@ -552,20 +554,9 @@
552554
options.scrollBar = options.scrollBar || options.hybrid;
553555

554556
setOptionsFromDOM();
555-
556557
prepareDom();
557558
setAllowScrolling(true);
558-
559559
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-
569560
responsive();
570561

571562
//setting the class for the body element
@@ -743,7 +734,7 @@
743734
//if the slide won't be an starting point, the default will be the first one
744735
//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.
745736
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');
747738
}else{
748739
slides.eq(0).addClass(ACTIVE);
749740
}
@@ -757,6 +748,7 @@
757748
if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
758749
section.addClass(ACTIVE);
759750
}
751+
startingSection = $(SECTION_ACTIVE_SEL);
760752

761753
section.css('height', windowsHeight + 'px');
762754

@@ -916,11 +908,24 @@
916908
lazyLoad(section);
917909
playMedia(section);
918910
options.scrollOverflowHandler.afterLoad();
911+
912+
if(isDestinyTheStartingSection()){
913+
$.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
914+
}
919915

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

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+
924929

925930
var isScrolling = false;
926931
var lastScroll = 0;
@@ -1017,22 +1022,30 @@
10171022
clearTimeout(scrollId2);
10181023

10191024
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();
10301028
}
10311029
}, options.fitToSectionDelay);
10321030
}
10331031
}
10341032
}
10351033

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+
10361049
/**
10371050
* Determines whether the active section has seen in its whole or not.
10381051
*/
@@ -1435,7 +1448,10 @@
14351448
}
14361449
}
14371450

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+
}
14391455

14401456
options.scrollOverflowHandler.beforeLeave();
14411457
element.addClass(ACTIVE).siblings().removeClass(ACTIVE);
@@ -1599,6 +1615,16 @@
15991615
$.isFunction(v.callback) && v.callback.call(this);
16001616
}
16011617

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+
16021628
/**
16031629
* Lazy loads image, video and audio elements.
16041630
*/
@@ -1609,11 +1635,16 @@
16091635

16101636
var panel = getSlideOrSection(destiny);
16111637
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(){
16141640
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+
});
16171648

16181649
if(element.is('source')){
16191650
element.closest('video').get(0).load();
@@ -1979,7 +2010,7 @@
19792010
}
19802011

19812012
//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){
19832014
setState(v.slideIndex, v.slideAnchor, v.anchorLink, v.sectionIndex);
19842015
}
19852016

@@ -2278,10 +2309,11 @@
22782309
* Gets a section by its anchor / index
22792310
*/
22802311
function getSectionByAnchor(sectionAnchor){
2281-
//section
2312+
if(!sectionAnchor) return [];
2313+
22822314
var section = container.find(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]');
22832315
if(!section.length){
2284-
section = $(SECTION_SEL).eq( (sectionAnchor -1) );
2316+
section = $(SECTION_SEL).eq( sectionAnchor -1);
22852317
}
22862318

22872319
return section;
@@ -2740,8 +2772,11 @@
27402772

27412773
//loading all the lazy load content
27422774
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');
27452780
});
27462781

27472782
$(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL).remove();

dist/jquery.fullpage.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)