1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-02 00:22:59 +00:00

Extend tm-scroll to accept CSS selector to identify the target

This commit is contained in:
jeremy@jermolene.com
2020-10-14 15:59:27 +01:00
parent 69c12618d9
commit 1446a1e44c
3 changed files with 30 additions and 6 deletions

View File

@@ -49,7 +49,12 @@ Handle an event
*/
PageScroller.prototype.handleEvent = function(event) {
if(event.type === "tm-scroll") {
return this.scrollIntoView(event.target);
if(event.paramObject && event.paramObject.selector) {
this.scrollSelectorIntoView(null,event.paramObject.selector);
} else {
this.scrollIntoView(event.target);
}
return false; // Event was handled
}
return true;
};
@@ -117,6 +122,14 @@ PageScroller.prototype.scrollIntoView = function(element,callback) {
drawFrame();
};
PageScroller.prototype.scrollSelectorIntoView = function(baseElement,selector,callback) {
baseElement = baseElement || document.body;
var element = baseElement.querySelector(selector);
if(element) {
this.scrollIntoView(element,callback);
}
};
exports.PageScroller = PageScroller;
})();