Determine if a Wiki has unsaved changes from wikitext

I’m sure this is a simple question, but I can’t find the state of “is the wiki dirty” anywhere. I’ve searched for “dirty” and “save” across system and shadow tiddlers.

I found @TW_Tones’ “Reset Dirty save status” (Prevent "Prevent leave" / "You have unsaved changes" - #5 by TW_Tones), which uses JS to read $tw.saverHandler.numChanges.

Is there any way to read the “unsaved” state from wikitext?

This should provide the equivalent information:

[subfilter{$:/config/SaverFilter}haschanged[]]

1 Like

I think I may be missing something. This always shows DIRTY, even if the TW has no unsaved changes:

<% if [subfilter{$:/config/SaverFilter}haschanged[]] %>
DIRTY
<% endif %>

Am I misusing this expression? My use-case is to append “DIRTY” to the subtitle of the wiki for scripting purposes.

Correct, that filter will always return a result if a tiddler has changed since the wiki started. If you want to track the actual dirty status - that it resets when the wiki is saved - I do not think we have a wikitext affordance for it.

if it helps, a dirty wiki has the class tc-dirty applied to the body of the document.

They dirty indicator is set via css as i understand it and is set by any action that makes it dirty as defined by they save filter as @saqimtiaz said.

  • it is then only unset if you use a function like I shared before.
    • css may be available to test this independant of tiddlywiki
    • we could bring reset dirty into tiddlywiki so you can reset it from tiddlywiki script.
  • in the absence of the dirty indicator using the save filter to test if changes is equivalent
    • unless that filter has changed
  • even using the local storage plugin that saves changes in the browser the dirty indicator is not reset.
  • depending on the use case such as read only wikis
    • you can edit the save filter to stop throwing the dirty status
    • you can hide the save button.

@saqimtiaz @TW_Tones So, if I have an element, in my case I want to display a message in a specific tiddler, that only appears when the wiki is dirty, for example:

<div class="dirtymessage">
To be safe, save changes before generating timelines. Do not risk losing your work.
.</div>

I could use CSS to control if this message is displayed?

.dirtymessage { display: none }
body.tc-dirty .dirtymessage {display: block !important}

This seems to work for me. Is there a better way?

Thank you,

Craig

That looks good, though I would drop the !important.

Thanks for the explanation, @TW_Tones and @saqimtiaz.

Is there a JS plugin way for me to tell the dirty state of the wiki? I’d like to change the title of the wiki to say “DIRTY” if it’s dirty.

See Craig’s use of css above.

Why do you want a JS way when css and wiki text methods are available? Use css in the title field to respond as desired.