From 3a78465d2d3150f2cafff18ab8ff8772b9dbdf22 Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Fri, 25 Apr 2014 08:45:17 -0400 Subject: [PATCH] Add isModified to Tiddler object Adds a check to see if this tiddler differers from the tiddler referenced in the draft.of field. It iterates of the fields property skiping those feilds that offer a false positives. Uses the isEqual util for the tags array. --- boot/boot.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/boot/boot.js b/boot/boot.js index 74d736cce..67d1a5582 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -795,6 +795,20 @@ $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.isEqual(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 */