Skip to content

Commit

Permalink
Update smooth-scroll.js to v16.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmistakes authored and jesuswasrasta committed Jul 8, 2020
1 parent 2656254 commit c213cb2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Enhancements

- Update smooth-scroll.js to `v16.1.2`. [#2430](https://github.com/mmistakes/minimal-mistakes/issues/2430)

## [4.19.0](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.19.0)

### Enhancements
Expand Down
5 changes: 1 addition & 4 deletions assets/js/main.min.js

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions assets/js/plugins/smooth-scroll.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* smooth-scroll v15.2.1
* smooth-scroll v16.1.2
* Animate scrolling to anchor links
* (c) 2019 Chris Ferdinandi
* (c) 2020 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/smooth-scroll
*/
Expand Down Expand Up @@ -90,7 +90,7 @@
* Check to see if user prefers reduced motion
* @param {Object} settings Script settings
*/
var reduceMotion = function (settings) {
var reduceMotion = function () {
if ('matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches) {
return true;
}
Expand Down Expand Up @@ -486,6 +486,12 @@
// Update the URL
updateURL(anchor, isNum, _settings);

// If the user prefers reduced motion, jump to location
if (reduceMotion()) {
window.scrollTo(0, Math.floor(endLocation));
return;
}

// Emit a custom event
emitEvent('scrollStart', _settings, anchor, toggle);

Expand All @@ -500,15 +506,16 @@
*/
var clickHandler = function (event) {

// Don't run if the user prefers reduced motion
if (reduceMotion(settings)) return;
// Don't run if event was canceled but still bubbled up
// By @mgreter - https://github.com/cferdinandi/smooth-scroll/pull/462/
if (event.defaultPrevented) return;

// Don't run if right-click or command/control + click
if (event.button !== 0 || event.metaKey || event.ctrlKey) return;
// Don't run if right-click or command/control + click or shift + click
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey) return;

// Check if event.target has closest() method
// By @totegi - https://github.com/cferdinandi/smooth-scroll/pull/401/
if(!('closest' in event.target))return;
if (!('closest' in event.target)) return;

// Check if a smooth scroll link was clicked
toggle = event.target.closest(selector);
Expand All @@ -518,10 +525,21 @@
if (toggle.hostname !== window.location.hostname || toggle.pathname !== window.location.pathname || !/#/.test(toggle.href)) return;

// Get an escaped version of the hash
var hash = escapeCharacters(toggle.hash);
var hash;
try {
hash = escapeCharacters(decodeURIComponent(toggle.hash));
} catch(e) {
hash = escapeCharacters(toggle.hash);
}

// Get the anchored element
var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
var anchor;
if (hash === '#') {
if (!settings.topOnEmptyHash) return;
anchor = document.documentElement;
} else {
anchor = document.querySelector(hash);
}
anchor = !anchor && hash === '#top' ? document.documentElement : anchor;

// If anchored element exists, scroll to it
Expand Down Expand Up @@ -589,7 +607,7 @@
* Initialize Smooth Scroll
* @param {Object} options User settings
*/
smoothScroll.init = function (options) {
var init = function () {

// feature test
if (!supports()) throw 'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.';
Expand All @@ -616,7 +634,7 @@
// Initialize plugin
//

smoothScroll.init(options);
init();


//
Expand Down
8 changes: 7 additions & 1 deletion docs/_docs/18-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ permalink: /docs/history/
excerpt: "Change log of enhancements and bug fixes made to the theme."
sidebar:
nav: docs
last_modified_at: 2020-03-10T19:02:48-04:00
last_modified_at: 2020-03-11T13:13:31-04:00
toc: false
---

## Unreleased

### Enhancements

- Update smooth-scroll.js to `v16.1.2`. [#2430](https://github.com/mmistakes/minimal-mistakes/issues/2430)

## [4.19.0](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.19.0)

### Enhancements
Expand Down

0 comments on commit c213cb2

Please sign in to comment.