Full control of window contents created by the tm-open-window message?

71 views
Skip to first unread message

IsoLin.CHiP

unread,
Nov 27, 2016, 5:49:33 PM11/27/16
to TiddlyWikiDev
Hi,

I am trying to integrate reveal.js [1] in a convenient way, such that I can use TiddlyWiki to edit and store the presentation slides, but then simply launch it straight from the wiki. Aditionally I am considering an export mode as well, for creating standalone versions.

While I still have various challenges to solve, I am currently stumped trying to open a new window with the reveal.js library loaded together with the slides. My idea was to use the existing `tm-open-window` message and a custom template. However I am having trouble finding out how I could take full control of the document being displayed in the new window.

While reading through `$:/core/modules/startup/windows.js` I am getting the impression there is no way to actually just dump a template similar to `$:/core/save/all` (which allows manipulating the entire document including headers etc) into a new window. Am I missing something here?

Can anyone suggest a method I could use? I would like to use a template tiddler which contains the entire document ( i.e. `<html><head>custom headers...</head><body>slide tiddlers rendered through another template...</body></html>`)

My current attempts have thus far only produced nested `<html>...<body><html>..</html></body></html>` type documents which do not display properly, for obvious reasons.

Since I was stumped using the existing `tm-open-window` message, I tried writing a new message `tm-open-raw-window` similar to the original, but without the surrounding document. However I was not able to find out how to parse a template-tiddler to html to dump it into the window. `$tw.wiki.renderTiddler("text/html",'templatename')` looked rather promising, but raised an exception for my template:

```
$:/core/modules/utils/utils.js:548 Uncaught TypeError: Cannot read property 'length' of undefined
    at Object.exports.parseTextReference
($:/core/modules/utils/utils.js:548:45)
    at exports.list ($:/core/modules/filters/list.js:21:18)
    at eval ($:/core/modules/filters.js:207:15)
    at Object.$tw.utils.each

...
```

Making a wild guess here, judging by the call stack, it might have something to do with the list widget in the template? Maybe missing the reference to the `currentTiddler` containing the `list` field?

Part of the template:
```
<$list filter="[list{!!title}]" emptyMessage="No slides added yet" template="$:/core/ui/ListItemTemplate"/>
```

So if anyone can tell me how to do this, this might also solve my problem. :)

Cheers.

Jeremy Ruston

unread,
Nov 28, 2016, 3:47:19 AM11/28/16
to tiddly...@googlegroups.com
Hi IsoLin

I am trying to integrate reveal.js [1] in a convenient way, such that I can use TiddlyWiki to edit and store the presentation slides, but then simply launch it straight from the wiki.

Terrific, that’s a great idea. I’m a huge fan of Reveal.js (and of Hakim’s other work; see http://hakim.se and things like http://lab.hakim.se/scroll-effects/).


Aditionally I am considering an export mode as well, for creating standalone versions.

Having the presentation dynamically update in a separate window is a very good approach.

While I still have various challenges to solve, I am currently stumped trying to open a new window with the reveal.js library loaded together with the slides. My idea was to use the existing `tm-open-window` message and a custom template. However I am having trouble finding out how I could take full control of the document being displayed in the new window.

As you’ve found, the template expected by tm-open-window is inserted within the body element of the window, and so can’t be used to specify the full markup of the window.

While reading through `$:/core/modules/startup/windows.js` I am getting the impression there is no way to actually just dump a template similar to `$:/core/save/all` (which allows manipulating the entire document including headers etc) into a new window. Am I missing something here?

No, your conclusions are correct.

It would be well worth fixing this. I’m not sure if it can be done in a backwards compatible way, and I’d concur with your idea of introducing a new `tm-open-raw-window` message. The existing message handler could be refactored so that the guts are more easily reusable.

Can anyone suggest a method I could use? I would like to use a template tiddler which contains the entire document ( i.e. `<html><head>custom headers...</head><body>slide tiddlers rendered through another template...</body></html>`)

My current attempts have thus far only produced nested `<html>...<body><html>..</html></body></html>` type documents which do not display properly, for obvious reasons.

Part of the problem is this line that writes the skeleton HTML content for the window:


As I recall it, I had problems getting things to work with Firefox when I omitted the document.write, or wrote a blank string.

Since I was stumped using the existing `tm-open-window` message, I tried writing a new message `tm-open-raw-window` similar to the original, but without the surrounding document. However I was not able to find out how to parse a template-tiddler to html to dump it into the window. `$tw.wiki.renderTiddler("text/html",'templatename')` looked rather promising, but raised an exception for my template:

The existing rendering code should do what you want:


This line needs changing to replace the entire document, not just insert the new element into the DOM:

widgetNode.render(srcDocument.body,srcDocument.body.firstChild)



```
$:/core/modules/utils/utils.js:548 Uncaught TypeError: Cannot read property 'length' of undefined
    at Object.exports.parseTextReference
($:/core/modules/utils/utils.js:548:45)
    at exports.list ($:/core/modules/filters/list.js:21:18)
    at eval ($:/core/modules/filters.js:207:15)
    at Object.$tw.utils.each

...
```

Making a wild guess here, judging by the call stack, it might have something to do with the list widget in the template? Maybe missing the reference to the `currentTiddler` containing the `list` field?

That could be the case. Perhaps pass “currentTiddler” as a parameter to the tm-open-window call.

One thing to note with TiddlyWiki templates is that the templates used to generate HTML output are used differently than usual: instead of treating the wikified output as HTML, we take the text content of the output, and then treat that as HTML. That’s why `$:/core/save/all` wraps the HTML elements in backticks, so that they are treated as plain text, and not parsed.

Best wishes

Jeremy




Part of the template:
```
<$list filter="[list{!!title}]" emptyMessage="No slides added yet" template="$:/core/ui/ListItemTemplate"/>
```

So if anyone can tell me how to do this, this might also solve my problem. :)

Cheers.


--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/f085efaf-7beb-4960-bcc6-b147dfba8a16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages