mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 19:47:20 +00:00
Add [is[image]]
filter operator
This commit is contained in:
parent
e58d9c7008
commit
02ba92c6b5
17
boot/boot.js
17
boot/boot.js
@ -371,10 +371,11 @@ $tw.utils.checkVersions = function(versionStringA,versionStringB) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Register file type information
|
Register file type information
|
||||||
|
flags: "image" for image types
|
||||||
*/
|
*/
|
||||||
$tw.utils.registerFileType = function(type,encoding,extension) {
|
$tw.utils.registerFileType = function(type,encoding,extension,flags) {
|
||||||
$tw.config.fileExtensionInfo[extension] = {type: type};
|
$tw.config.fileExtensionInfo[extension] = {type: type};
|
||||||
$tw.config.contentTypeInfo[type] = {encoding: encoding, extension: extension};
|
$tw.config.contentTypeInfo[type] = {encoding: encoding, extension: extension, flags: flags || []};
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1459,12 +1460,12 @@ $tw.boot.startup = function(options) {
|
|||||||
$tw.utils.registerFileType("text/html","utf8",".html");
|
$tw.utils.registerFileType("text/html","utf8",".html");
|
||||||
$tw.utils.registerFileType("application/javascript","utf8",".js");
|
$tw.utils.registerFileType("application/javascript","utf8",".js");
|
||||||
$tw.utils.registerFileType("application/json","utf8",".json");
|
$tw.utils.registerFileType("application/json","utf8",".json");
|
||||||
$tw.utils.registerFileType("application/pdf","base64",".pdf");
|
$tw.utils.registerFileType("application/pdf","base64",".pdf",["image"]);
|
||||||
$tw.utils.registerFileType("image/jpeg","base64",".jpg");
|
$tw.utils.registerFileType("image/jpeg","base64",".jpg",["image"]);
|
||||||
$tw.utils.registerFileType("image/png","base64",".png");
|
$tw.utils.registerFileType("image/png","base64",".png",["image"]);
|
||||||
$tw.utils.registerFileType("image/gif","base64",".gif");
|
$tw.utils.registerFileType("image/gif","base64",".gif",["image"]);
|
||||||
$tw.utils.registerFileType("image/svg+xml","utf8",".svg");
|
$tw.utils.registerFileType("image/svg+xml","utf8",".svg",["image"]);
|
||||||
$tw.utils.registerFileType("image/x-icon","base64",".ico");
|
$tw.utils.registerFileType("image/x-icon","base64",".ico",["image"]);
|
||||||
$tw.utils.registerFileType("application/font-woff","base64",".woff");
|
$tw.utils.registerFileType("application/font-woff","base64",".woff");
|
||||||
// Create the wiki store for the app
|
// Create the wiki store for the app
|
||||||
$tw.wiki = new $tw.Wiki();
|
$tw.wiki = new $tw.Wiki();
|
||||||
|
43
core/modules/filters/is/image.js
Normal file
43
core/modules/filters/is/image.js
Normal file
@ -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);
|
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) {
|
exports.addTiddler = function(tiddler) {
|
||||||
// Check if we're passed a fields hashmap instead of a tiddler
|
// Check if we're passed a fields hashmap instead of a tiddler
|
||||||
if(!(tiddler instanceof $tw.Tiddler)) {
|
if(!(tiddler instanceof $tw.Tiddler)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user