Skip to content

Commit

Permalink
Adjust read-only behavior for TiddlyWiki classic
Browse files Browse the repository at this point in the history
This rolls back the behavior change from #328, but provides a way
to bring it back if you prefer it, by setting up a window.bidix
object in another tiddler tagged with "systemConfig".

As mentioned in the comments, the motivation for doing this is that
hiding the "upload to tiddlyhost" button causes usability problems
for TW classic users.
  • Loading branch information
simonbaird committed Jul 27, 2024
1 parent b8154df commit 26ed8fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 7 additions & 2 deletions rails/lib/th_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,13 @@ def apply_classic_mods(site_name, for_download:, is_logged_in:)
modifier: 'TiddlyHost',
},

# Used in the ThostUploadPlugin to ensure we don't render in readonly mode
# and to show the 'save to tiddlyhost' button
# The original idea for this was to read this value in the ThostUploadPlugin to decide
# whether to show the 'save to tiddlyhost' button, and perhaps to render in read-only
# mode. However the feedback from classic users is that having the save button unavailable
# is very disruptive, e.g. if you didn't notice that it was gone and added or modified some
# content, you're then unable to save the changes. So the default logic in ThostUploadPlugin
# was changed. This tiddler is still available so it is possible to restore that behavior if
# you prefer it that way.
'TiddlyHostIsLoggedIn' => {
text: status_is_logged_in(is_logged_in:, for_download:),
modifier: 'TiddlyHost',
Expand Down
24 changes: 22 additions & 2 deletions rails/tw_content/plugins/thost_upload_plugin.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ version.extensions.ThostUploadPlugin = { major: 1, minor: 0, revision: 1 };
//

if (!window.bidix) window.bidix = {};
bidix.debugMode = false;

// To change these defaults, create a tiddler named "ThostOptions" with tag
// "systemConfig" and the following content:
// window.bidix = { "editModeAlways": false, "uploadButtonAlways": false };

// Set false if you want the chkHttpReadOnly cookie to decide whether to
// render in read-only mode or edit mode when you're not logged in or when
// the site is being viewed by others. Default true.
if (!("editModeAlways" in bidix)) { bidix.editModeAlways = true; }

// Set false to hide the "upload to tiddlyhost" button when you're not logged
// in or when the site is being viewed by others. Default true.
if (!("uploadButtonAlways" in bidix)) { bidix.uploadButtonAlways = true; }

// For debugging. Default false.
if (!("debugMode" in bidix)) { bidix.debugMode = false; }

//
// Upload Macro
Expand Down Expand Up @@ -192,15 +207,20 @@ bidix.initOption('txtThostSiteName','<%= site_name %>');
// Tiddlyhost stuff
//

if (config.shadowTiddlers.TiddlyHostIsLoggedIn == "yes") {
bidix.ownerLoggedIn = (config.shadowTiddlers.TiddlyHostIsLoggedIn &&
config.shadowTiddlers.TiddlyHostIsLoggedIn == "yes")

if (bidix.editModeAlways || bidix.ownerLoggedIn) {
// If user is logged in to Tiddlyhost and viewing their own site then
// we disregard the original value of the chkHttpReadOnly cookie
config.options.chkHttpReadOnly = false
// window.readOnly gets set before plugins are loaded, so we need to
// set it here to make sure TW is editable, unlike window.showBackstage
// which is set after
window.readOnly = false
}

if (bidix.uploadButtonAlways || bidix.ownerLoggedIn) {
// Add the 'save to tiddlyhost' button after the regular save button
config.shadowTiddlers.SideBarOptions = config.shadowTiddlers.SideBarOptions
.replace(/(<<saveChanges>>)/,"$1<<thostUpload>>");
Expand Down

0 comments on commit 26ed8fa

Please sign in to comment.