1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-01-24 11:54:41 +00:00

Compare commits

..

9 Commits

Author SHA1 Message Date
Jeremy Ruston
81679b8514 Neatening up 2023-07-30 18:00:17 +01:00
Jeremy Ruston
4a39097fee Simplify method naming 2023-07-29 16:52:28 +01:00
Jeremy Ruston
99232c3c82 Resolve another inefficiency
The transclusion target was sometimes being parsed twice when transcluding as text/plain

Associated test results are also made more consistent
2023-07-29 16:31:10 +01:00
Jeremy Ruston
fa5bae0150 Split getTransclusionTarget into getTransclusionTargetIncludingParseTreeNodes 2023-07-29 15:55:31 +01:00
Jeremy Ruston
091cc3c26e Preparing to split getTransclusionTarget into two separate functions 2023-07-29 15:03:46 +01:00
Jeremy Ruston
fd95a942aa Refactor condition logic 2023-07-29 11:55:42 +01:00
Jeremy Ruston
7e86cdf44d Add a test to avoid regressions on the handling of macros vs procedures 2023-07-27 22:05:24 +01:00
Jeremy Ruston
2c58a0ac71 Refactor missing transclusion target 2023-07-27 18:48:01 +01:00
Jeremy Ruston
c4fc3168d1 Refactor parse mode out of getTransclusionTarget 2023-07-27 18:39:59 +01:00
4 changed files with 3 additions and 72 deletions

View File

@@ -171,42 +171,6 @@ ScrollableWidget.prototype.render = function(parent,nextSibling) {
parent.insertBefore(this.outerDomNode,nextSibling);
this.renderChildren(this.innerDomNode,null);
this.domNodes.push(this.outerDomNode);
// If the scroll position is bound to a tiddler
if(this.scrollableBind) {
// After a delay for rendering, scroll to the bound position
setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50);
// Save scroll position on DOM scroll event
this.outerDomNode.addEventListener("scroll",function(event) {
var existingTiddler = self.wiki.getTiddler(self.scrollableBind),
newTiddlerFields = {
title: self.scrollableBind,
"scroll-left": self.outerDomNode.scrollLeft.toString(),
"scroll-top": self.outerDomNode.scrollTop.toString()
};
if(!existingTiddler || (existingTiddler.fields["scroll-left"] !== newTiddlerFields["scroll-left"] || existingTiddler.fields["scroll-top"] !== newTiddlerFields["scroll-top"])) {
self.wiki.addTiddler(new $tw.Tiddler(existingTiddler,newTiddlerFields));
}
});
}
};
ScrollableWidget.prototype.updateScrollPositionFromBoundTiddler = function() {
var tiddler = this.wiki.getTiddler(this.scrollableBind);
if(tiddler) {
var scrollLeftTo = this.outerDomNode.scrollLeft;
if(parseFloat(tiddler.fields["scroll-left"]).toString() === tiddler.fields["scroll-left"]) {
scrollLeftTo = parseFloat(tiddler.fields["scroll-left"]);
}
var scrollTopTo = this.outerDomNode.scrollTop;
if(parseFloat(tiddler.fields["scroll-top"]).toString() === tiddler.fields["scroll-top"]) {
scrollTopTo = parseFloat(tiddler.fields["scroll-top"]);
}
this.outerDomNode.scrollTo({
top: scrollTopTo,
left: scrollLeftTo,
behavior: "instant"
})
}
};
/*
@@ -214,7 +178,6 @@ Compute the internal state of the widget
*/
ScrollableWidget.prototype.execute = function() {
// Get attributes
this.scrollableBind = this.getAttribute("bind");
this.fallthrough = this.getAttribute("fallthrough","yes");
this["class"] = this.getAttribute("class");
// Make child widgets
@@ -230,9 +193,6 @@ ScrollableWidget.prototype.refresh = function(changedTiddlers) {
this.refreshSelf();
return true;
}
if(changedAttributes.bind || changedTiddlers[this.getAttribute("bind")]) {
this.updateScrollPositionFromBoundTiddler();
}
return this.refreshChildren(changedTiddlers);
};

View File

@@ -9,10 +9,9 @@ type: text/vnd.tiddlywiki
! Overview of v5.3.1
! Bug Fixes and Reversions of v5.3.0 Changes
! Reversions of v5.3.0 Changes
* Reverted adding the `widget.destroy()` method because of performance concerns (see https://github.com/Jermolene/TiddlyWiki5/pull/7468)
* <<.link-badge-fixed "https://github.com/Jermolene/TiddlyWiki5/pull/7647">> inefficiency when transcluding with the ''$output'' attribute set to `text/plain`
! Plugin Improvements

View File

@@ -1,3 +0,0 @@
title: $:/my-scroll-position
scroll-left: 0
scroll-top: 100

View File

@@ -1,6 +1,6 @@
caption: scrollable
created: 20140324223413403
modified: 20230731100903977
modified: 20220620115347910
tags: Widgets
title: ScrollableWidget
type: text/vnd.tiddlywiki
@@ -16,15 +16,12 @@ The content of the `<$scrollable>` widget is displayed within a pair of wrapper
|!Attribute |!Description |
|class |The CSS class(es) to be applied to the outer DIV |
|fallthrough |See below |
|bind |<<.from-version "5.3.2">> Optional title of tiddler to which the scroll position should be bound |
Binding the scroll position to a tiddler automatically copies the scroll coordinates into the `scroll-left` and `scroll-top` fields as scrolling occurs. Conversely, setting those field values will automatically cause the scrollable to scroll if it can.
<$macrocall $name=".note" _="""If a scrollable widget can't handle the `tm-scroll` message because the inner DIV fits within the outer DIV, then by default the message falls through to the parent widget. Setting the ''fallthrough'' attribute to `no` prevents this behaviour."""/>
! Examples
These examples require the following CSS definitions from [[$:/_tw5.com-styles]]:
This example requires the following CSS definitions from [[$:/_tw5.com-styles]]:
```
.tc-scrollable-demo {
@@ -36,8 +33,6 @@ These examples require the following CSS definitions from [[$:/_tw5.com-styles]]
}
```
!! Simple Usage
This wiki text shows how to display a list within the scrollable widget:
<<wikitext-example-without-html "<$scrollable class='tc-scrollable-demo'>
@@ -51,23 +46,3 @@ This wiki text shows how to display a list within the scrollable widget:
</$scrollable>
">>
!! Binding scroll position to a tiddler
[[Current scroll position|$:/my-scroll-position]]: {{$:/my-scroll-position!!scroll-left}}, {{$:/my-scroll-position!!scroll-top}}
<$button>
<$action-setfield $tiddler="$:/my-scroll-position" scroll-left="100" scroll-top="100"/>
Set current scroll position to 100,100
</$button>
<<wikitext-example-without-html "<$scrollable class='tc-scrollable-demo' bind='$:/my-scroll-position'>
<$list filter='[tag[Reference]]'>
<$view field='title'/>: <$list filter='[all[current]links[]sort[title]]' storyview='pop'>
<$link><$view field='title'/></$link>
</$list>
</$list>
</$scrollable>
">>