mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 03:27:18 +00:00
Extend ImageWidget to generate the src based on the encoding format of the image entries (#7783)
* Make ImageWidget rendering image tiddler based on encoding of type * change indent * use deserializerType instead of type
This commit is contained in:
parent
4d548580e6
commit
c93d56667e
@ -58,24 +58,25 @@ ImageWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
if(this.wiki.isImageTiddler(this.imageSource)) {
|
if(this.wiki.isImageTiddler(this.imageSource)) {
|
||||||
var type = tiddler.fields.type,
|
var type = tiddler.fields.type,
|
||||||
text = tiddler.fields.text,
|
text = tiddler.fields.text,
|
||||||
_canonical_uri = tiddler.fields._canonical_uri;
|
_canonical_uri = tiddler.fields._canonical_uri,
|
||||||
|
typeInfo = $tw.config.contentTypeInfo[type] || {},
|
||||||
|
deserializerType = typeInfo.deserializerType || type;
|
||||||
// If the tiddler has body text then it doesn't need to be lazily loaded
|
// If the tiddler has body text then it doesn't need to be lazily loaded
|
||||||
if(text) {
|
if(text) {
|
||||||
// Render the appropriate element for the image type
|
// Render the appropriate element for the image type by looking up the encoding in the content type info
|
||||||
switch(type) {
|
var encoding = typeInfo.encoding || "utf8";
|
||||||
case "application/pdf":
|
if (encoding === "base64") {
|
||||||
|
// .pdf .png .jpg etc.
|
||||||
|
src = "data:" + deserializerType + ";base64," + text;
|
||||||
|
if (deserializerType === "application/pdf") {
|
||||||
tag = "embed";
|
tag = "embed";
|
||||||
src = "data:application/pdf;base64," + text;
|
}
|
||||||
break;
|
} else {
|
||||||
case "image/svg+xml":
|
// .svg .tid .xml etc.
|
||||||
src = "data:image/svg+xml," + encodeURIComponent(text);
|
src = "data:" + deserializerType + "," + encodeURIComponent(text);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
src = "data:" + type + ";base64," + text;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if(_canonical_uri) {
|
} else if(_canonical_uri) {
|
||||||
switch(type) {
|
switch(deserializerType) {
|
||||||
case "application/pdf":
|
case "application/pdf":
|
||||||
tag = "embed";
|
tag = "embed";
|
||||||
src = _canonical_uri;
|
src = _canonical_uri;
|
||||||
|
Loading…
Reference in New Issue
Block a user