Skip to content

Commit

Permalink
fix Scroller.scrollTo + add complete option
Browse files Browse the repository at this point in the history
  • Loading branch information
dasiux committed Apr 26, 2022
1 parent d1bada8 commit 0b089e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 0.8.5
- Added *options.complete* for *Scroller* class to provide a default complete callback option.
- Fixed *Scroller.event_scrollToClick()* event target, should be currentTarget.

## 0.8.4
- Fixed *scrollTo* functions *withTop* option to respect scroll position.
- Added *Plugins.require()* to check for and fetch required plugins or throw and error.
- Added *Plugins.require()* to check for and fetch required plugins or throw an error.

## 0.8.3
- Minor improvements.
Expand Down
2 changes: 1 addition & 1 deletion docs/es6/Animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Scroller extends EventDispatcher {
selector : String // Scroll to link selector, default: [href^="#"]
capture : Boolean // Capture initial scroll, default: true
initial : Number|'ready' // Initial scroll delay after capture
hashClean : Number // scrollComplete delay, default: 300
complete : null|Function // Complete callback for local scrollTo
}
initial : null|HTMLElement // Initial scroll-to target
scrollTo( element, complete = null ) {} // void
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@squirrel-forge/ui-util",
"version": "0.8.4",
"version": "0.8.5",
"description": "A collection of utilities, classes, functions and abstracts made for the browser and babel compatible.",
"main": "src/es6/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/es6/Animation/Scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { isPojo } from '../Object/isPojo.js';
* @property {string} selector - Scroll to link selector, default: [href^="#"]
* @property {boolean} capture - Capture initial scroll, default: true
* @property {number|'ready'} initial - Initial scroll delay after capture
* @property {null|Function} complete - Complete callback for local scrollTo
*/

/**
Expand Down Expand Up @@ -69,6 +70,7 @@ export class Scroller extends EventDispatcher {
selector : '[href^="#"]',
capture : true,
initial : 1000,
complete : null,
};

// Update config
Expand All @@ -88,10 +90,11 @@ export class Scroller extends EventDispatcher {
* @param {null|Function} complete - Complete callback
* @return {void}
*/
scrollTo( element, complete = null ) {
scrollTo( element, complete ) {
let params = this.config.offset;
if ( !( params instanceof Array ) ) params = [ params ];
params.unshift( element );
if ( typeof complete === 'undefined' ) complete = this.config.complete;
if ( typeof complete === 'function' ) scrollComplete( complete );
scrollTo( ...params );
}
Expand All @@ -103,7 +106,7 @@ export class Scroller extends EventDispatcher {
* @return {void}
*/
#event_scrollToClick( event ) {
const id = event.target.getAttribute( 'href' ).substr( 1 );
const id = event.currentTarget.getAttribute( 'href' ).substr( 1 );
const target = document.getElementById( id );
if ( target ) {
this.scrollTo( target );
Expand Down

0 comments on commit 0b089e4

Please sign in to comment.