mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 03:27:18 +00:00
Handle switching the bound tiddler (#7868)
This commit is contained in:
parent
f7359671aa
commit
e60ddf0b0a
@ -177,14 +177,16 @@ ScrollableWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
if(this.scrollableBind) {
|
if(this.scrollableBind) {
|
||||||
// After a delay for rendering, scroll to the bound position
|
// After a delay for rendering, scroll to the bound position
|
||||||
setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50);
|
setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50);
|
||||||
// Save scroll position on DOM scroll event
|
// Set up event listener
|
||||||
var timeout;
|
this.currentListener = this.listenerFunction.bind(this);
|
||||||
this.outerDomNode.addEventListener("scroll",function(event) {
|
this.outerDomNode.addEventListener("scroll", this.currentListener);
|
||||||
if(timeout) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
timeout = null;
|
|
||||||
}
|
}
|
||||||
timeout = setTimeout(function() {
|
};
|
||||||
|
|
||||||
|
ScrollableWidget.prototype.listenerFunction = function(event) {
|
||||||
|
self = this;
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
this.timeout = setTimeout(function() {
|
||||||
var existingTiddler = self.wiki.getTiddler(self.scrollableBind),
|
var existingTiddler = self.wiki.getTiddler(self.scrollableBind),
|
||||||
newTiddlerFields = {
|
newTiddlerFields = {
|
||||||
title: self.scrollableBind,
|
title: self.scrollableBind,
|
||||||
@ -195,9 +197,7 @@ ScrollableWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
self.wiki.addTiddler(new $tw.Tiddler(existingTiddler,newTiddlerFields));
|
self.wiki.addTiddler(new $tw.Tiddler(existingTiddler,newTiddlerFields));
|
||||||
}
|
}
|
||||||
}, DEBOUNCE_INTERVAL);
|
}, DEBOUNCE_INTERVAL);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ScrollableWidget.prototype.updateScrollPositionFromBoundTiddler = function() {
|
ScrollableWidget.prototype.updateScrollPositionFromBoundTiddler = function() {
|
||||||
// Bail if we're running on the fakedom
|
// Bail if we're running on the fakedom
|
||||||
@ -243,8 +243,19 @@ ScrollableWidget.prototype.refresh = function(changedTiddlers) {
|
|||||||
this.refreshSelf();
|
this.refreshSelf();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(changedAttributes.bind || changedTiddlers[this.getAttribute("bind")]) {
|
// If the bound tiddler has changed, update the eventListener and update scroll position
|
||||||
this.updateScrollPositionFromBoundTiddler();
|
if(changedAttributes["bind"]) {
|
||||||
|
if(this.currentListener) {
|
||||||
|
this.outerDomNode.removeEventListener("scroll", this.currentListener, false);
|
||||||
|
}
|
||||||
|
this.scrollableBind = this.getAttribute("bind");
|
||||||
|
this.currentListener = this.listenerFunction.bind(this);
|
||||||
|
this.outerDomNode.addEventListener("scroll", this.currentListener);
|
||||||
|
setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50);
|
||||||
|
}
|
||||||
|
// If a new scroll position was written into the tiddler, update scroll position
|
||||||
|
if(changedTiddlers[this.getAttribute("bind")]) {
|
||||||
|
setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50);
|
||||||
}
|
}
|
||||||
return this.refreshChildren(changedTiddlers);
|
return this.refreshChildren(changedTiddlers);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user