diff --git a/boot/boot.js b/boot/boot.js index b83779dd5..7dbb23dda 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -371,10 +371,11 @@ $tw.utils.checkVersions = function(versionStringA,versionStringB) { /* 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.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("application/javascript","utf8",".js"); $tw.utils.registerFileType("application/json","utf8",".json"); - $tw.utils.registerFileType("application/pdf","base64",".pdf"); - $tw.utils.registerFileType("image/jpeg","base64",".jpg"); - $tw.utils.registerFileType("image/png","base64",".png"); - $tw.utils.registerFileType("image/gif","base64",".gif"); - $tw.utils.registerFileType("image/svg+xml","utf8",".svg"); - $tw.utils.registerFileType("image/x-icon","base64",".ico"); + $tw.utils.registerFileType("application/pdf","base64",".pdf",["image"]); + $tw.utils.registerFileType("image/jpeg","base64",".jpg",["image"]); + $tw.utils.registerFileType("image/png","base64",".png",["image"]); + $tw.utils.registerFileType("image/gif","base64",".gif",["image"]); + $tw.utils.registerFileType("image/svg+xml","utf8",".svg",["image"]); + $tw.utils.registerFileType("image/x-icon","base64",".ico",["image"]); $tw.utils.registerFileType("application/font-woff","base64",".woff"); // Create the wiki store for the app $tw.wiki = new $tw.Wiki(); diff --git a/core/modules/filters/is/image.js b/core/modules/filters/is/image.js new file mode 100644 index 000000000..777e88dda --- /dev/null +++ b/core/modules/filters/is/image.js @@ -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; +}; + +})(); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 83fd6679e..a133b2f47 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -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)) {