Skip to content

Commit

Permalink
Merge pull request #29 from UFHealth/patch/oops-missing-defaults-for-to
Browse files Browse the repository at this point in the history
Fix missing defaults for `To` method
  • Loading branch information
billcolumbia authored Feb 5, 2020
2 parents 3e501d5 + 8aa9d45 commit 1e69a8d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion dist/butr.js

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions example/as-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import Butr from './butr'

document.addEventListener('DOMContentLoaded', () => {
Butr.init({
To: false,
Marker: true,
AutoAnchors: true,
AutoSidebar: true,
StickyNav: true,
scrollOffset: 126,
distanceTop: 0,
topBuffer: 30,
avoid: '.Footer',
avoidBuffer: 24,
scrollOffset: 128,
mediaQuery: '(min-width: 1200px)'
})
Butr.to({
target: 500
})
})
4 changes: 2 additions & 2 deletions example/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/butr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "butr",
"version": "1.0.1",
"version": "1.0.2",
"description": "Scroll like butter",
"contributors": [
"Bill Columbia <[email protected]>",
Expand Down
7 changes: 1 addition & 6 deletions src/autoAnchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ export const AutoAnchors = () => {
links[i].addEventListener('click', e => {
e.preventDefault()
To({
target: e.currentTarget.getAttribute('href'),
direction: State.settings.direction,
keepHash: State.settings.keepHash,
speed: State.settings.speed,
afterTo: State.settings.afterTo,
scrollOffset: State.settings.scrollOffset
target: e.currentTarget.getAttribute('href')
})
})
}
Expand Down
7 changes: 0 additions & 7 deletions src/butr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import { StickyNav } from './stickyNav'
import { State } from './state'

const defaults = {
// To
target: 0,
direction: 'y',
keepHash: true,
speed: 1,
afterTo: null,
scrollOffset: 0,
// Sidebar
olClass: 'Butr__Sidebar__List',
liClass: 'Butr__Sidebar__Item',
Expand Down
21 changes: 17 additions & 4 deletions src/to.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import { State } from './state'
* A stand alone, globally accessible method for scrolling to a target
* (location or hash).
*/
export const To = (options = {}) => {
options = Object.assign({}, State.settings, options)
export const To = (options) => {
const defaults = {
target: 0,
direction: 'y',
keepHash: true,
speed: 1,
afterTo: null,
/**
* A global offset can be passed from Butr's initialization that will be used
* as the default instead of 0 when needed. Otherwise it can be explicitly
* set when using To() or Butr.to()
*/
scrollOffset: State.settings.scrollOffset || 0,
}
options = Object.assign({}, defaults, options)

// User may prefer reduced motion - do not animate to scroll position
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion)').matches
Expand All @@ -35,7 +48,7 @@ export const To = (options = {}) => {
*/
const getCurrentPosition = () => {
if (options.direction === 'x') return scrollingElement.scrollLeft
if (options.direction === 'y') return scrollingElement.scrollTop
else return scrollingElement.scrollTop
}

/**
Expand Down Expand Up @@ -67,7 +80,7 @@ export const To = (options = {}) => {
*/
const scrollTheEl = distance => {
if (options.direction === 'x') scrollingElement.scrollLeft = distance
if (options.direction === 'y') scrollingElement.scrollTop = distance
else scrollingElement.scrollTop = distance
}

/**
Expand Down

0 comments on commit 1e69a8d

Please sign in to comment.