\ No newline at end of file
diff --git a/src/js/smooth-scroll.js b/src/js/smooth-scroll.js
index 7e83b2c..f9b751d 100755
--- a/src/js/smooth-scroll.js
+++ b/src/js/smooth-scroll.js
@@ -1,9 +1,9 @@
(function (root, factory) {
- if ( typeof define === 'function' && define.amd ) {
+ if (typeof define === 'function' && define.amd) {
define([], function () {
return factory(root);
});
- } else if ( typeof exports === 'object' ) {
+ } else if (typeof exports === 'object') {
module.exports = factory(root);
} else {
root.SmoothScroll = factory(root);
@@ -31,6 +31,7 @@
// Selectors
ignore: '[data-scroll-ignore]',
header: null,
+ topOnEmptyHash: true,
// Speed & Easing
speed: 500,
@@ -38,6 +39,10 @@
easing: 'easeInOutCubic',
customEasing: null,
+ // History
+ updateURL: true,
+ popstate: true,
+
// Callback API
before: function () {},
after: function () {}
@@ -57,8 +62,6 @@
// Variables
var extended = {};
- var i = 0;
- var length = arguments.length;
// Merge the object into the extended object
var merge = function (obj) {
@@ -70,15 +73,25 @@
};
// Loop through each object and conduct a merge
- for ( ; i < length; i++ ) {
- var obj = arguments[i];
- merge(obj);
+ for (var i = 0; i < arguments.length; i++) {
+ merge(arguments[i]);
}
return extended;
};
+ /**
+ * Check to see if user prefers reduced motion
+ * @param {Object} settings Script settings
+ */
+ var reduceMotion = function (settings) {
+ if ('matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches) {
+ return true;
+ }
+ return false;
+ };
+
/**
* Get the height of an element.
* @param {Node} elem The element to get the height of
@@ -88,11 +101,26 @@
return parseInt(window.getComputedStyle(elem).height, 10);
};
+ /**
+ * Decode a URI, with error check
+ * @param {String} hash The URI to decode
+ * @return {String} A decoded URI (or the original string if an error is thrown)
+ */
+ var decode = function (hash) {
+ var decoded;
+ try {
+ decoded = decodeURIComponent(hash);
+ } catch(e) {
+ decoded = hash;
+ }
+ return decoded;
+ };
+
/**
* Escape special characters for use with querySelector
- * @param {String} id The anchor ID to escape
* @author Mathias Bynens
* @link https://github.com/mathiasbynens/CSS.escape
+ * @param {String} id The anchor ID to escape
*/
var escapeCharacters = function (id) {
@@ -163,7 +191,14 @@
}
- return '#' + result;
+ // Return sanitized hash
+ var hash;
+ try {
+ hash = decodeURIComponent('#' + result);
+ } catch(e) {
+ hash = '#' + result;
+ }
+ return hash;
};
@@ -259,15 +294,21 @@
};
- /**
- * Check to see if user prefers reduced motion
- * @param {Object} settings Script settings
- */
- var reduceMotion = function (settings) {
- if ('matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches) {
- return true;
- }
- return false;
+ var updateURL = function (anchor, options) {
+
+ // Verify that pushState is supported and the updateURL option is enabled
+ if (!history.pushState || !options.updateURL) return;
+
+ // Update URL
+ history.pushState(
+ {
+ smoothScroll: JSON.stringify(options),
+ anchor: anchor.id
+ },
+ document.title,
+ anchor === 0 ? '#top' : '#' + anchor.id
+ );
+
};
@@ -293,8 +334,8 @@
* Cancel a scroll-in-progress
*/
smoothScroll.cancelScroll = function () {
- // clearInterval(animationInterval);
cancelAnimationFrame(animationInterval);
+ animationInterval = null;
};
/**
@@ -315,7 +356,7 @@
var startLocation = window.pageYOffset; // Current location on the page
if (animateSettings.header && !fixedHeader) {
// Get the fixed header if not already set
- fixedHeader = document.querySelector( animateSettings.header );
+ fixedHeader = document.querySelector(animateSettings.header);
}
if (!headerHeight) {
// Get the height of a fixed header if one exists and not already set
@@ -339,7 +380,7 @@
var currentLocation = window.pageYOffset;
// Check if the end location has been reached yet (or we've hit the end of the document)
- if ( position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight )) {
+ if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
smoothScroll.cancelScroll();
@@ -352,6 +393,7 @@
// Reset start
start = null;
+ animationInterval = null;
return true;
@@ -369,7 +411,7 @@
position = startLocation + (distance * easingPattern(animateSettings, percentage));
window.scrollTo(0, Math.floor(position));
if (!stopAnimateScroll(position, endLocation)) {
- window.requestAnimationFrame(loopAnimateScroll);
+ animationInterval = window.requestAnimationFrame(loopAnimateScroll);
start = timestamp;
}
};
@@ -379,37 +421,19 @@
* @link https://github.com/cferdinandi/smooth-scroll/issues/45
*/
if (window.pageYOffset === 0) {
- window.scrollTo( 0, 0 );
+ window.scrollTo(0, 0);
}
// Run callback before animation starts
animateSettings.before(anchor, toggle);
+ // Update the URL
+ updateURL(anchor, animateSettings);
+
// Start scrolling animation
smoothScroll.cancelScroll();
window.requestAnimationFrame(loopAnimateScroll);
-
- };
-
- /**
- * Handle has change event
- */
- var hashChangeHandler = function (event) {
-
- // Only run if there's an anchor element to scroll to
- if (!anchor) return;
-
- // Reset the anchor element's ID
- anchor.id = anchor.getAttribute('data-scroll-id');
-
- // Scroll to the anchored content
- smoothScroll.animateScroll(anchor, toggle);
-
- // Reset anchor and toggle
- anchor = null;
- toggle = null;
-
};
/**
@@ -430,35 +454,17 @@
// Only run if link is an anchor and points to the current page
if (toggle.hostname !== window.location.hostname || toggle.pathname !== window.location.pathname || !/#/.test(toggle.href)) return;
- // Get the sanitized hash
- var hash;
- try {
- hash = escapeCharacters(decodeURIComponent(toggle.hash));
- } catch(e) {
- hash = escapeCharacters(toggle.hash);
- }
+ // Get an escaped version of the hash
+ var hash = escapeCharacters(decode(toggle.hash));
// If the hash is empty, scroll to the top of the page
- if (hash === '#') {
+ if (settings.topOnEmptyHash && ['#', '#top'].indexOf(hash) !== -1) {
// Prevent default link behavior
event.preventDefault();
- // Set the anchored element
- anchor = document.body;
-
- // Save or create the ID as a data attribute and remove it (prevents scroll jump)
- var id = anchor.id ? anchor.id : 'smooth-scroll-top';
- anchor.setAttribute('data-scroll-id', id);
- anchor.id = '';
-
- // If no hash change event will happen, fire manually
- // Otherwise, update the hash
- if (window.location.hash.substring(1) === id) {
- hashChangeHandler();
- } else {
- window.location.hash = id;
- }
+ // Scroll to the top of the page
+ smoothScroll.animateScroll(0, toggle);
return;
@@ -467,16 +473,30 @@
// Get the anchored element
anchor = document.querySelector(hash);
- // If anchored element exists, save the ID as a data attribute and remove it (prevents scroll jump)
+ // If anchored element exists, scroll to it
if (!anchor) return;
- anchor.setAttribute('data-scroll-id', anchor.id);
- anchor.id = '';
+ event.preventDefault();
+ smoothScroll.animateScroll(anchor, toggle);
- // If no hash change event will happen, fire manually
- if (toggle.hash === window.location.hash) {
- event.preventDefault();
- hashChangeHandler();
- }
+ };
+
+ /**
+ * Animate scroll on popstate events
+ */
+ var popstateHandler = function (event) {
+
+ // Only run if state is a popstate record for this instantiation
+ if (!history.state.smoothScroll || history.state.smoothScroll !== JSON.stringify(settings)) return;
+
+ // Only run if state includes an anchor
+ if (!history.state.anchor) return;
+
+ // Get the anchor
+ var anchor = document.querySelector(escapeCharacters(decode(history.state.anchor)));
+ if (!anchor) return;
+
+ // Animate scroll to anchor link
+ smoothScroll.animateScroll(anchor, null, {updateURL: false});
};
@@ -503,6 +523,7 @@
// Remove event listeners
document.removeEventListener('click', clickHandler, false);
window.removeEventListener('resize', resizeThrottler, false);
+ window.removeEventListener('popstate', popstateHandler, false);
// Cancel any scrolls-in-progress
smoothScroll.cancelScroll();
@@ -515,6 +536,7 @@
headerHeight = null;
eventTimeout = null;
animationInterval = null;
+
};
/**
@@ -537,14 +559,16 @@
// When a toggle is clicked, run the click handler
document.addEventListener('click', clickHandler, false);
- // Listen for hash changes
- window.addEventListener('hashchange', hashChangeHandler, false);
-
// If window is resized and there's a fixed header, recalculate its size
if (fixedHeader) {
window.addEventListener('resize', resizeThrottler, false);
}
+ // If updateURL and popState are enabled, listen for pop events
+ if (settings.updateURL && settings.popstate) {
+ window.addEventListener('popstate', popstateHandler, false);
+ }
+
};
From b768cf9c851bee1ae0e8cb7228d2c362b2711b4d Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 19:38:26 -0400
Subject: [PATCH 03/51] v14.0.0: WIP Added feature test and option for custom
events
---
dist/js/smooth-scroll.js | 46 +++++++++++----
dist/js/smooth-scroll.min.js | 2 +-
dist/js/smooth-scroll.polyfills.js | 65 +++++++++++++++++----
dist/js/smooth-scroll.polyfills.min.js | 2 +-
docs/dist/js/smooth-scroll.js | 46 +++++++++++----
docs/dist/js/smooth-scroll.min.js | 2 +-
docs/dist/js/smooth-scroll.polyfills.js | 65 +++++++++++++++++----
docs/dist/js/smooth-scroll.polyfills.min.js | 2 +-
docs/index.html | 49 +++++++++-------
src/docs/_templates/_footer.html | 49 +++++++++-------
src/js/_customEvent.polyfill.js | 19 ++++++
src/js/smooth-scroll.js | 46 +++++++++++----
12 files changed, 294 insertions(+), 99 deletions(-)
create mode 100644 src/js/_customEvent.polyfill.js
diff --git a/dist/js/smooth-scroll.js b/dist/js/smooth-scroll.js
index 7e0602e..3c57b41 100755
--- a/dist/js/smooth-scroll.js
+++ b/dist/js/smooth-scroll.js
@@ -50,9 +50,8 @@
updateURL: true,
popstate: true,
- // Callback API
- before: function () {},
- after: function () {}
+ // Custom Events
+ emitEvents: true
};
@@ -301,6 +300,11 @@
};
+ /**
+ * Update the URL
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Object} options Settings for Smooth Scroll
+ */
var updateURL = function (anchor, options) {
// Verify that pushState is supported and the updateURL option is enabled
@@ -318,6 +322,24 @@
};
+ /**
+ * Emit a custom event
+ * @todo feature test before emitting
+ * @todo make optional with a setting
+ * @param {String} type The event type
+ */
+ var emitEvent = function (type, anchor, toggle, options) {
+ if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
+ var event = new CustomEvent(type, {
+ bubbles: true,
+ detail: {
+ anchor: anchor,
+ toggle: toggle
+ }
+ });
+ document.dispatchEvent(event);
+ };
+
//
// SmoothScroll Constructor
@@ -340,9 +362,11 @@
/**
* Cancel a scroll-in-progress
*/
- smoothScroll.cancelScroll = function () {
+ smoothScroll.cancelScroll = function (noEvent) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
+ if (noEvent) return;
+ emitEvent('scrollCancel');
};
/**
@@ -390,13 +414,13 @@
if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
// Bring the anchored element into focus
adjustFocus(anchor, endLocation, isNum);
- // Run callback after animation complete
- animateSettings.after(anchor, toggle);
+ // Emit a custom event
+ emitEvent('scrollStop', anchor, toggle);
// Reset start
start = null;
@@ -431,14 +455,14 @@
window.scrollTo(0, 0);
}
- // Run callback before animation starts
- animateSettings.before(anchor, toggle);
-
// Update the URL
updateURL(anchor, animateSettings);
+ // Emit a custom event
+ emitEvent('scrollStart', anchor, toggle);
+
// Start scrolling animation
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
window.requestAnimationFrame(loopAnimateScroll);
};
diff --git a/dist/js/smooth-scroll.min.js b/dist/js/smooth-scroll.min.js
index 2f6e242..f4279e6 100755
--- a/dist/js/smooth-scroll.min.js
+++ b/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,before:function(){},after:function(){}},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)};return function(a,h){var p,g,y,v,S,b,O,E={};E.cancelScroll=function(){cancelAnimationFrame(O),O=null},E.animateScroll=function(t,r,a){var i=o(p||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),h=u||!t.tagName?null:t;if(u||h){var g=e.pageYOffset;i.header&&!v&&(v=document.querySelector(i.header)),S||(S=f(v));var y,b,I,L=u?t:l(h,S,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),C=L-g,A=s(),w=0,H=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(g=A)return E.cancelScroll(),d(t,o,u),i.after(t,r),y=null,O=null,!0},Q=function(t){y||(y=t),w+=t-y,b=w/parseInt(i.speed,10),b=b>1?1:b,I=g+C*c(i,b),e.scrollTo(0,Math.floor(I)),H(I,L)||(O=e.requestAnimationFrame(Q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),i.before(t,r),m(t,i),E.cancelScroll(),e.requestAnimationFrame(Q)}};var I=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(p.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(p.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void E.animateScroll(0,y);g=document.querySelector(n),g&&(t.preventDefault(),E.animateScroll(g,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(p)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&E.animateScroll(t,null,{updateURL:!1})}},C=function(e){b||(b=setTimeout((function(){b=null,S=f(v)}),66))};return E.destroy=function(){p&&(document.removeEventListener("click",I,!1),e.removeEventListener("resize",C,!1),e.removeEventListener("popstate",L,!1),E.cancelScroll(),p=null,g=null,y=null,v=null,S=null,b=null,O=null)},E.init=function(r){t&&(E.destroy(),p=o(n,r||{}),v=p.header?document.querySelector(p.header):null,S=f(v),document.addEventListener("click",I,!1),v&&e.addEventListener("resize",C,!1),p.updateURL&&p.popstate&&e.addEventListener("popstate",L,!1))},E.init(h),E}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(r.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel")},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/dist/js/smooth-scroll.polyfills.js b/dist/js/smooth-scroll.polyfills.js
index ffcb742..baddb6f 100755
--- a/dist/js/smooth-scroll.polyfills.js
+++ b/dist/js/smooth-scroll.polyfills.js
@@ -22,6 +22,25 @@ if (window.Element && !Element.prototype.closest) {
};
}
+/**
+ * CustomEvent() polyfill
+ * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
+ */
+(function () {
+
+ if (typeof window.CustomEvent === "function") return false;
+
+ function CustomEvent(event, params) {
+ params = params || { bubbles: false, cancelable: false, detail: undefined };
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
+ return evt;
+ }
+
+ CustomEvent.prototype = window.Event.prototype;
+
+ window.CustomEvent = CustomEvent;
+})();
/**
* requestAnimationFrame() polyfill
* By Erik Möller. Fixes from Paul Irish and Tino Zijdel.
@@ -101,9 +120,8 @@ if (window.Element && !Element.prototype.closest) {
updateURL: true,
popstate: true,
- // Callback API
- before: function () {},
- after: function () {}
+ // Custom Events
+ emitEvents: true
};
@@ -352,6 +370,11 @@ if (window.Element && !Element.prototype.closest) {
};
+ /**
+ * Update the URL
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Object} options Settings for Smooth Scroll
+ */
var updateURL = function (anchor, options) {
// Verify that pushState is supported and the updateURL option is enabled
@@ -369,6 +392,24 @@ if (window.Element && !Element.prototype.closest) {
};
+ /**
+ * Emit a custom event
+ * @todo feature test before emitting
+ * @todo make optional with a setting
+ * @param {String} type The event type
+ */
+ var emitEvent = function (type, anchor, toggle, options) {
+ if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
+ var event = new CustomEvent(type, {
+ bubbles: true,
+ detail: {
+ anchor: anchor,
+ toggle: toggle
+ }
+ });
+ document.dispatchEvent(event);
+ };
+
//
// SmoothScroll Constructor
@@ -391,9 +432,11 @@ if (window.Element && !Element.prototype.closest) {
/**
* Cancel a scroll-in-progress
*/
- smoothScroll.cancelScroll = function () {
+ smoothScroll.cancelScroll = function (noEvent) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
+ if (noEvent) return;
+ emitEvent('scrollCancel');
};
/**
@@ -441,13 +484,13 @@ if (window.Element && !Element.prototype.closest) {
if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
// Bring the anchored element into focus
adjustFocus(anchor, endLocation, isNum);
- // Run callback after animation complete
- animateSettings.after(anchor, toggle);
+ // Emit a custom event
+ emitEvent('scrollStop', anchor, toggle);
// Reset start
start = null;
@@ -482,14 +525,14 @@ if (window.Element && !Element.prototype.closest) {
window.scrollTo(0, 0);
}
- // Run callback before animation starts
- animateSettings.before(anchor, toggle);
-
// Update the URL
updateURL(anchor, animateSettings);
+ // Emit a custom event
+ emitEvent('scrollStart', anchor, toggle);
+
// Start scrolling animation
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
window.requestAnimationFrame(loopAnimateScroll);
};
diff --git a/dist/js/smooth-scroll.polyfills.min.js b/dist/js/smooth-scroll.polyfills.min.js
index 575668e..86cbd06 100755
--- a/dist/js/smooth-scroll.polyfills.min.js
+++ b/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},f=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},d=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)};return function(r,h){var p,g,w,y,v,S,E,A={};A.cancelScroll=function(){cancelAnimationFrame(E),E=null},A.animateScroll=function(t,i,r){var a=o(p||n,r||{}),u="[object Number]"===Object.prototype.toString.call(t),h=u||!t.tagName?null:t;if(u||h){var g=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),v||(v=m(y));var w,S,b,O=u?t:l(h,v,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-g,q=s(),F=0,C=function(n,o){var r=e.pageYOffset;if(n==o||r==o||(g=q)return A.cancelScroll(),f(t,o,u),a.after(t,i),w=null,E=null,!0},L=function(t){w||(w=t),F+=t-w,S=F/parseInt(a.speed,10),S=S>1?1:S,b=g+I*c(a,S),e.scrollTo(0,Math.floor(b)),C(b,O)||(E=e.requestAnimationFrame(L),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),a.before(t,i),d(t,a),A.cancelScroll(),e.requestAnimationFrame(L)}};var b=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(p.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(p.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);g=document.querySelector(n),g&&(t.preventDefault(),A.animateScroll(g,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(p)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){S||(S=setTimeout((function(){S=null,v=m(y)}),66))};return A.destroy=function(){p&&(document.removeEventListener("click",b,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),p=null,g=null,w=null,y=null,v=null,S=null,E=null)},A.init=function(i){t&&(A.destroy(),p=o(n,i||{}),y=p.header?document.querySelector(p.header):null,v=m(y),document.addEventListener("click",b,!1),y&&e.addEventListener("resize",I,!1),p.updateURL&&p.popstate&&e.addEventListener("popstate",O,!1))},A.init(h),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(i.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel")},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.js b/docs/dist/js/smooth-scroll.js
index 7e0602e..3c57b41 100755
--- a/docs/dist/js/smooth-scroll.js
+++ b/docs/dist/js/smooth-scroll.js
@@ -50,9 +50,8 @@
updateURL: true,
popstate: true,
- // Callback API
- before: function () {},
- after: function () {}
+ // Custom Events
+ emitEvents: true
};
@@ -301,6 +300,11 @@
};
+ /**
+ * Update the URL
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Object} options Settings for Smooth Scroll
+ */
var updateURL = function (anchor, options) {
// Verify that pushState is supported and the updateURL option is enabled
@@ -318,6 +322,24 @@
};
+ /**
+ * Emit a custom event
+ * @todo feature test before emitting
+ * @todo make optional with a setting
+ * @param {String} type The event type
+ */
+ var emitEvent = function (type, anchor, toggle, options) {
+ if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
+ var event = new CustomEvent(type, {
+ bubbles: true,
+ detail: {
+ anchor: anchor,
+ toggle: toggle
+ }
+ });
+ document.dispatchEvent(event);
+ };
+
//
// SmoothScroll Constructor
@@ -340,9 +362,11 @@
/**
* Cancel a scroll-in-progress
*/
- smoothScroll.cancelScroll = function () {
+ smoothScroll.cancelScroll = function (noEvent) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
+ if (noEvent) return;
+ emitEvent('scrollCancel');
};
/**
@@ -390,13 +414,13 @@
if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
// Bring the anchored element into focus
adjustFocus(anchor, endLocation, isNum);
- // Run callback after animation complete
- animateSettings.after(anchor, toggle);
+ // Emit a custom event
+ emitEvent('scrollStop', anchor, toggle);
// Reset start
start = null;
@@ -431,14 +455,14 @@
window.scrollTo(0, 0);
}
- // Run callback before animation starts
- animateSettings.before(anchor, toggle);
-
// Update the URL
updateURL(anchor, animateSettings);
+ // Emit a custom event
+ emitEvent('scrollStart', anchor, toggle);
+
// Start scrolling animation
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
window.requestAnimationFrame(loopAnimateScroll);
};
diff --git a/docs/dist/js/smooth-scroll.min.js b/docs/dist/js/smooth-scroll.min.js
index 2f6e242..f4279e6 100755
--- a/docs/dist/js/smooth-scroll.min.js
+++ b/docs/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,before:function(){},after:function(){}},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)};return function(a,h){var p,g,y,v,S,b,O,E={};E.cancelScroll=function(){cancelAnimationFrame(O),O=null},E.animateScroll=function(t,r,a){var i=o(p||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),h=u||!t.tagName?null:t;if(u||h){var g=e.pageYOffset;i.header&&!v&&(v=document.querySelector(i.header)),S||(S=f(v));var y,b,I,L=u?t:l(h,S,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),C=L-g,A=s(),w=0,H=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(g=A)return E.cancelScroll(),d(t,o,u),i.after(t,r),y=null,O=null,!0},Q=function(t){y||(y=t),w+=t-y,b=w/parseInt(i.speed,10),b=b>1?1:b,I=g+C*c(i,b),e.scrollTo(0,Math.floor(I)),H(I,L)||(O=e.requestAnimationFrame(Q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),i.before(t,r),m(t,i),E.cancelScroll(),e.requestAnimationFrame(Q)}};var I=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(p.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(p.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void E.animateScroll(0,y);g=document.querySelector(n),g&&(t.preventDefault(),E.animateScroll(g,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(p)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&E.animateScroll(t,null,{updateURL:!1})}},C=function(e){b||(b=setTimeout((function(){b=null,S=f(v)}),66))};return E.destroy=function(){p&&(document.removeEventListener("click",I,!1),e.removeEventListener("resize",C,!1),e.removeEventListener("popstate",L,!1),E.cancelScroll(),p=null,g=null,y=null,v=null,S=null,b=null,O=null)},E.init=function(r){t&&(E.destroy(),p=o(n,r||{}),v=p.header?document.querySelector(p.header):null,S=f(v),document.addEventListener("click",I,!1),v&&e.addEventListener("resize",C,!1),p.updateURL&&p.popstate&&e.addEventListener("popstate",L,!1))},E.init(h),E}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(r.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel")},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.polyfills.js b/docs/dist/js/smooth-scroll.polyfills.js
index ffcb742..baddb6f 100755
--- a/docs/dist/js/smooth-scroll.polyfills.js
+++ b/docs/dist/js/smooth-scroll.polyfills.js
@@ -22,6 +22,25 @@ if (window.Element && !Element.prototype.closest) {
};
}
+/**
+ * CustomEvent() polyfill
+ * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
+ */
+(function () {
+
+ if (typeof window.CustomEvent === "function") return false;
+
+ function CustomEvent(event, params) {
+ params = params || { bubbles: false, cancelable: false, detail: undefined };
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
+ return evt;
+ }
+
+ CustomEvent.prototype = window.Event.prototype;
+
+ window.CustomEvent = CustomEvent;
+})();
/**
* requestAnimationFrame() polyfill
* By Erik Möller. Fixes from Paul Irish and Tino Zijdel.
@@ -101,9 +120,8 @@ if (window.Element && !Element.prototype.closest) {
updateURL: true,
popstate: true,
- // Callback API
- before: function () {},
- after: function () {}
+ // Custom Events
+ emitEvents: true
};
@@ -352,6 +370,11 @@ if (window.Element && !Element.prototype.closest) {
};
+ /**
+ * Update the URL
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Object} options Settings for Smooth Scroll
+ */
var updateURL = function (anchor, options) {
// Verify that pushState is supported and the updateURL option is enabled
@@ -369,6 +392,24 @@ if (window.Element && !Element.prototype.closest) {
};
+ /**
+ * Emit a custom event
+ * @todo feature test before emitting
+ * @todo make optional with a setting
+ * @param {String} type The event type
+ */
+ var emitEvent = function (type, anchor, toggle, options) {
+ if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
+ var event = new CustomEvent(type, {
+ bubbles: true,
+ detail: {
+ anchor: anchor,
+ toggle: toggle
+ }
+ });
+ document.dispatchEvent(event);
+ };
+
//
// SmoothScroll Constructor
@@ -391,9 +432,11 @@ if (window.Element && !Element.prototype.closest) {
/**
* Cancel a scroll-in-progress
*/
- smoothScroll.cancelScroll = function () {
+ smoothScroll.cancelScroll = function (noEvent) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
+ if (noEvent) return;
+ emitEvent('scrollCancel');
};
/**
@@ -441,13 +484,13 @@ if (window.Element && !Element.prototype.closest) {
if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
// Bring the anchored element into focus
adjustFocus(anchor, endLocation, isNum);
- // Run callback after animation complete
- animateSettings.after(anchor, toggle);
+ // Emit a custom event
+ emitEvent('scrollStop', anchor, toggle);
// Reset start
start = null;
@@ -482,14 +525,14 @@ if (window.Element && !Element.prototype.closest) {
window.scrollTo(0, 0);
}
- // Run callback before animation starts
- animateSettings.before(anchor, toggle);
-
// Update the URL
updateURL(anchor, animateSettings);
+ // Emit a custom event
+ emitEvent('scrollStart', anchor, toggle);
+
// Start scrolling animation
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
window.requestAnimationFrame(loopAnimateScroll);
};
diff --git a/docs/dist/js/smooth-scroll.polyfills.min.js b/docs/dist/js/smooth-scroll.polyfills.min.js
index 575668e..86cbd06 100755
--- a/docs/dist/js/smooth-scroll.polyfills.min.js
+++ b/docs/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},f=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},d=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)};return function(r,h){var p,g,w,y,v,S,E,A={};A.cancelScroll=function(){cancelAnimationFrame(E),E=null},A.animateScroll=function(t,i,r){var a=o(p||n,r||{}),u="[object Number]"===Object.prototype.toString.call(t),h=u||!t.tagName?null:t;if(u||h){var g=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),v||(v=m(y));var w,S,b,O=u?t:l(h,v,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-g,q=s(),F=0,C=function(n,o){var r=e.pageYOffset;if(n==o||r==o||(g=q)return A.cancelScroll(),f(t,o,u),a.after(t,i),w=null,E=null,!0},L=function(t){w||(w=t),F+=t-w,S=F/parseInt(a.speed,10),S=S>1?1:S,b=g+I*c(a,S),e.scrollTo(0,Math.floor(b)),C(b,O)||(E=e.requestAnimationFrame(L),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),a.before(t,i),d(t,a),A.cancelScroll(),e.requestAnimationFrame(L)}};var b=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(p.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(p.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);g=document.querySelector(n),g&&(t.preventDefault(),A.animateScroll(g,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(p)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){S||(S=setTimeout((function(){S=null,v=m(y)}),66))};return A.destroy=function(){p&&(document.removeEventListener("click",b,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),p=null,g=null,w=null,y=null,v=null,S=null,E=null)},A.init=function(i){t&&(A.destroy(),p=o(n,i||{}),y=p.header?document.querySelector(p.header):null,v=m(y),document.addEventListener("click",b,!1),y&&e.addEventListener("resize",I,!1),p.updateURL&&p.popstate&&e.addEventListener("popstate",O,!1))},A.init(h),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(i.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel")},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
index b07ed03..be9ff69 100755
--- a/docs/index.html
+++ b/docs/index.html
@@ -93,27 +93,36 @@
Smooth Scroll
diff --git a/src/docs/_templates/_footer.html b/src/docs/_templates/_footer.html
index 2f84278..7d5455d 100755
--- a/src/docs/_templates/_footer.html
+++ b/src/docs/_templates/_footer.html
@@ -5,27 +5,36 @@
diff --git a/src/js/_customEvent.polyfill.js b/src/js/_customEvent.polyfill.js
new file mode 100644
index 0000000..4e7a110
--- /dev/null
+++ b/src/js/_customEvent.polyfill.js
@@ -0,0 +1,19 @@
+/**
+ * CustomEvent() polyfill
+ * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
+ */
+(function () {
+
+ if (typeof window.CustomEvent === "function") return false;
+
+ function CustomEvent(event, params) {
+ params = params || { bubbles: false, cancelable: false, detail: undefined };
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
+ return evt;
+ }
+
+ CustomEvent.prototype = window.Event.prototype;
+
+ window.CustomEvent = CustomEvent;
+})();
\ No newline at end of file
diff --git a/src/js/smooth-scroll.js b/src/js/smooth-scroll.js
index f9b751d..555dc38 100755
--- a/src/js/smooth-scroll.js
+++ b/src/js/smooth-scroll.js
@@ -43,9 +43,8 @@
updateURL: true,
popstate: true,
- // Callback API
- before: function () {},
- after: function () {}
+ // Custom Events
+ emitEvents: true
};
@@ -294,6 +293,11 @@
};
+ /**
+ * Update the URL
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Object} options Settings for Smooth Scroll
+ */
var updateURL = function (anchor, options) {
// Verify that pushState is supported and the updateURL option is enabled
@@ -311,6 +315,24 @@
};
+ /**
+ * Emit a custom event
+ * @todo feature test before emitting
+ * @todo make optional with a setting
+ * @param {String} type The event type
+ */
+ var emitEvent = function (type, anchor, toggle, options) {
+ if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
+ var event = new CustomEvent(type, {
+ bubbles: true,
+ detail: {
+ anchor: anchor,
+ toggle: toggle
+ }
+ });
+ document.dispatchEvent(event);
+ };
+
//
// SmoothScroll Constructor
@@ -333,9 +355,11 @@
/**
* Cancel a scroll-in-progress
*/
- smoothScroll.cancelScroll = function () {
+ smoothScroll.cancelScroll = function (noEvent) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
+ if (noEvent) return;
+ emitEvent('scrollCancel');
};
/**
@@ -383,13 +407,13 @@
if (position == endLocation || currentLocation == endLocation || ((startLocation < endLocation && window.innerHeight + currentLocation) >= documentHeight)) {
// Clear the animation timer
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
// Bring the anchored element into focus
adjustFocus(anchor, endLocation, isNum);
- // Run callback after animation complete
- animateSettings.after(anchor, toggle);
+ // Emit a custom event
+ emitEvent('scrollStop', anchor, toggle);
// Reset start
start = null;
@@ -424,14 +448,14 @@
window.scrollTo(0, 0);
}
- // Run callback before animation starts
- animateSettings.before(anchor, toggle);
-
// Update the URL
updateURL(anchor, animateSettings);
+ // Emit a custom event
+ emitEvent('scrollStart', anchor, toggle);
+
// Start scrolling animation
- smoothScroll.cancelScroll();
+ smoothScroll.cancelScroll(true);
window.requestAnimationFrame(loopAnimateScroll);
};
From 4c1c7413b7f6901c5ce1ae856fe6e9dc7197d305 Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 20:05:15 -0400
Subject: [PATCH 04/51] pass options into emitEvent method
---
src/js/smooth-scroll.js | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/js/smooth-scroll.js b/src/js/smooth-scroll.js
index 555dc38..573f299 100755
--- a/src/js/smooth-scroll.js
+++ b/src/js/smooth-scroll.js
@@ -317,11 +317,12 @@
/**
* Emit a custom event
- * @todo feature test before emitting
- * @todo make optional with a setting
- * @param {String} type The event type
+ * @param {String} type The event type
+ * @param {Object} options The settings object
+ * @param {Node} anchor The anchor element
+ * @param {Node} toggle The toggle element
*/
- var emitEvent = function (type, anchor, toggle, options) {
+ var emitEvent = function (type, options, anchor, toggle) {
if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
var event = new CustomEvent(type, {
bubbles: true,
@@ -359,7 +360,7 @@
cancelAnimationFrame(animationInterval);
animationInterval = null;
if (noEvent) return;
- emitEvent('scrollCancel');
+ emitEvent('scrollCancel', settings);
};
/**
@@ -413,7 +414,7 @@
adjustFocus(anchor, endLocation, isNum);
// Emit a custom event
- emitEvent('scrollStop', anchor, toggle);
+ emitEvent('scrollStop', animateSettings, anchor, toggle);
// Reset start
start = null;
@@ -452,7 +453,7 @@
updateURL(anchor, animateSettings);
// Emit a custom event
- emitEvent('scrollStart', anchor, toggle);
+ emitEvent('scrollStart', animateSettings, anchor, toggle);
// Start scrolling animation
smoothScroll.cancelScroll(true);
From de7d92029836cb5cf8aded94e18e18afd0e3b3ca Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 20:05:33 -0400
Subject: [PATCH 05/51] Pass options into emitEvent method
---
dist/js/smooth-scroll.js | 15 ++++++++-------
dist/js/smooth-scroll.min.js | 2 +-
dist/js/smooth-scroll.polyfills.js | 15 ++++++++-------
dist/js/smooth-scroll.polyfills.min.js | 2 +-
docs/dist/js/smooth-scroll.js | 15 ++++++++-------
docs/dist/js/smooth-scroll.min.js | 2 +-
docs/dist/js/smooth-scroll.polyfills.js | 15 ++++++++-------
docs/dist/js/smooth-scroll.polyfills.min.js | 2 +-
8 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/dist/js/smooth-scroll.js b/dist/js/smooth-scroll.js
index 3c57b41..d352bf7 100755
--- a/dist/js/smooth-scroll.js
+++ b/dist/js/smooth-scroll.js
@@ -324,11 +324,12 @@
/**
* Emit a custom event
- * @todo feature test before emitting
- * @todo make optional with a setting
- * @param {String} type The event type
+ * @param {String} type The event type
+ * @param {Object} options The settings object
+ * @param {Node} anchor The anchor element
+ * @param {Node} toggle The toggle element
*/
- var emitEvent = function (type, anchor, toggle, options) {
+ var emitEvent = function (type, options, anchor, toggle) {
if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
var event = new CustomEvent(type, {
bubbles: true,
@@ -366,7 +367,7 @@
cancelAnimationFrame(animationInterval);
animationInterval = null;
if (noEvent) return;
- emitEvent('scrollCancel');
+ emitEvent('scrollCancel', settings);
};
/**
@@ -420,7 +421,7 @@
adjustFocus(anchor, endLocation, isNum);
// Emit a custom event
- emitEvent('scrollStop', anchor, toggle);
+ emitEvent('scrollStop', animateSettings, anchor, toggle);
// Reset start
start = null;
@@ -459,7 +460,7 @@
updateURL(anchor, animateSettings);
// Emit a custom event
- emitEvent('scrollStart', anchor, toggle);
+ emitEvent('scrollStart', animateSettings, anchor, toggle);
// Start scrolling animation
smoothScroll.cancelScroll(true);
diff --git a/dist/js/smooth-scroll.min.js b/dist/js/smooth-scroll.min.js
index f4279e6..6638cc4 100755
--- a/dist/js/smooth-scroll.min.js
+++ b/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(r.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel")},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",i,t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",i,t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/dist/js/smooth-scroll.polyfills.js b/dist/js/smooth-scroll.polyfills.js
index baddb6f..8e0bd7f 100755
--- a/dist/js/smooth-scroll.polyfills.js
+++ b/dist/js/smooth-scroll.polyfills.js
@@ -394,11 +394,12 @@ if (window.Element && !Element.prototype.closest) {
/**
* Emit a custom event
- * @todo feature test before emitting
- * @todo make optional with a setting
- * @param {String} type The event type
+ * @param {String} type The event type
+ * @param {Object} options The settings object
+ * @param {Node} anchor The anchor element
+ * @param {Node} toggle The toggle element
*/
- var emitEvent = function (type, anchor, toggle, options) {
+ var emitEvent = function (type, options, anchor, toggle) {
if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
var event = new CustomEvent(type, {
bubbles: true,
@@ -436,7 +437,7 @@ if (window.Element && !Element.prototype.closest) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
if (noEvent) return;
- emitEvent('scrollCancel');
+ emitEvent('scrollCancel', settings);
};
/**
@@ -490,7 +491,7 @@ if (window.Element && !Element.prototype.closest) {
adjustFocus(anchor, endLocation, isNum);
// Emit a custom event
- emitEvent('scrollStop', anchor, toggle);
+ emitEvent('scrollStop', animateSettings, anchor, toggle);
// Reset start
start = null;
@@ -529,7 +530,7 @@ if (window.Element && !Element.prototype.closest) {
updateURL(anchor, animateSettings);
// Emit a custom event
- emitEvent('scrollStart', anchor, toggle);
+ emitEvent('scrollStart', animateSettings, anchor, toggle);
// Start scrolling animation
smoothScroll.cancelScroll(true);
diff --git a/dist/js/smooth-scroll.polyfills.min.js b/dist/js/smooth-scroll.polyfills.min.js
index 86cbd06..3173c4c 100755
--- a/dist/js/smooth-scroll.polyfills.min.js
+++ b/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(i.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel")},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",r,t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",r,t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.js b/docs/dist/js/smooth-scroll.js
index 3c57b41..d352bf7 100755
--- a/docs/dist/js/smooth-scroll.js
+++ b/docs/dist/js/smooth-scroll.js
@@ -324,11 +324,12 @@
/**
* Emit a custom event
- * @todo feature test before emitting
- * @todo make optional with a setting
- * @param {String} type The event type
+ * @param {String} type The event type
+ * @param {Object} options The settings object
+ * @param {Node} anchor The anchor element
+ * @param {Node} toggle The toggle element
*/
- var emitEvent = function (type, anchor, toggle, options) {
+ var emitEvent = function (type, options, anchor, toggle) {
if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
var event = new CustomEvent(type, {
bubbles: true,
@@ -366,7 +367,7 @@
cancelAnimationFrame(animationInterval);
animationInterval = null;
if (noEvent) return;
- emitEvent('scrollCancel');
+ emitEvent('scrollCancel', settings);
};
/**
@@ -420,7 +421,7 @@
adjustFocus(anchor, endLocation, isNum);
// Emit a custom event
- emitEvent('scrollStop', anchor, toggle);
+ emitEvent('scrollStop', animateSettings, anchor, toggle);
// Reset start
start = null;
@@ -459,7 +460,7 @@
updateURL(anchor, animateSettings);
// Emit a custom event
- emitEvent('scrollStart', anchor, toggle);
+ emitEvent('scrollStart', animateSettings, anchor, toggle);
// Start scrolling animation
smoothScroll.cancelScroll(true);
diff --git a/docs/dist/js/smooth-scroll.min.js b/docs/dist/js/smooth-scroll.min.js
index f4279e6..6638cc4 100755
--- a/docs/dist/js/smooth-scroll.min.js
+++ b/docs/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(r.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel")},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",i,t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",i,t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.polyfills.js b/docs/dist/js/smooth-scroll.polyfills.js
index baddb6f..8e0bd7f 100755
--- a/docs/dist/js/smooth-scroll.polyfills.js
+++ b/docs/dist/js/smooth-scroll.polyfills.js
@@ -394,11 +394,12 @@ if (window.Element && !Element.prototype.closest) {
/**
* Emit a custom event
- * @todo feature test before emitting
- * @todo make optional with a setting
- * @param {String} type The event type
+ * @param {String} type The event type
+ * @param {Object} options The settings object
+ * @param {Node} anchor The anchor element
+ * @param {Node} toggle The toggle element
*/
- var emitEvent = function (type, anchor, toggle, options) {
+ var emitEvent = function (type, options, anchor, toggle) {
if (!options.emitEvents || typeof window.CustomEvent !== 'function') return;
var event = new CustomEvent(type, {
bubbles: true,
@@ -436,7 +437,7 @@ if (window.Element && !Element.prototype.closest) {
cancelAnimationFrame(animationInterval);
animationInterval = null;
if (noEvent) return;
- emitEvent('scrollCancel');
+ emitEvent('scrollCancel', settings);
};
/**
@@ -490,7 +491,7 @@ if (window.Element && !Element.prototype.closest) {
adjustFocus(anchor, endLocation, isNum);
// Emit a custom event
- emitEvent('scrollStop', anchor, toggle);
+ emitEvent('scrollStop', animateSettings, anchor, toggle);
// Reset start
start = null;
@@ -529,7 +530,7 @@ if (window.Element && !Element.prototype.closest) {
updateURL(anchor, animateSettings);
// Emit a custom event
- emitEvent('scrollStart', anchor, toggle);
+ emitEvent('scrollStart', animateSettings, anchor, toggle);
// Start scrolling animation
smoothScroll.cancelScroll(true);
diff --git a/docs/dist/js/smooth-scroll.polyfills.min.js b/docs/dist/js/smooth-scroll.polyfills.min.js
index 86cbd06..3173c4c 100755
--- a/docs/dist/js/smooth-scroll.polyfills.min.js
+++ b/docs/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(i.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel")},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",r,t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",r,t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
From 499201267cb4b3c21df52f5ba3fde4ffe77ee823 Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 20:35:32 -0400
Subject: [PATCH 06/51] Moved feature test to a method Fixes
https://github.com/cferdinandi/smooth-scroll/pull/419
---
dist/js/smooth-scroll.js | 26 +++++++++++----------
dist/js/smooth-scroll.min.js | 2 +-
dist/js/smooth-scroll.polyfills.js | 26 +++++++++++----------
dist/js/smooth-scroll.polyfills.min.js | 2 +-
docs/dist/js/smooth-scroll.js | 26 +++++++++++----------
docs/dist/js/smooth-scroll.min.js | 2 +-
docs/dist/js/smooth-scroll.polyfills.js | 26 +++++++++++----------
docs/dist/js/smooth-scroll.polyfills.min.js | 2 +-
src/js/smooth-scroll.js | 26 +++++++++++----------
9 files changed, 74 insertions(+), 64 deletions(-)
diff --git a/dist/js/smooth-scroll.js b/dist/js/smooth-scroll.js
index d352bf7..c0741d2 100755
--- a/dist/js/smooth-scroll.js
+++ b/dist/js/smooth-scroll.js
@@ -19,17 +19,6 @@
'use strict';
- //
- // Feature Test
- //
-
- var supports =
- 'querySelector' in document &&
- 'addEventListener' in window &&
- 'requestAnimationFrame' in window &&
- 'closest' in window.Element.prototype;
-
-
//
// Default settings
//
@@ -59,6 +48,19 @@
// Utility Methods
//
+ /**
+ * Check if browser supports required methods
+ * @return {Boolean} Returns true if all required methods are supported
+ */
+ var supports = function () {
+ return (
+ 'querySelector' in document &&
+ 'addEventListener' in window &&
+ 'requestAnimationFrame' in window &&
+ 'closest' in window.Element.prototype
+ );
+ };
+
/**
* Merge two or more objects. Returns a new object.
* @param {Object} objects The objects to merge together
@@ -578,7 +580,7 @@
smoothScroll.init = function (options) {
// feature test
- if (!supports) return;
+ if (!supports()) return;
// Destroy any existing initializations
smoothScroll.destroy();
diff --git a/dist/js/smooth-scroll.min.js b/dist/js/smooth-scroll.min.js
index 6638cc4..9544052 100755
--- a/dist/js/smooth-scroll.min.js
+++ b/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",i,t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",i,t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/dist/js/smooth-scroll.polyfills.js b/dist/js/smooth-scroll.polyfills.js
index 8e0bd7f..265ad13 100755
--- a/dist/js/smooth-scroll.polyfills.js
+++ b/dist/js/smooth-scroll.polyfills.js
@@ -89,17 +89,6 @@ if (window.Element && !Element.prototype.closest) {
'use strict';
- //
- // Feature Test
- //
-
- var supports =
- 'querySelector' in document &&
- 'addEventListener' in window &&
- 'requestAnimationFrame' in window &&
- 'closest' in window.Element.prototype;
-
-
//
// Default settings
//
@@ -129,6 +118,19 @@ if (window.Element && !Element.prototype.closest) {
// Utility Methods
//
+ /**
+ * Check if browser supports required methods
+ * @return {Boolean} Returns true if all required methods are supported
+ */
+ var supports = function () {
+ return (
+ 'querySelector' in document &&
+ 'addEventListener' in window &&
+ 'requestAnimationFrame' in window &&
+ 'closest' in window.Element.prototype
+ );
+ };
+
/**
* Merge two or more objects. Returns a new object.
* @param {Object} objects The objects to merge together
@@ -648,7 +650,7 @@ if (window.Element && !Element.prototype.closest) {
smoothScroll.init = function (options) {
// feature test
- if (!supports) return;
+ if (!supports()) return;
// Destroy any existing initializations
smoothScroll.destroy();
diff --git a/dist/js/smooth-scroll.polyfills.min.js b/dist/js/smooth-scroll.polyfills.min.js
index 3173c4c..46ad04c 100755
--- a/dist/js/smooth-scroll.polyfills.min.js
+++ b/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",r,t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",r,t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var r=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(r)}};return function(r,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,r){var a=o(g||t,r||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var r=e.pageYOffset;if(t==o||r==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",a,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(a.speed,10),b=b>1?1:b,C=v+I*c(a,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,a),h("scrollStart",a,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.js b/docs/dist/js/smooth-scroll.js
index d352bf7..c0741d2 100755
--- a/docs/dist/js/smooth-scroll.js
+++ b/docs/dist/js/smooth-scroll.js
@@ -19,17 +19,6 @@
'use strict';
- //
- // Feature Test
- //
-
- var supports =
- 'querySelector' in document &&
- 'addEventListener' in window &&
- 'requestAnimationFrame' in window &&
- 'closest' in window.Element.prototype;
-
-
//
// Default settings
//
@@ -59,6 +48,19 @@
// Utility Methods
//
+ /**
+ * Check if browser supports required methods
+ * @return {Boolean} Returns true if all required methods are supported
+ */
+ var supports = function () {
+ return (
+ 'querySelector' in document &&
+ 'addEventListener' in window &&
+ 'requestAnimationFrame' in window &&
+ 'closest' in window.Element.prototype
+ );
+ };
+
/**
* Merge two or more objects. Returns a new object.
* @param {Object} objects The objects to merge together
@@ -578,7 +580,7 @@
smoothScroll.init = function (options) {
// feature test
- if (!supports) return;
+ if (!supports()) return;
// Destroy any existing initializations
smoothScroll.destroy();
diff --git a/docs/dist/js/smooth-scroll.min.js b/docs/dist/js/smooth-scroll.min.js
index 6638cc4..9544052 100755
--- a/docs/dist/js/smooth-scroll.min.js
+++ b/docs/dist/js/smooth-scroll.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t="querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype,n={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(t,r,a){var i=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?t:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=A)return I.cancelScroll(!0),d(t,o,u),h("scrollStop",i,t,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(t,i),h("scrollStart",i,t,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){t&&(I.destroy(),g=o(n,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/docs/dist/js/smooth-scroll.polyfills.js b/docs/dist/js/smooth-scroll.polyfills.js
index 8e0bd7f..265ad13 100755
--- a/docs/dist/js/smooth-scroll.polyfills.js
+++ b/docs/dist/js/smooth-scroll.polyfills.js
@@ -89,17 +89,6 @@ if (window.Element && !Element.prototype.closest) {
'use strict';
- //
- // Feature Test
- //
-
- var supports =
- 'querySelector' in document &&
- 'addEventListener' in window &&
- 'requestAnimationFrame' in window &&
- 'closest' in window.Element.prototype;
-
-
//
// Default settings
//
@@ -129,6 +118,19 @@ if (window.Element && !Element.prototype.closest) {
// Utility Methods
//
+ /**
+ * Check if browser supports required methods
+ * @return {Boolean} Returns true if all required methods are supported
+ */
+ var supports = function () {
+ return (
+ 'querySelector' in document &&
+ 'addEventListener' in window &&
+ 'requestAnimationFrame' in window &&
+ 'closest' in window.Element.prototype
+ );
+ };
+
/**
* Merge two or more objects. Returns a new object.
* @param {Object} objects The objects to merge together
@@ -648,7 +650,7 @@ if (window.Element && !Element.prototype.closest) {
smoothScroll.init = function (options) {
// feature test
- if (!supports) return;
+ if (!supports()) return;
// Destroy any existing initializations
smoothScroll.destroy();
diff --git a/docs/dist/js/smooth-scroll.polyfills.min.js b/docs/dist/js/smooth-scroll.polyfills.min.js
index 3173c4c..46ad04c 100755
--- a/docs/dist/js/smooth-scroll.polyfills.min.js
+++ b/docs/dist/js/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(t,i,a){var r=o(g||n,a||{}),u="[object Number]"===Object.prototype.toString.call(t),p=u||!t.tagName?null:t;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?t:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(n,o){var a=e.pageYOffset;if(n==o||a==o||(v=q)return A.cancelScroll(!0),d(t,o,u),h("scrollStop",r,t,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(t,r),h("scrollStart",r,t,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){t&&(A.destroy(),g=o(n,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var r=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(r)}};return function(r,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,r){var a=o(g||t,r||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var r=e.pageYOffset;if(t==o||r==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",a,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(a.speed,10),b=b>1?1:b,C=v+I*c(a,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,a),h("scrollStart",a,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/src/js/smooth-scroll.js b/src/js/smooth-scroll.js
index 573f299..9090cbd 100755
--- a/src/js/smooth-scroll.js
+++ b/src/js/smooth-scroll.js
@@ -12,17 +12,6 @@
'use strict';
- //
- // Feature Test
- //
-
- var supports =
- 'querySelector' in document &&
- 'addEventListener' in window &&
- 'requestAnimationFrame' in window &&
- 'closest' in window.Element.prototype;
-
-
//
// Default settings
//
@@ -52,6 +41,19 @@
// Utility Methods
//
+ /**
+ * Check if browser supports required methods
+ * @return {Boolean} Returns true if all required methods are supported
+ */
+ var supports = function () {
+ return (
+ 'querySelector' in document &&
+ 'addEventListener' in window &&
+ 'requestAnimationFrame' in window &&
+ 'closest' in window.Element.prototype
+ );
+ };
+
/**
* Merge two or more objects. Returns a new object.
* @param {Object} objects The objects to merge together
@@ -571,7 +573,7 @@
smoothScroll.init = function (options) {
// feature test
- if (!supports) return;
+ if (!supports()) return;
// Destroy any existing initializations
smoothScroll.destroy();
From 902c26cbb4d5cdf98e1594804fec9748a98487b5 Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 21:10:03 -0400
Subject: [PATCH 07/51] v14.0.0 Release
---
.github/issue_template.md | 3 +
SUPPORT.md => .github/support.md | 9 +-
README.md | 162 +++++++-----------
dist/{js => }/smooth-scroll.js | 0
dist/{js => }/smooth-scroll.min.js | 0
dist/{js => }/smooth-scroll.polyfills.js | 0
dist/{js => }/smooth-scroll.polyfills.min.js | 0
docs/dist/{js => }/smooth-scroll.js | 0
docs/dist/{js => }/smooth-scroll.min.js | 0
docs/dist/{js => }/smooth-scroll.polyfills.js | 0
.../{js => }/smooth-scroll.polyfills.min.js | 0
gulpfile.js | 2 +-
package.json | 2 +-
13 files changed, 77 insertions(+), 101 deletions(-)
create mode 100755 .github/issue_template.md
rename SUPPORT.md => .github/support.md (59%)
rename dist/{js => }/smooth-scroll.js (100%)
rename dist/{js => }/smooth-scroll.min.js (100%)
rename dist/{js => }/smooth-scroll.polyfills.js (100%)
rename dist/{js => }/smooth-scroll.polyfills.min.js (100%)
rename docs/dist/{js => }/smooth-scroll.js (100%)
rename docs/dist/{js => }/smooth-scroll.min.js (100%)
rename docs/dist/{js => }/smooth-scroll.polyfills.js (100%)
rename docs/dist/{js => }/smooth-scroll.polyfills.min.js (100%)
diff --git a/.github/issue_template.md b/.github/issue_template.md
new file mode 100755
index 0000000..e92cc83
--- /dev/null
+++ b/.github/issue_template.md
@@ -0,0 +1,3 @@
+
+
+**Test case:** https://jsfiddle.net/cferdinandi/87v3pqp0/
\ No newline at end of file
diff --git a/SUPPORT.md b/.github/support.md
similarity index 59%
rename from SUPPORT.md
rename to .github/support.md
index 3ac7048..a9e4594 100644
--- a/SUPPORT.md
+++ b/.github/support.md
@@ -1,14 +1,17 @@
# Bugs, Questions, and Feature Requests
-You can ask questions and get help from a community of developers on [GitHub Issues](https://github.com/cferdinandi/smooth-scroll/issues).
+Report bugs, ask questions, and request features using [GitHub Issues](https://github.com/cferdinandi/smooth-scroll/issues).
-**Before posting, do a search to make sure your issue or question hasn't already been reported or discussed.** If no matching issue exists, go ahead and create one. Please be sure to include all of the following:
+**Before posting, do a search to make sure your issue or question hasn't already been reported or discussed.** If no matching issue exists, go ahead and create one.
+
+**Please be sure to include all of the following:**
1. A clear, descriptive title (ie. "A bug" is not a good title).
2. [A reduced test case.](https://css-tricks.com/reduced-test-cases/)
- Clearly demonstrate the bug or issue.
- Include the bare minimum HTML, CSS, and JavaScript required to demonstrate the bug.
- - A link to your production site is not a reduced test case.
+ - A link to your production site is **not** a reduced test case.
+ - You can create one by [forking this JSFiddle](https://jsfiddle.net/cferdinandi/87v3pqp0/).
3. The browser and OS that you're using.
Duplicates and issues without a reduced test case may be closed without comment.
\ No newline at end of file
diff --git a/README.md b/README.md
index 61f8f46..0c6bb31 100755
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
# Smooth Scroll [](https://travis-ci.org/cferdinandi/smooth-scroll)
A lightweight script to animate scrolling to anchor links. Smooth Scroll works great with [Gumshoe](https://github.com/cferdinandi/gumshoe).
-[Download Smooth Scroll](https://github.com/cferdinandi/smooth-scroll/archive/master.zip) / [View the demo](http://cferdinandi.github.io/smooth-scroll/)
+[Demo](http://cferdinandi.github.io/smooth-scroll/)
-### Want to learn how to write your own vanilla JS plugins? Check out my [Vanilla JS Pocket Guides series](https://gomakethings.com/guides/) and level-up as a web developer. 🚀
+### Want to learn how to write your own vanilla JS plugins? Check out my [Vanilla JS Pocket Guides](https://vanillajsguides.com/) or join the [Vanilla JS Academy](https://vanillajsacademy.com) and level-up as a web developer. 🚀
@@ -18,12 +18,26 @@ Compiled and production-ready code can be found in the `dist` directory. The `sr
### 1. Include Smooth Scroll on your site.
-There are two versions of Smooth Scroll: the standalone version, and one that comes preloaded with polyfills for the `closest()` and `requestAnimationFrame()` methods, which are only supported in newer browsers.
+There are two versions of Smooth Scroll: the standalone version, and one that comes preloaded with polyfills for `closest()`, `requestAnimationFrame()`, and `CustomEvent()`, which are only supported in newer browsers.
If you're including your own polyfills or don't want to enable this feature for older browsers, use the standalone version. Otherwise, use the version with polyfills.
+**Direct `
+
+
+
+
+
+```
+
+**NPM**
+
+```bash
+npm install smooth-scroll
```
### 2. Add the markup to your HTML.
@@ -52,16 +66,6 @@ In the footer of your page, after the content, initialize Smooth Scroll by passi
-## Installing with Package Managers
-
-You can install Smooth Scroll with your favorite package manager or module loader directly from NPM.
-
-```
-npm install smooth-scroll
-```
-
-
-
## Working with the Source Files
If you would prefer, you can work with the development code in the `src` directory using the included [Gulp build system](http://gulpjs.com/). This compiles, lints, and minifies code.
@@ -92,9 +96,11 @@ You can pass options and callbacks into Smooth Scroll through the `init()` funct
```javascript
var scroll = new SmoothScroll('a[href*="#"]', {
+
// Selectors
ignore: '[data-scroll-ignore]', // Selector for links to ignore (must be a valid CSS selector)
header: null, // Selector for fixed headers (must be a valid CSS selector)
+ topOnEmptyHash: true, // Scroll to the top of the page for links with href="#"
// Speed & Easing
speed: 500, // Integer. How fast to complete the scroll in milliseconds
@@ -112,9 +118,13 @@ var scroll = new SmoothScroll('a[href*="#"]', {
},
- // Callback API
- before: function (anchor, toggle) {}, // Callback to run before scroll
- after: function (anchor, toggle) {} // Callback to run after scroll
+ // History
+ updateURL: true, // Update the URL on scroll
+ popstate: true, // Animate scrolling with the forward/backward browser buttons (requires updateURL to be true)
+
+ // Custom Events
+ emitEvents: true // Emit custom events
+
});
```
@@ -156,6 +166,37 @@ Some common easing patterns are included by default, but you can also pass in yo
Learn more about the different easing patterns and what they do at [easings.net](http://easings.net/).
+### Custom Events
+
+Smooth Scroll emits three custom events:
+
+- `scrollStart` is emitted when the scrolling animation starts.
+- `scrollStop` is emitted when the scrolling animation stops.
+- `scrollCancel` is emitted if the scrolling animation is canceled.
+
+All three events are emitted on the `document` element and bubble up. You can listen for them with the `addEventListener()` method. The `event.detail` object includes the `anchor` and `toggle` elements for the animation.
+
+```js
+// Log scroll events
+var logScrollEvent = function (event) {
+
+ // The event type
+ console.log('type:', event.type);
+
+ // The anchor element being scrolled to
+ console.log('anchor:', event.detail.anchor);
+
+ // The anchor link that triggered the scroll
+ console.log('toggle:', event.detail.toggle);
+
+};
+
+// Listen for scroll events
+document.addEventListener('scrollStart', logScrollEvent, false);
+document.addEventListener('scrollStop', logScrollEvent, false);
+document.addEventListener('scrollCancel', logScrollEvent, false);
+```
+
### Use Smooth Scroll events in your own scripts
You can also call Smooth Scroll's methods in your own scripts.
@@ -244,24 +285,19 @@ If you have multiple fixed headers, pass in the last one in the markup.
```
-## Migrating to Smooth Scroll 12 from Older Versions
+## Migrating to Smooth Scroll 14 from Older Versions
### New Features
-- You can now initialize multiple instances of Smooth Scroll with different selectors and options:
- ```js
- var scrollFast = new SmoothScroll('.scroll-fast', {speed: 100});
- var scrollSlow = new SmoothScroll('.scroll-slow', {speed: 5000});
- ```
-- The new `cancelScroll()` method lets you programatically cancel a scroll-in-progress.
-- Scrolling animation is now powered by `requestAnimationFrame()`, resulting in smoother scrolling and better performance.
-- Smooth Scroll now supports Reduced Motion (currently a Safari-only feature). If the visitor has indicated that they [prefer reduced motion](https://css-tricks.com/smooth-scrolling-accessibility/), Smooth Scroll will jump to the anchor link as normal instead of animating the scroll.
+- You can now choose not to update the URL as a native feature. No more hacks using the API.
+- You can choose not to scroll to top on `href="#"`, providing more flexibility for some CMS implementations.
+- Custom events let you more easily hook into Smooth Scroll from other scripts.
+- The feature test is scoped to a function, allowing for server-side implementations.
+- The loss of styling with IDs experienced in earlier versions has been eliminated.
### Breaking Changes
-- You no longer initialize Smooth Scroll via `smoothScroll.init()`. You must now instantiate a new JavaScript object: `new SmoothScroll()`.
-- There is no longer a default selector. You should pass in a selector as the first argument when setting up your constructor: `new SmoothScroll('.my-selector')`.
-- The `data-options` feature has been deprecated, as the same effect can be achieved by initializing the plugin with different selectors.
+- Callback methods have been removed in favor of events.
@@ -273,7 +309,7 @@ Smooth Scroll is built with modern JavaScript APIs, and uses progressive enhance
### Polyfills
-Support back to IE9 requires polyfills for the `closest()` and `requestAnimationFrame()` methods. Without them, support starts with Edge.
+Support back to IE9 requires polyfills for `closest()`, `requestAnimationFrame()`, and `CustomEvent()`. Without them, support starts with Edge.
Use the included polyfills version of Smooth Scroll, or include your own.
@@ -289,78 +325,12 @@ If the `` element has been assigned a height of `100%` or `overflow: hidde
Animated scrolling links at the very bottom of the page (example: a "scroll to top" link) will stop animated almost immediately after they start when using certain easing patterns. This is an issue that's been around for a while and I've yet to find a good fix for it. I've found that `easeOut*` easing patterns work as expected, but other patterns can cause issues. [See this discussion for more details.](https://github.com/cferdinandi/smooth-scroll/issues/49)
-### Styling with IDs
-
-If you use an ID to style an element in your CSS, and that same element is targeted by an anchor link that you're scrolling to with Smooth Scroll, you will experience a temporary loss of styling.
-
-Smooth Scroll temporarily removes the ID to prevent the page from jumping when the URL changes, and then adds it back. Use a class instead of an ID to avoid this issue.
-
-```css
-/* Instead of this */
-#some-element {
- background-color: purple;
-}
-
-/* Do this */
-.some-element {
- background-color: purple;
-}
-```
-
-
-
-## Extras
-
-Frequently asked questions, code snippets, and more to help you get the most out of Smooth Scroll.
-
### Scrolling to an anchor link on another page
This, unfortunately, cannot be done well.
Most browsers instantly jump you to the anchor location when you load a page. You could use `scrollTo(0, 0)` to pull users back up to the top, and then manually use the `animateScroll()` method, but in my experience, it results in a visible jump on the page that's a worse experience than the default browser behavior.
-### Scrolling without updating the URL
-
-Smooth Scroll is designed to progressively enhance anchor links while offloading as much to the browser as possible. In it's current implementation, it relies on `hashchange` events (which occur whenever a `#` changes in the URL) to trigger the scrolling behavior.
-
-A benefit of this approach is that it preserves browser history and let's users navigate between anchors with the forward and back buttons on the browsers, just like you would normally.
-
-*However*, I know certain front-end frameworks also use URL hashes for their own internal processes. While I view this as an anti-pattern, and won't bake hashless anchor links into Smooth Scroll's core, you can enable scrolling without updating the URL via the Smooth Scroll API.
-
-Here's a relatively lightweight helper function that listens for click events and uses the `animateScroll()` method to scroll to the anchor. If you use this, you **should not** pass a selector into `new SmoothScroll()`.
-
-```js
-var scroll = new SmoothScroll();
-
-var smoothScrollWithoutHash = function (selector, settings) {
- /**
- * If smooth scroll element clicked, animate scroll
- */
- var clickHandler = function (event) {
- var toggle = event.target.closest( selector );
- console.log(toggle);
- if ( !toggle || toggle.tagName.toLowerCase() !== 'a' ) return;
- console.log(toggle.hash);
- var anchor = document.querySelector( toggle.hash );
- if ( !anchor ) return;
-
- event.preventDefault(); // Prevent default click event
- scroll.animateScroll( anchor, toggle, settings || {} ); // Animate scroll
- };
-
- window.addEventListener('click', clickHandler, false );
-};
-
-// Run our function
-smoothScrollWithoutHash( 'a[href*="#"]' );
-```
-
-
-
-## Support
-
-Please review the [support guidelines](SUPPORT.md).
-
## License
diff --git a/dist/js/smooth-scroll.js b/dist/smooth-scroll.js
similarity index 100%
rename from dist/js/smooth-scroll.js
rename to dist/smooth-scroll.js
diff --git a/dist/js/smooth-scroll.min.js b/dist/smooth-scroll.min.js
similarity index 100%
rename from dist/js/smooth-scroll.min.js
rename to dist/smooth-scroll.min.js
diff --git a/dist/js/smooth-scroll.polyfills.js b/dist/smooth-scroll.polyfills.js
similarity index 100%
rename from dist/js/smooth-scroll.polyfills.js
rename to dist/smooth-scroll.polyfills.js
diff --git a/dist/js/smooth-scroll.polyfills.min.js b/dist/smooth-scroll.polyfills.min.js
similarity index 100%
rename from dist/js/smooth-scroll.polyfills.min.js
rename to dist/smooth-scroll.polyfills.min.js
diff --git a/docs/dist/js/smooth-scroll.js b/docs/dist/smooth-scroll.js
similarity index 100%
rename from docs/dist/js/smooth-scroll.js
rename to docs/dist/smooth-scroll.js
diff --git a/docs/dist/js/smooth-scroll.min.js b/docs/dist/smooth-scroll.min.js
similarity index 100%
rename from docs/dist/js/smooth-scroll.min.js
rename to docs/dist/smooth-scroll.min.js
diff --git a/docs/dist/js/smooth-scroll.polyfills.js b/docs/dist/smooth-scroll.polyfills.js
similarity index 100%
rename from docs/dist/js/smooth-scroll.polyfills.js
rename to docs/dist/smooth-scroll.polyfills.js
diff --git a/docs/dist/js/smooth-scroll.polyfills.min.js b/docs/dist/smooth-scroll.polyfills.min.js
similarity index 100%
rename from docs/dist/js/smooth-scroll.polyfills.min.js
rename to docs/dist/smooth-scroll.polyfills.min.js
diff --git a/gulpfile.js b/gulpfile.js
index 2c41489..e8eb065 100755
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -66,7 +66,7 @@ var paths = {
scripts: {
input: 'src/js/*',
polyfills: '!src/js/*.polyfill.js',
- output: 'dist/js/'
+ output: 'dist/'
},
styles: {
input: 'src/sass/**/*.{scss,sass}',
diff --git a/package.json b/package.json
index af8a26d..34054ff 100755
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "smooth-scroll",
"version": "14.0.0",
"description": "Animate scrolling to anchor links",
- "main": "./dist/js/smooth-scroll.min.js",
+ "main": "./dist/smooth-scroll.min.js",
"author": {
"name": "Chris Ferdinandi",
"url": "http://gomakethings.com/"
From b64d4fd0596ef19ccfb381aa5e852dc0ac6ae716 Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Thu, 17 May 2018 23:13:50 -0400
Subject: [PATCH 08/51] Updated the readme
---
README.md | 41 ++++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 0c6bb31..33c64f4 100755
--- a/README.md
+++ b/README.md
@@ -22,22 +22,31 @@ There are two versions of Smooth Scroll: the standalone version, and one that co
If you're including your own polyfills or don't want to enable this feature for older browsers, use the standalone version. Otherwise, use the version with polyfills.
-**Direct `
-
-
-
```
-**NPM**
+**CDN**
+
+You can also use the [jsDelivr CDN](https://cdn.jsdelivr.net/gh/cferdinandi/smooth-scroll/dist/). I recommend linking to a specific version number or version range to prevent major updates from breaking your site. Smooth Scroll uses semantic versioning.
+
+```html
+
+
+
-```bash
-npm install smooth-scroll
+
+
+
+
+
+
+
+
```
### 2. Add the markup to your HTML.
@@ -65,6 +74,20 @@ In the footer of your page, after the content, initialize Smooth Scroll by passi
***Note:*** *The `a[href*="#"]` selector will apply Smooth Scroll to all anchor links. You can selectively target links using any other selector(s) you'd like. Smooth Scroll accepts multiple selectors as a comma separated list. Example: `'.js-scroll, [data-scroll], #some-link'`.*
+## ES6 Modules
+
+Smooth Scroll does not have a default export, but does support CommonJS and can be used with native ES6 module imports.
+
+```js
+import('/path/to/smooth-scroll.polyfills.min.js')
+ .then(function () {
+ var scroll = new SmoothScroll('a[href*="#"]');
+ });
+```
+
+It uses a UMD pattern, and should also work in most major module bundlers and package managers.
+
+
## Working with the Source Files
From 1dbadbc891dd7600f05b5d0b228fd6f6e4d81b7e Mon Sep 17 00:00:00 2001
From: cferdinandi
Date: Fri, 18 May 2018 10:34:11 -0400
Subject: [PATCH 09/51] v14.0.1 Fixed issues with updating the URL and
adjusting focus in certain situations
---
README.md | 14 ++++-----
dist/smooth-scroll.js | 39 +++++++++++-------------
dist/smooth-scroll.min.js | 4 +--
dist/smooth-scroll.polyfills.js | 39 +++++++++++-------------
dist/smooth-scroll.polyfills.min.js | 4 +--
docs/dist/smooth-scroll.js | 39 +++++++++++-------------
docs/dist/smooth-scroll.min.js | 4 +--
docs/dist/smooth-scroll.polyfills.js | 39 +++++++++++-------------
docs/dist/smooth-scroll.polyfills.min.js | 4 +--
docs/index.html | 2 +-
package.json | 2 +-
src/docs/_templates/_footer.html | 2 +-
src/js/smooth-scroll.js | 37 +++++++++++-----------
13 files changed, 107 insertions(+), 122 deletions(-)
diff --git a/README.md b/README.md
index 33c64f4..d5b7b76 100755
--- a/README.md
+++ b/README.md
@@ -230,8 +230,8 @@ Animate scrolling to an anchor.
```javascript
var scroll = new SmoothScroll();
scroll.animateScroll(
- anchor, // Node to scroll to. ex. document.querySelector( '#bazinga' )
- toggle, // Node that toggles the animation, OR an integer. ex. document.querySelector( '#toggle' )
+ anchor, // Node to scroll to. ex. document.querySelector('#bazinga')
+ toggle, // Node that toggles the animation, OR an integer. ex. document.querySelector('#toggle')
options // Classes and callbacks. Same options as those passed into the init() function.
);
```
@@ -240,18 +240,18 @@ scroll.animateScroll(
```javascript
var scroll = new SmoothScroll();
-var anchor = document.querySelector( '#bazinga' );
-scroll.animateScroll( anchor );
+var anchor = document.querySelector('#bazinga');
+scroll.animateScroll(anchor);
```
**Example 2**
```javascript
var scroll = new SmoothScroll();
-var anchor = document.querySelector( '#bazinga' );
+var anchor = document.querySelector('#bazinga');
var toggle = document.querySelector('#toggle');
var options = { speed: 1000, easing: 'easeOutCubic' };
-scroll.animateScroll( anchor, toggle, options );
+scroll.animateScroll(anchor, toggle, options);
```
**Example 3**
@@ -259,7 +259,7 @@ scroll.animateScroll( anchor, toggle, options );
```javascript
// You can optionally pass in a y-position to scroll to as an integer
var scroll = new SmoothScroll();
-scroll.animateScroll( 750 );
+scroll.animateScroll(750);
```
#### cancelScroll()
diff --git a/dist/smooth-scroll.js b/dist/smooth-scroll.js
index c0741d2..5f3e3de 100755
--- a/dist/smooth-scroll.js
+++ b/dist/smooth-scroll.js
@@ -1,5 +1,5 @@
/*!
- * smooth-scroll v14.0.0: Animate scrolling to anchor links
+ * smooth-scroll v14.0.1: Animate scrolling to anchor links
* (c) 2018 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/smooth-scroll
@@ -288,12 +288,17 @@
*/
var adjustFocus = function (anchor, endLocation, isNum) {
+ // Is scrolling to top of page, blur
+ if (anchor === 0) {
+ document.body.focus();
+ }
+
// Don't run if scrolling to a number on the page
if (isNum) return;
// Otherwise, bring anchor element into focus
anchor.focus();
- if (document.activeElement.id !== anchor.id) {
+ if (document.activeElement !== anchor) {
anchor.setAttribute('tabindex', '-1');
anchor.focus();
anchor.style.outline = 'none';
@@ -304,10 +309,14 @@
/**
* Update the URL
- * @param {Node} anchor The anchor that was scrolled to
- * @param {Object} options Settings for Smooth Scroll
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Boolean} isNum If true, anchor is a number
+ * @param {Object} options Settings for Smooth Scroll
*/
- var updateURL = function (anchor, options) {
+ var updateURL = function (anchor, isNum, options) {
+
+ // Bail if the anchor is a number
+ if (isNum) return;
// Verify that pushState is supported and the updateURL option is enabled
if (!history.pushState || !options.updateURL) return;
@@ -319,7 +328,7 @@
anchor: anchor.id
},
document.title,
- anchor === 0 ? '#top' : '#' + anchor.id
+ anchor === document.documentElement ? '#top' : '#' + anchor.id
);
};
@@ -459,7 +468,7 @@
}
// Update the URL
- updateURL(anchor, animateSettings);
+ updateURL(anchor, isNum, animateSettings);
// Emit a custom event
emitEvent('scrollStart', animateSettings, anchor, toggle);
@@ -491,21 +500,9 @@
// Get an escaped version of the hash
var hash = escapeCharacters(decode(toggle.hash));
- // If the hash is empty, scroll to the top of the page
- if (settings.topOnEmptyHash && ['#', '#top'].indexOf(hash) !== -1) {
-
- // Prevent default link behavior
- event.preventDefault();
-
- // Scroll to the top of the page
- smoothScroll.animateScroll(0, toggle);
-
- return;
-
- }
-
// Get the anchored element
- anchor = document.querySelector(hash);
+ var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
+ anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
// If anchored element exists, scroll to it
if (!anchor) return;
diff --git a/dist/smooth-scroll.min.js b/dist/smooth-scroll.min.js
index 9544052..75085f2 100755
--- a/dist/smooth-scroll.min.js
+++ b/dist/smooth-scroll.min.js
@@ -1,2 +1,2 @@
-/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+/*! smooth-scroll v14.0.1 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){0===t&&document.body.focus(),o||(t.focus(),document.activeElement!==t&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t,n){t||history.pushState&&n.updateURL&&history.pushState({smoothScroll:JSON.stringify(n),anchor:e.id},document.title,e===document.documentElement?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,u,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash)),o=g.topOnEmptyHash&&"#"===n?document.documentElement:document.querySelector(n);o=o||"#top"!==n?o:document.documentElement,o&&(t.preventDefault(),I.animateScroll(o,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/dist/smooth-scroll.polyfills.js b/dist/smooth-scroll.polyfills.js
index 265ad13..c7149c7 100755
--- a/dist/smooth-scroll.polyfills.js
+++ b/dist/smooth-scroll.polyfills.js
@@ -1,5 +1,5 @@
/*!
- * smooth-scroll v14.0.0: Animate scrolling to anchor links
+ * smooth-scroll v14.0.1: Animate scrolling to anchor links
* (c) 2018 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/smooth-scroll
@@ -358,12 +358,17 @@ if (window.Element && !Element.prototype.closest) {
*/
var adjustFocus = function (anchor, endLocation, isNum) {
+ // Is scrolling to top of page, blur
+ if (anchor === 0) {
+ document.body.focus();
+ }
+
// Don't run if scrolling to a number on the page
if (isNum) return;
// Otherwise, bring anchor element into focus
anchor.focus();
- if (document.activeElement.id !== anchor.id) {
+ if (document.activeElement !== anchor) {
anchor.setAttribute('tabindex', '-1');
anchor.focus();
anchor.style.outline = 'none';
@@ -374,10 +379,14 @@ if (window.Element && !Element.prototype.closest) {
/**
* Update the URL
- * @param {Node} anchor The anchor that was scrolled to
- * @param {Object} options Settings for Smooth Scroll
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Boolean} isNum If true, anchor is a number
+ * @param {Object} options Settings for Smooth Scroll
*/
- var updateURL = function (anchor, options) {
+ var updateURL = function (anchor, isNum, options) {
+
+ // Bail if the anchor is a number
+ if (isNum) return;
// Verify that pushState is supported and the updateURL option is enabled
if (!history.pushState || !options.updateURL) return;
@@ -389,7 +398,7 @@ if (window.Element && !Element.prototype.closest) {
anchor: anchor.id
},
document.title,
- anchor === 0 ? '#top' : '#' + anchor.id
+ anchor === document.documentElement ? '#top' : '#' + anchor.id
);
};
@@ -529,7 +538,7 @@ if (window.Element && !Element.prototype.closest) {
}
// Update the URL
- updateURL(anchor, animateSettings);
+ updateURL(anchor, isNum, animateSettings);
// Emit a custom event
emitEvent('scrollStart', animateSettings, anchor, toggle);
@@ -561,21 +570,9 @@ if (window.Element && !Element.prototype.closest) {
// Get an escaped version of the hash
var hash = escapeCharacters(decode(toggle.hash));
- // If the hash is empty, scroll to the top of the page
- if (settings.topOnEmptyHash && ['#', '#top'].indexOf(hash) !== -1) {
-
- // Prevent default link behavior
- event.preventDefault();
-
- // Scroll to the top of the page
- smoothScroll.animateScroll(0, toggle);
-
- return;
-
- }
-
// Get the anchored element
- anchor = document.querySelector(hash);
+ var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
+ anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
// If anchored element exists, scroll to it
if (!anchor) return;
diff --git a/dist/smooth-scroll.polyfills.min.js b/dist/smooth-scroll.polyfills.min.js
index 46ad04c..5a61d9d 100755
--- a/dist/smooth-scroll.polyfills.min.js
+++ b/dist/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
-/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var r=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(r)}};return function(r,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,r){var a=o(g||t,r||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var r=e.pageYOffset;if(t==o||r==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",a,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(a.speed,10),b=b>1?1:b,C=v+I*c(a,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,a),h("scrollStart",a,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+/*! smooth-scroll v14.0.1 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){0===t&&document.body.focus(),o||(t.focus(),document.activeElement!==t&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t,n){t||history.pushState&&n.updateURL&&history.pushState({smoothScroll:JSON.stringify(n),anchor:e.id},document.title,e===document.documentElement?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,a){var r=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",r,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,u,r),h("scrollStart",r,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash)),o=g.topOnEmptyHash&&"#"===n?document.documentElement:document.querySelector(n);o=o||"#top"!==n?o:document.documentElement,o&&(t.preventDefault(),A.animateScroll(o,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/dist/smooth-scroll.js b/docs/dist/smooth-scroll.js
index c0741d2..5f3e3de 100755
--- a/docs/dist/smooth-scroll.js
+++ b/docs/dist/smooth-scroll.js
@@ -1,5 +1,5 @@
/*!
- * smooth-scroll v14.0.0: Animate scrolling to anchor links
+ * smooth-scroll v14.0.1: Animate scrolling to anchor links
* (c) 2018 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/smooth-scroll
@@ -288,12 +288,17 @@
*/
var adjustFocus = function (anchor, endLocation, isNum) {
+ // Is scrolling to top of page, blur
+ if (anchor === 0) {
+ document.body.focus();
+ }
+
// Don't run if scrolling to a number on the page
if (isNum) return;
// Otherwise, bring anchor element into focus
anchor.focus();
- if (document.activeElement.id !== anchor.id) {
+ if (document.activeElement !== anchor) {
anchor.setAttribute('tabindex', '-1');
anchor.focus();
anchor.style.outline = 'none';
@@ -304,10 +309,14 @@
/**
* Update the URL
- * @param {Node} anchor The anchor that was scrolled to
- * @param {Object} options Settings for Smooth Scroll
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Boolean} isNum If true, anchor is a number
+ * @param {Object} options Settings for Smooth Scroll
*/
- var updateURL = function (anchor, options) {
+ var updateURL = function (anchor, isNum, options) {
+
+ // Bail if the anchor is a number
+ if (isNum) return;
// Verify that pushState is supported and the updateURL option is enabled
if (!history.pushState || !options.updateURL) return;
@@ -319,7 +328,7 @@
anchor: anchor.id
},
document.title,
- anchor === 0 ? '#top' : '#' + anchor.id
+ anchor === document.documentElement ? '#top' : '#' + anchor.id
);
};
@@ -459,7 +468,7 @@
}
// Update the URL
- updateURL(anchor, animateSettings);
+ updateURL(anchor, isNum, animateSettings);
// Emit a custom event
emitEvent('scrollStart', animateSettings, anchor, toggle);
@@ -491,21 +500,9 @@
// Get an escaped version of the hash
var hash = escapeCharacters(decode(toggle.hash));
- // If the hash is empty, scroll to the top of the page
- if (settings.topOnEmptyHash && ['#', '#top'].indexOf(hash) !== -1) {
-
- // Prevent default link behavior
- event.preventDefault();
-
- // Scroll to the top of the page
- smoothScroll.animateScroll(0, toggle);
-
- return;
-
- }
-
// Get the anchored element
- anchor = document.querySelector(hash);
+ var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
+ anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
// If anchored element exists, scroll to it
if (!anchor) return;
diff --git a/docs/dist/smooth-scroll.min.js b/docs/dist/smooth-scroll.min.js
index 9544052..75085f2 100755
--- a/docs/dist/smooth-scroll.min.js
+++ b/docs/dist/smooth-scroll.min.js
@@ -1,2 +1,2 @@
-/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void I.animateScroll(0,y);v=document.querySelector(n),v&&(t.preventDefault(),I.animateScroll(v,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
+/*! smooth-scroll v14.0.1 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
+!(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){for(var e={},t=0;t=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},f=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){0===t&&document.body.focus(),o||(t.focus(),document.activeElement!==t&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},m=function(e,t,n){t||history.pushState&&n.updateURL&&history.pushState({smoothScroll:JSON.stringify(n),anchor:e.id},document.title,e===document.documentElement?"#top":"#"+e.id)},h=function(t,n,o,r){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:r}});document.dispatchEvent(a)}};return function(a,p){var g,v,y,S,E,b,O,I={};I.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||h("scrollCancel",g)},I.animateScroll=function(n,r,a){var i=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;i.header&&!S&&(S=document.querySelector(i.header)),E||(E=f(S));var y,b,C,L=u?n:l(p,E,parseInt("function"==typeof i.offset?i.offset():i.offset,10)),w=L-v,A=s(),H=0,Q=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=A)return I.cancelScroll(!0),d(n,o,u),h("scrollStop",i,n,r),y=null,O=null,!0},q=function(t){y||(y=t),H+=t-y,b=H/parseInt(i.speed,10),b=b>1?1:b,C=v+w*c(i,b),e.scrollTo(0,Math.floor(C)),Q(C,L)||(O=e.requestAnimationFrame(q),y=t)};0===e.pageYOffset&&e.scrollTo(0,0),m(n,u,i),h("scrollStart",i,n,r),I.cancelScroll(!0),e.requestAnimationFrame(q)}};var C=function(t){if(!r()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(y=t.target.closest(a))&&"a"===y.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&y.hostname===e.location.hostname&&y.pathname===e.location.pathname&&/#/.test(y.href)){var n=u(i(y.hash)),o=g.topOnEmptyHash&&"#"===n?document.documentElement:document.querySelector(n);o=o||"#top"!==n?o:document.documentElement,o&&(t.preventDefault(),I.animateScroll(o,y))}},L=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(i(history.state.anchor)));t&&I.animateScroll(t,null,{updateURL:!1})}},w=function(e){b||(b=setTimeout((function(){b=null,E=f(S)}),66))};return I.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",w,!1),e.removeEventListener("popstate",L,!1),I.cancelScroll(),g=null,v=null,y=null,S=null,E=null,b=null,O=null)},I.init=function(r){n()&&(I.destroy(),g=o(t,r||{}),S=g.header?document.querySelector(g.header):null,E=f(S),document.addEventListener("click",C,!1),S&&e.addEventListener("resize",w,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",L,!1))},I.init(p),I}}));
\ No newline at end of file
diff --git a/docs/dist/smooth-scroll.polyfills.js b/docs/dist/smooth-scroll.polyfills.js
index 265ad13..c7149c7 100755
--- a/docs/dist/smooth-scroll.polyfills.js
+++ b/docs/dist/smooth-scroll.polyfills.js
@@ -1,5 +1,5 @@
/*!
- * smooth-scroll v14.0.0: Animate scrolling to anchor links
+ * smooth-scroll v14.0.1: Animate scrolling to anchor links
* (c) 2018 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/smooth-scroll
@@ -358,12 +358,17 @@ if (window.Element && !Element.prototype.closest) {
*/
var adjustFocus = function (anchor, endLocation, isNum) {
+ // Is scrolling to top of page, blur
+ if (anchor === 0) {
+ document.body.focus();
+ }
+
// Don't run if scrolling to a number on the page
if (isNum) return;
// Otherwise, bring anchor element into focus
anchor.focus();
- if (document.activeElement.id !== anchor.id) {
+ if (document.activeElement !== anchor) {
anchor.setAttribute('tabindex', '-1');
anchor.focus();
anchor.style.outline = 'none';
@@ -374,10 +379,14 @@ if (window.Element && !Element.prototype.closest) {
/**
* Update the URL
- * @param {Node} anchor The anchor that was scrolled to
- * @param {Object} options Settings for Smooth Scroll
+ * @param {Node} anchor The anchor that was scrolled to
+ * @param {Boolean} isNum If true, anchor is a number
+ * @param {Object} options Settings for Smooth Scroll
*/
- var updateURL = function (anchor, options) {
+ var updateURL = function (anchor, isNum, options) {
+
+ // Bail if the anchor is a number
+ if (isNum) return;
// Verify that pushState is supported and the updateURL option is enabled
if (!history.pushState || !options.updateURL) return;
@@ -389,7 +398,7 @@ if (window.Element && !Element.prototype.closest) {
anchor: anchor.id
},
document.title,
- anchor === 0 ? '#top' : '#' + anchor.id
+ anchor === document.documentElement ? '#top' : '#' + anchor.id
);
};
@@ -529,7 +538,7 @@ if (window.Element && !Element.prototype.closest) {
}
// Update the URL
- updateURL(anchor, animateSettings);
+ updateURL(anchor, isNum, animateSettings);
// Emit a custom event
emitEvent('scrollStart', animateSettings, anchor, toggle);
@@ -561,21 +570,9 @@ if (window.Element && !Element.prototype.closest) {
// Get an escaped version of the hash
var hash = escapeCharacters(decode(toggle.hash));
- // If the hash is empty, scroll to the top of the page
- if (settings.topOnEmptyHash && ['#', '#top'].indexOf(hash) !== -1) {
-
- // Prevent default link behavior
- event.preventDefault();
-
- // Scroll to the top of the page
- smoothScroll.animateScroll(0, toggle);
-
- return;
-
- }
-
// Get the anchored element
- anchor = document.querySelector(hash);
+ var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
+ anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
// If anchored element exists, scroll to it
if (!anchor) return;
diff --git a/docs/dist/smooth-scroll.polyfills.min.js b/docs/dist/smooth-scroll.polyfills.min.js
index 46ad04c..5a61d9d 100755
--- a/docs/dist/smooth-scroll.polyfills.min.js
+++ b/docs/dist/smooth-scroll.polyfills.min.js
@@ -1,2 +1,2 @@
-/*! smooth-scroll v14.0.0 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
-window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?r(e)+e.offsetTop:0},d=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t){history.pushState&&t.updateURL&&history.pushState({smoothScroll:JSON.stringify(t),anchor:e.id},document.title,0===e?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var r=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(r)}};return function(r,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,r){var a=o(g||t,r||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;a.header&&!y&&(y=document.querySelector(a.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof a.offset?a.offset():a.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var r=e.pageYOffset;if(t==o||r==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",a,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(a.speed,10),b=b>1?1:b,C=v+I*c(a,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,a),h("scrollStart",a,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(r))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(a(w.hash));if(g.topOnEmptyHash&&-1!==["#","#top"].indexOf(n))return t.preventDefault(),void A.animateScroll(0,w);v=document.querySelector(n),v&&(t.preventDefault(),A.animateScroll(v,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(a(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
+/*! smooth-scroll v14.0.1 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
+window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===r?a+="\\"+t.toString(16)+" ":a+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+a)}catch(e){u="#"+a}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(e,t,n){var o=0;if(e.offsetParent)do{o+=e.offsetTop,e=e.offsetParent}while(e);return o=Math.max(o-t-n,0)},m=function(e){return e?a(e)+e.offsetTop:0},d=function(t,n,o){0===t&&document.body.focus(),o||(t.focus(),document.activeElement!==t&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},f=function(e,t,n){t||history.pushState&&n.updateURL&&history.pushState({smoothScroll:JSON.stringify(n),anchor:e.id},document.title,e===document.documentElement?"#top":"#"+e.id)},h=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var a=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(a)}};return function(a,p){var g,v,w,y,E,b,S,A={};A.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||h("scrollCancel",g)},A.animateScroll=function(n,i,a){var r=o(g||t,a||{}),u="[object Number]"===Object.prototype.toString.call(n),p=u||!n.tagName?null:n;if(u||p){var v=e.pageYOffset;r.header&&!y&&(y=document.querySelector(r.header)),E||(E=m(y));var w,b,C,O=u?n:l(p,E,parseInt("function"==typeof r.offset?r.offset():r.offset,10)),I=O-v,q=s(),F=0,L=function(t,o){var a=e.pageYOffset;if(t==o||a==o||(v=q)return A.cancelScroll(!0),d(n,o,u),h("scrollStop",r,n,i),w=null,S=null,!0},H=function(t){w||(w=t),F+=t-w,b=F/parseInt(r.speed,10),b=b>1?1:b,C=v+I*c(r,b),e.scrollTo(0,Math.floor(C)),L(C,O)||(S=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),f(n,u,r),h("scrollStart",r,n,i),A.cancelScroll(!0),e.requestAnimationFrame(H)}};var C=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&(w=t.target.closest(a))&&"a"===w.tagName.toLowerCase()&&!t.target.closest(g.ignore)&&w.hostname===e.location.hostname&&w.pathname===e.location.pathname&&/#/.test(w.href)){var n=u(r(w.hash)),o=g.topOnEmptyHash&&"#"===n?document.documentElement:document.querySelector(n);o=o||"#top"!==n?o:document.documentElement,o&&(t.preventDefault(),A.animateScroll(o,w))}},O=function(e){if(history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(g)&&history.state.anchor){var t=document.querySelector(u(r(history.state.anchor)));t&&A.animateScroll(t,null,{updateURL:!1})}},I=function(e){b||(b=setTimeout((function(){b=null,E=m(y)}),66))};return A.destroy=function(){g&&(document.removeEventListener("click",C,!1),e.removeEventListener("resize",I,!1),e.removeEventListener("popstate",O,!1),A.cancelScroll(),g=null,v=null,w=null,y=null,E=null,b=null,S=null)},A.init=function(i){n()&&(A.destroy(),g=o(t,i||{}),y=g.header?document.querySelector(g.header):null,E=m(y),document.addEventListener("click",C,!1),y&&e.addEventListener("resize",I,!1),g.updateURL&&g.popstate&&e.addEventListener("popstate",O,!1))},A.init(p),A}}));
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
index be9ff69..8d01595 100755
--- a/docs/index.html
+++ b/docs/index.html
@@ -91,7 +91,7 @@