mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-08 19:09:13 +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:
@@ -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];
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user