2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/tiddler.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: tiddlermethod
|
|
|
|
|
2013-04-30 21:37:02 +00:00
|
|
|
Extension methods for the $tw.Tiddler object (constructor and methods required at boot time are in boot/boot.js)
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.hasTag = function(tag) {
|
|
|
|
return this.fields.tags && this.fields.tags.indexOf(tag) !== -1;
|
|
|
|
};
|
|
|
|
|
2013-04-30 21:37:02 +00:00
|
|
|
exports.isPlugin = function() {
|
2013-08-23 17:37:54 +00:00
|
|
|
return this.fields.type === "application/json" && this.hasField("plugin-type");
|
2014-06-23 07:09:59 +00:00
|
|
|
};
|
2013-04-29 11:05:58 +00:00
|
|
|
|
2014-04-28 14:16:31 +00:00
|
|
|
exports.isDraft = function() {
|
|
|
|
return this.hasField("draft.of");
|
|
|
|
};
|
|
|
|
|
2018-08-15 12:50:07 +00:00
|
|
|
/*
|
|
|
|
Get the value of a field as a list
|
|
|
|
*/
|
|
|
|
exports.getFieldList = function(field) {
|
|
|
|
var value = this.fields[field];
|
|
|
|
// Check for a missing field
|
|
|
|
if(value === undefined || value === null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return $tw.utils.parseStringArray(value);
|
|
|
|
};
|
|
|
|
|
2012-11-11 14:12:10 +00:00
|
|
|
/*
|
|
|
|
Get all the fields as a name:value block. Options:
|
|
|
|
exclude: an array of field names to exclude
|
|
|
|
*/
|
|
|
|
exports.getFieldStringBlock = function(options) {
|
|
|
|
options = options || {};
|
2019-04-14 13:23:49 +00:00
|
|
|
var exclude = options.exclude || [],
|
|
|
|
fields = Object.keys(this.fields).sort(),
|
|
|
|
result = [];
|
|
|
|
for(var t=0; t<fields.length; t++) {
|
|
|
|
var field = fields[t];
|
|
|
|
if(exclude.indexOf(field) === -1) {
|
|
|
|
result.push(field + ": " + this.getFieldString(field));
|
2012-11-11 14:12:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-14 13:23:49 +00:00
|
|
|
return result.join("\n");
|
2012-11-11 14:12:10 +00:00
|
|
|
};
|
|
|
|
|
2017-02-21 08:31:05 +00:00
|
|
|
exports.getFieldDay = function(field) {
|
|
|
|
if(this.cache && this.cache.day && $tw.utils.hop(this.cache.day,field) ) {
|
|
|
|
return this.cache.day[field];
|
|
|
|
}
|
|
|
|
var day = "";
|
|
|
|
if(this.fields[field]) {
|
|
|
|
day = (new Date($tw.utils.parseDate(this.fields[field]))).setHours(0,0,0,0);
|
|
|
|
}
|
|
|
|
this.cache.day = this.cache.day || {};
|
|
|
|
this.cache.day[field] = day;
|
|
|
|
return day;
|
|
|
|
};
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
})();
|