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:
@@ -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;
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user