Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default anonymous source to nearest #208

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

johannesodland
Copy link
Contributor

The progress demo is currently throwing a "TypeError: Invalid ScrollTimeline Source Type".

This happens because

  1. parseAnonymousScrollTimeline() does not set a default source
  2. getAnonymousSourceElement() requires a source, and will throw an error if one is not set.

Adding 'nearest' as a default anonymous source in getAnonymousScrollTimelineOptions(), the same place a default value for axis is set.

parseAnonymousScrollTimeline(part) {
const anonymousMatch = RegexMatcher.ANONYMOUS_SCROLL_TIMELINE.exec(part);
if(!anonymousMatch)
return null;
const value = anonymousMatch[VALUES_CAPTURE_INDEX];
const options = {};
value.split(" ").forEach(token => {
if(TIMELINE_AXIS_TYPES.includes(token)) {
options['axis'] = token;
} else if(ANONYMOUS_TIMELINE_SOURCE_TYPES.includes(token)) {
options['source'] = token;
}
});
return options;
}

getAnonymousScrollTimelineOptions(timelineName, target) {
const options = this.anonymousScrollTimelineOptions.get(timelineName);
if(options) {
return {
anonymousSource: options.source,
anonymousTarget: target,
source: getAnonymousSourceElement(options.source, target),
axis: (options.axis ? options.axis : 'block'),
};
}
return null;
}

export function getAnonymousSourceElement(sourceType, node) {
switch (sourceType) {
case 'root':
return document.scrollingElement;
case 'nearest':
return getScrollParent(node);
case 'self':
return node;
default:
throw new TypeError('Invalid ScrollTimeline Source Type.');
}
}

@bramus bramus merged commit c4c79e9 into flackr:master Jan 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants