From a832338bb6857c3dd419434c983afde332b90a76 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 16 Oct 2012 19:12:09 +0100 Subject: [PATCH] Add a function to check whether a tiddler has a given field --- core/modules/macros/list.js | 2 +- core/modules/tiddler.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/modules/macros/list.js b/core/modules/macros/list.js index 6a562f593..ae423dccc 100644 --- a/core/modules/macros/list.js +++ b/core/modules/macros/list.js @@ -92,7 +92,7 @@ Create the tiddler macro needed to represent a given tiddler exports.createListElementMacro = function(title) { // Check if the tiddler is a draft var tiddler = this.wiki.getTiddler(title), - draft = tiddler ? $tw.utils.hop(tiddler.fields,"draft-of") : false; + draft = tiddler ? tiddler.hasField("draft-of") : false; // Figure out the template to use var template = this.params.template, templateText = this.params.templateText; diff --git a/core/modules/tiddler.js b/core/modules/tiddler.js index bfc48e1da..98d50c0c9 100644 --- a/core/modules/tiddler.js +++ b/core/modules/tiddler.js @@ -16,6 +16,10 @@ exports.hasTag = function(tag) { return this.fields.tags && this.fields.tags.indexOf(tag) !== -1; }; +exports.hasField = function(field) { + return $tw.utils.hop(this.fields,field); +}; + exports.getFieldString = function(field) { var value = this.fields[field]; // Check for a missing field