mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 09:50:27 +00:00
Minor tweaks to shadow warning infrastructure
1. Moved some methods out of boot.js because they are not needed until after bootup 2. Added alternate message for editing an overridden shadow tiddler 3. Minor style tweaks
This commit is contained in:
parent
a90339d1e5
commit
84cd296c58
32
boot/boot.js
32
boot/boot.js
@ -85,18 +85,6 @@ $tw.utils.each = function(object,callback) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an array is equal by value and by reference.
|
||||
*/
|
||||
$tw.utils.isArrayEqual = function(array1,array2) {
|
||||
if(array1 === array2) { return true; }
|
||||
array1 = array1 || []; array2 = array2 || [];
|
||||
if(array1.length !== array2.length) { return false; }
|
||||
return array1.every(function(value,index) {
|
||||
return value === array2[index];
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Helper for making DOM elements
|
||||
tag: tag name
|
||||
@ -791,10 +779,6 @@ $tw.Tiddler.prototype.hasField = function(field) {
|
||||
return $tw.utils.hop(this.fields,field);
|
||||
};
|
||||
|
||||
$tw.Tiddler.prototype.isDraft = function() {
|
||||
return this.hasField("draft.of");
|
||||
};
|
||||
|
||||
/*
|
||||
Register and install the built in tiddler field modules
|
||||
*/
|
||||
@ -1124,22 +1108,6 @@ $tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
|
||||
}
|
||||
};
|
||||
|
||||
$tw.Wiki.prototype.isModifiedTiddler = function(title) {
|
||||
var tiddler = this.getTiddler(title);
|
||||
if(!tiddler.isDraft()) {
|
||||
return false;
|
||||
}
|
||||
var ignoredFields = ["created", "modified", "title", "draft.title", "draft.of", "tags"],
|
||||
origTiddler = this.getTiddler(tiddler.fields["draft.of"]);
|
||||
if(!$tw.utils.isArrayEqual(tiddler.fields.tags,origTiddler.fields.tags)) {
|
||||
return true;
|
||||
}
|
||||
return !Object.keys(tiddler.fields).every(function(field) {
|
||||
if(ignoredFields.indexOf(field) >= 0) { return true; }
|
||||
return tiddler.fields[field] === origTiddler.fields[field];
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Register the built in tiddler deserializer modules
|
||||
*/
|
||||
|
@ -4,11 +4,12 @@ Body/Hint: Use [[wiki text|http://tiddlywiki.com/static/WikiText.html]] to add f
|
||||
Body/Placeholder: Type the text for this tiddler
|
||||
Body/Preview/Button/Hide: hide preview
|
||||
Body/Preview/Button/Show: show preview
|
||||
Body/ShadowWarning: You are editing a shadow tiddler. Any changes will override the default version.
|
||||
Fields/Add/Button: add
|
||||
Fields/Add/Name/Placeholder: field name
|
||||
Fields/Add/Prompt: Add a new field:
|
||||
Fields/Add/Value/Placeholder: field value
|
||||
Shadow/Warning: This is a shadow tiddler. Any changes will override the default version
|
||||
Shadow/OverriddenWarning: This is a modified shadow tiddler. You can revert to the default version by deleting this tiddler
|
||||
Tags/Add/Button: add
|
||||
Tags/Add/Placeholder: tag name
|
||||
Type/Placeholder: content type
|
||||
|
@ -6,7 +6,7 @@ CloseAll/Button: close all
|
||||
ConfirmCancelTiddler: Do you wish to discard changes to the tiddler "<$text text=<<title>>/>"?
|
||||
ConfirmDeleteTiddler: Do you wish to delete the tiddler "<$text text=<<title>>/>"?
|
||||
ConfirmOverwriteTiddler: Do you wish to overwrite the tiddler "<$text text=<<title>>/>"?
|
||||
ConfirmEditShadowTiddler: Your about to edit a ShaddowTiddler. This will override the default system making upgrading non-trivial. Are you sure you want to edit "<$text text=<<title>>/>"?
|
||||
ConfirmEditShadowTiddler: You are about to edit a ShadowTiddler. Any changes will override the default system making future upgrades non-trivial. Are you sure you want to edit "<$text text=<<title>>/>"?
|
||||
InvalidFieldName: Illegal characters in field name "<$text text=<<fieldName>>/>". Fields can only contain lowercase letters and the characters underscore (`_`), hyphen (`-`) and period (`.`)
|
||||
MissingTiddler/Hint: Missing tiddler "<$text text=<<currentTiddler>>/>" - click {{$:/core/images/edit-button}} to create
|
||||
RecentChanges/DateFormat: DDth MMM YYYY
|
||||
|
@ -20,6 +20,10 @@ exports.isPlugin = function() {
|
||||
return this.fields.type === "application/json" && this.hasField("plugin-type");
|
||||
}
|
||||
|
||||
exports.isDraft = function() {
|
||||
return this.hasField("draft.of");
|
||||
};
|
||||
|
||||
exports.getFieldString = function(field) {
|
||||
var value = this.fields[field];
|
||||
// Check for a missing field
|
||||
|
@ -33,6 +33,23 @@ exports.count = function(object) {
|
||||
return s;
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an array is equal by value and by reference.
|
||||
*/
|
||||
exports.isArrayEqual = function(array1,array2) {
|
||||
if(array1 === array2) {
|
||||
return true;
|
||||
}
|
||||
array1 = array1 || [];
|
||||
array2 = array2 || [];
|
||||
if(array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
return array1.every(function(value,index) {
|
||||
return value === array2[index];
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Push entries onto an array, removing them first if they already exist in the array
|
||||
array: array to modify (assumed to be free of duplicates)
|
||||
@ -481,6 +498,6 @@ exports.timer = function(base) {
|
||||
m = m - base;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -315,7 +315,7 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
|
||||
{title: draftTitle}
|
||||
}
|
||||
));
|
||||
} else if(!this.wiki.isModifiedTiddler(title)) {
|
||||
} else if(!this.wiki.isDraftModified(title)) {
|
||||
event.type = "tw-cancel-tiddler";
|
||||
this.dispatchEvent(event);
|
||||
} else if(isConfirmed) {
|
||||
|
@ -1060,4 +1060,25 @@ exports.readFile = function(file,callback) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Check whether the specified draft tiddler has been modified
|
||||
*/
|
||||
$tw.Wiki.prototype.isDraftModified = function(title) {
|
||||
var tiddler = this.getTiddler(title);
|
||||
if(!tiddler.isDraft()) {
|
||||
return false;
|
||||
}
|
||||
var ignoredFields = ["created", "modified", "title", "draft.title", "draft.of", "tags"],
|
||||
origTiddler = this.getTiddler(tiddler.fields["draft.of"]);
|
||||
if(!$tw.utils.isArrayEqual(tiddler.fields.tags,origTiddler.fields.tags)) {
|
||||
return true;
|
||||
}
|
||||
return !Object.keys(tiddler.fields).every(function(field) {
|
||||
if(ignoredFields.indexOf(field) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return tiddler.fields[field] === origTiddler.fields[field];
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
|
19
core/ui/EditTemplate/shadow.tid
Normal file
19
core/ui/EditTemplate/shadow.tid
Normal file
@ -0,0 +1,19 @@
|
||||
title: $:/core/ui/EditTemplate/shadow
|
||||
tags: $:/tags/EditTemplate
|
||||
|
||||
\define lingo-base() $:/language/EditTemplate/Shadow/
|
||||
<$list filter="[all[current]get[draft.of]is[shadow]!is[tiddler]]">
|
||||
<div class="tw-message-box">
|
||||
|
||||
<<lingo Warning>>
|
||||
|
||||
</div>
|
||||
</$list>
|
||||
|
||||
<$list filter="[all[current]get[draft.of]is[shadow]is[tiddler]]">
|
||||
<div class="tw-message-box">
|
||||
|
||||
<<lingo OverriddenWarning>>
|
||||
|
||||
</div>
|
||||
</$list>
|
@ -1,11 +0,0 @@
|
||||
title: $:/core/ui/EditTemplate/shadowWarning
|
||||
tags: $:/tags/EditTemplate
|
||||
|
||||
\define lingo-base() $:/language/EditTemplate/
|
||||
<$list filter="[all[current]get[draft.of]is[shadow]]">
|
||||
<div class="tw-message-box">
|
||||
|
||||
<<lingo Body/ShadowWarning>>
|
||||
|
||||
</div>
|
||||
</$list>
|
@ -1,2 +1,2 @@
|
||||
title: $:/tags/EditTemplate
|
||||
list: [[$:/core/ui/EditTemplate/controls]] [[$:/core/ui/EditTemplate/title]] [[$:/core/ui/EditTemplate/tags]] [[$:/core/ui/EditTemplate/shadowWarning]] [[$:/core/ui/ViewTemplate/classic]] [[$:/core/ui/EditTemplate/body]] [[$:/core/ui/EditTemplate/type]] [[$:/core/ui/EditTemplate/fields]]
|
||||
list: [[$:/core/ui/EditTemplate/controls]] [[$:/core/ui/EditTemplate/title]] [[$:/core/ui/EditTemplate/tags]] [[$:/core/ui/EditTemplate/shadow]] [[$:/core/ui/ViewTemplate/classic]] [[$:/core/ui/EditTemplate/body]] [[$:/core/ui/EditTemplate/type]] [[$:/core/ui/EditTemplate/fields]]
|
||||
|
Loading…
Reference in New Issue
Block a user