How can a widget know whether it is inside a draft tiddler's preview?

52 views
Skip to first unread message

Felix Küppers

unread,
Jun 19, 2015, 5:14:31 PM6/19/15
to tiddly...@googlegroups.com
Hi @all

I want to prevent that a widget is displayed in preview when a tiddler is edited. Instead I want to display a placeholder.

Is there an easy way or predefined function that I can call from inside a widget to find out whether this widget is inside a draft?

Otherwise I would be forced to walk my way up the widget tree I guess. But at which level can I check whether I am inside a draft or not?

Many thanks!

-Felix

PMario

unread,
Jun 19, 2015, 6:56:52 PM6/19/15
to tiddly...@googlegroups.com
Hi Felix,

I think a widget doesn't know, if it is in preview mode, because preview mode is nothing special. It's a button with a reveal widget.

I did a short test:

<$edit tiddler="xx"> ... which produces the textarea

creates this DOM:

<div class="tc-tiddler-preview-preview">
  <p>
    <textarea style="height: 100px;">Type the text for the tiddler 'xx'</textarea>
  </p>
</div>


-m

So imo you need to walk up 2 parent nodes, and check for class tc-tiddler-preview-preview. The mechanism is a bit fragile, because it depends on the class, but imo it won't change any time soon.

-m

Felix Küppers

unread,
Jun 20, 2015, 4:23:19 AM6/20/15
to tiddly...@googlegroups.com
Servus Mario,

Walking up the dom-node tree and checking for a class is a nice idea. I initially wanted to extract the information from the widget tree but your idea is way easier.
If there is no better solution, I'll go with your suggestion! Thanks!

-Felix
--
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 http://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/a3b7dbd0-4d0b-4c67-b0f2-d0fc74965858%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeremy Ruston

unread,
Jun 20, 2015, 4:25:39 AM6/20/15
to TiddlyWikiDev
Hi Felix

I think we might as well add an explicit variable that marks the preview region. I'll push a commit shortly,

Best wishes

Jeremy



For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

PMario

unread,
Jun 20, 2015, 7:55:19 AM6/20/15
to tiddly...@googlegroups.com
On Saturday, June 20, 2015 at 10:23:19 AM UTC+2, Felix Küppers wrote:
Walking up the dom-node tree and checking for a class is a nice idea. I initially wanted to extract the information from the widget tree but your idea is way easier.
If there is no better solution, I'll go with your suggestion! Thanks!

I actually didn't suggest, to walk the browser DOM tree. I did suggest, that you only need to go up 2 parent nodes. IMO the widget gets a reference to the parent, and the nextSibling. So this should be every thing you need.
Since TW builds the DOM from the widget tree, I used the DOM to find some info, that we can use.

-m

Felix Küppers

unread,
Jun 20, 2015, 10:49:48 AM6/20/15
to tiddly...@googlegroups.com
Hi Mario,

> I actually didn't suggest, to walk the browser DOM tree. I did
> suggest, that you only need to go up 2 parent nodes. IMO the widget
> gets a reference to the parent, and the nextSibling. So this should be
> every thing you need.

Yap, we were really talking about the same thing, I mean once I get the
parent dom node I need to call the parentNode again to reach the place
where the class attribute is...

Reply all
Reply to author
Forward
0 new messages