-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Reverting fitToSection from CSS Snaps to custom JS
- Loading branch information
1 parent
30beb1b
commit 614dcf4
Showing
17 changed files
with
41 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,29 @@ | ||
import * as utils from './common/utils.js'; | ||
import { setVariableState } from './common/options.js'; | ||
import { getOptions } from './common/options.js'; | ||
import { $html } from './common/cache.js'; | ||
import { doc, FP } from './common/constants.js'; | ||
import { | ||
SNAPS | ||
} from './common/selectors.js'; | ||
import { FP } from './common/constants.js'; | ||
import { setState, state } from './common/state.js'; | ||
import { scrollPage } from './scroll/scrollPage.js'; | ||
|
||
FP.setFitToSection = setFitToSection; | ||
FP.fitToSection = fitToSection; | ||
|
||
export const g_isCssSnapsSupported = (function(){ | ||
return isCssSnapsSupported(); | ||
})(); | ||
|
||
/** | ||
* Sets fitToSection | ||
*/ | ||
export function setFitToSection(value, type){ | ||
toggleCssSnapsWhenPossible(value); | ||
setVariableState('fitToSection', value, type); | ||
} | ||
|
||
|
||
/** | ||
* Adds or removes CSS snaps scrolling behaviour depending on the given value. | ||
*/ | ||
export function toggleCssSnapsWhenPossible(value){ | ||
if(g_isCssSnapsSupported){ | ||
var canAddSnaps = getOptions().fitToSection && (!getOptions().autoScrolling || getOptions().scrollBar) && value; | ||
var toggleFunction = canAddSnaps ? utils.addClass : utils.removeClass; | ||
toggleFunction($html, SNAPS); | ||
} | ||
} | ||
|
||
/** | ||
* Checks for CSS scroll snaps support. | ||
*/ | ||
function isCssSnapsSupported(){ | ||
var style = doc.documentElement.style; | ||
|
||
return 'scrollSnapAlign' in style || | ||
'webkitScrollSnapAlign' in style || | ||
'msScrollSnapAlign' in style; | ||
} | ||
|
||
/** | ||
* Fits the site to the nearest active section | ||
*/ | ||
export function fitToSection(){ | ||
// //checking fitToSection again in case it was set to false before the timeout delay | ||
// if(canScroll){ | ||
// //allows to scroll to an active section and | ||
// //if the section is already active, we prevent firing callbacks | ||
// isResizing = true; | ||
|
||
// scrollPage(state.activeSection); | ||
// isResizing = false; | ||
// } | ||
//checking fitToSection again in case it was set to false before the timeout delay | ||
if(state.canScroll){ | ||
//allows to scroll to an active section and | ||
//if the section is already active, we prevent firing callbacks | ||
setState({isResizing: true}); | ||
|
||
scrollPage(state.activeSection); | ||
setState({isResizing: false}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters