Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Add "silent" option #438

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ var scroll = new SmoothScroll('a[href*="#"]', {
// Custom Events
emitEvents: true // Emit custom events

// Logging & Errors
silent: false // if set to true, if the browser does not support necessary features, the library will not work, and no error will be thrown

});
```

Expand Down Expand Up @@ -372,4 +375,4 @@ Most browsers instantly jump you to the anchor location when you load a page. Yo

## License

The code is available under the [MIT License](LICENSE.md).
The code is available under the [MIT License](LICENSE.md).
26 changes: 19 additions & 7 deletions dist/smooth-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
popstate: true,

// Custom Events
emitEvents: true
emitEvents: true,

// Error Logging
silent: false
};


Expand Down Expand Up @@ -585,15 +588,24 @@
* @param {Object} options User settings
*/
smoothScroll.init = function (options) {

// feature test
if (!supports()) throw 'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.';

// Destroy any existing initializations
smoothScroll.destroy();

// Selectors and variables
// base settings
settings = extend(defaults, options || {}); // Merge user options with defaults

// feature test
if (!supports()) {
// if silent is set to true, no error but it won't work in unsupported
// browsers
if (settings.silent) {
return;
} else {
throw 'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.';
}
}

// Selectors and variables
fixedHeader = settings.header ? document.querySelector(settings.header) : null; // Get the fixed header
headerHeight = getHeaderHeight(fixedHeader);

Expand Down Expand Up @@ -630,4 +642,4 @@

return SmoothScroll;

}));
}));
2 changes: 1 addition & 1 deletion dist/smooth-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions dist/smooth-scroll.polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ if (window.Element && !Element.prototype.closest) {
popstate: true,

// Custom Events
emitEvents: true
emitEvents: true,

// Error Logging
silent: false
};


Expand Down Expand Up @@ -655,15 +658,24 @@ if (window.Element && !Element.prototype.closest) {
* @param {Object} options User settings
*/
smoothScroll.init = function (options) {

// feature test
if (!supports()) throw 'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.';

// Destroy any existing initializations
smoothScroll.destroy();

// Selectors and variables
// base settings
settings = extend(defaults, options || {}); // Merge user options with defaults

// feature test
if (!supports()) {
// if silent is set to true, no error but it won't work in unsupported
// browsers
if (settings.silent) {
return;
} else {
throw 'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.';
}
}

// Selectors and variables
fixedHeader = settings.header ? document.querySelector(settings.header) : null; // Get the fixed header
headerHeight = getHeaderHeight(fixedHeader);

Expand Down Expand Up @@ -700,4 +712,4 @@ if (window.Element && !Element.prototype.closest) {

return SmoothScroll;

}));
}));
Loading