mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-10-04 23:21:42 +00:00
Add [is[image]] filter operator
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/is/image.js
|
||||
type: application/javascript
|
||||
module-type: isfilteroperator
|
||||
|
||||
Filter function for [is[image]]
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.image = function(source,prefix,options) {
|
||||
var results = [];
|
||||
// Function to check a tiddler
|
||||
function checkTiddler(title) {
|
||||
var match = options.wiki.isImageTiddler(title);
|
||||
if(prefix === "!") {
|
||||
match = !match;
|
||||
}
|
||||
if(match) {
|
||||
results.push(title);
|
||||
}
|
||||
};
|
||||
// Iterate through the source tiddlers
|
||||
if($tw.utils.isArray(source)) {
|
||||
$tw.utils.each(source,function(title) {
|
||||
checkTiddler(title);
|
||||
});
|
||||
} else {
|
||||
$tw.utils.each(source,function(element,title) {
|
||||
checkTiddler(title);
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -196,6 +196,16 @@ exports.isShadowTiddler = function(title) {
|
||||
return $tw.utils.hop(this.shadowTiddlers,title);
|
||||
};
|
||||
|
||||
exports.isImageTiddler = function(title) {
|
||||
var tiddler = this.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type || "text/vnd.tiddlywiki"];
|
||||
return !!contentTypeInfo && contentTypeInfo.flags.indexOf("image") !== -1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.addTiddler = function(tiddler) {
|
||||
// Check if we're passed a fields hashmap instead of a tiddler
|
||||
if(!(tiddler instanceof $tw.Tiddler)) {
|
||||
|
||||
Reference in New Issue
Block a user