mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-15 23:07:18 +00:00
Add support to tm-scroll message for scrolling without animating (#6410)
* feat: add support for animationDuration attribute of paramObject for tm-scroll message * docs: added docs for animationDuration attribute of tm-scroll message * fix: use .utils.hop instead of Object.hasOwnProperty() * fix: do not check if object before calling utils.hop() * fix: syntax
This commit is contained in:
@@ -38,10 +38,14 @@ ScrollableWidget.prototype.handleScrollEvent = function(event) {
|
||||
if(this.outerDomNode.scrollWidth <= this.outerDomNode.offsetWidth && this.outerDomNode.scrollHeight <= this.outerDomNode.offsetHeight && this.fallthrough === "yes") {
|
||||
return true;
|
||||
}
|
||||
var options = {};
|
||||
if($tw.utils.hop(event.paramObject,"animationDuration")) {
|
||||
options.animationDuration = event.paramObject.animationDuration;
|
||||
}
|
||||
if(event.paramObject && event.paramObject.selector) {
|
||||
this.scrollSelectorIntoView(null,event.paramObject.selector);
|
||||
this.scrollSelectorIntoView(null,event.paramObject.selector,null,options);
|
||||
} else {
|
||||
this.scrollIntoView(event.target);
|
||||
this.scrollIntoView(event.target,null,options);
|
||||
}
|
||||
return false; // Handled event
|
||||
};
|
||||
@@ -49,9 +53,9 @@ ScrollableWidget.prototype.handleScrollEvent = function(event) {
|
||||
/*
|
||||
Scroll an element into view
|
||||
*/
|
||||
ScrollableWidget.prototype.scrollIntoView = function(element) {
|
||||
var duration = $tw.utils.getAnimationDuration(),
|
||||
srcWindow = element ? element.ownerDocument.defaultView : window;
|
||||
ScrollableWidget.prototype.scrollIntoView = function(element,callback,options) {
|
||||
var duration = $tw.utils.hop(options,"animationDuration") ? parseInt(options.animationDuration) : $tw.utils.getAnimationDuration(),
|
||||
srcWindow = element ? element.ownerDocument.defaultView : window;
|
||||
this.cancelScroll();
|
||||
this.startTime = Date.now();
|
||||
var scrollPosition = {
|
||||
@@ -114,11 +118,11 @@ ScrollableWidget.prototype.scrollIntoView = function(element) {
|
||||
}
|
||||
};
|
||||
|
||||
ScrollableWidget.prototype.scrollSelectorIntoView = function(baseElement,selector,callback) {
|
||||
ScrollableWidget.prototype.scrollSelectorIntoView = function(baseElement,selector,callback,options) {
|
||||
baseElement = baseElement || document.body;
|
||||
var element = baseElement.querySelector(selector);
|
||||
if(element) {
|
||||
this.scrollIntoView(element,callback);
|
||||
this.scrollIntoView(element,callback,options);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user