From a505b6ffc07d19c1bdcb79e0c30e31dfce7f2433 Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Sun, 27 Apr 2014 16:31:00 -0400 Subject: [PATCH] Move isModified from Tiddler to Wiki Replace this with a $tw.wiki.isModifiedTiddler(title) as part of the wiki object. This allows it to be used outside of the current Wiki which can change. --- boot/boot.js | 32 +++++++++++++++---------------- core/modules/widgets/navigator.js | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 25101f55e..c54fa53d6 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -795,22 +795,6 @@ $tw.Tiddler.prototype.isDraft = function() { return this.hasField("draft.of"); }; -$tw.Tiddler.prototype.isModified = function() { - if(!this.isDraft()) { - return false; - } - var ignoredFields = ["created", "modified", "title", "draft.title", "draft.of", "tags"], - tiddler = this, - origTiddler = $tw.wiki.getTiddler(this.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 and install the built in tiddler field modules */ @@ -1140,6 +1124,22 @@ $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 */ diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 0f75cb7e9..40aaae9cf 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -315,7 +315,7 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) { {title: draftTitle} } )); - } else if(!tiddler.isModified()) { + } else if(!this.wiki.isModifiedTiddler(title)) { event.type = "tw-cancel-tiddler"; this.dispatchEvent(event); } else if(isConfirmed) {