1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-18 15:54:50 +00:00

Add a datauri widget

Used in stylesheets to get a data URI for a font or bitmap
This commit is contained in:
Jeremy Ruston 2013-05-17 17:30:03 +01:00
parent 6e1cd46bc7
commit f3bcc1c0af

View File

@ -0,0 +1,48 @@
/*\
title: $:/core/modules/widgets/datauri.js
type: application/javascript
module-type: widget
The datauri widget displays the contents of a tiddler as a data URI.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var DataUriWidget = function(renderer) {
// Save state
this.renderer = renderer;
// Generate child nodes
this.generate();
};
DataUriWidget.prototype.generate = function() {
// Get parameters from our attributes
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle);
// Compose the data URI
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle),
uri = "";
if(tiddler) {
var type = tiddler.fields.type || "text/vnd.tiddlywiki",
typeInfo = $tw.config.contentTypeInfo[type],
isBase64 = typeInfo && typeInfo.encoding === "base64";
uri = "data:" + type + (isBase64 ? ";base64" : "") + "," + tiddler.fields.text;
}
// Set the element
this.tag = "pre";
this.attributes = {
"class": "tw-data-uri"
};
// Create the renderers for the wrapper and the children
this.children = this.renderer.renderTree.createRenderers(this.renderer,[{
type: "text",
text: uri
}]);
};
exports.datauri = DataUriWidget;
})();