TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.05k stars 1.19k forks source link

Lazy loading images not working correctly #2263

Open buggyj opened 8 years ago

buggyj commented 8 years ago

"Lazy Load" (--server 8080 $:/core/save/lazy-images) shows missing images (for an image stored in a tiddler) until the tiddler holding the images is loaded.

reported here: https://groups.google.com/forum/#!topic/tiddlywiki/X-iTuEV9fDc

buggyj commented 8 years ago

seems that the render function in the image widget needs an extra 'else' - else this.wiki.getTiddlerText(this.imageSource);

buggyj commented 8 years ago

like this:

    var tag = "img", src = "",
        tiddler = this.wiki.getTiddler(this.imageSource);
    if(!tiddler) {
        // The source isn't the title of a tiddler, so we'll assume it's a URL
        src = this.getVariable("tv-get-export-image-link",{params: [{name: "src",value: this.imageSource}],defaultValue: this.imageSource});
    } else {
        // Check if it is an image tiddler
        if(this.wiki.isImageTiddler(this.imageSource)) {
            var type = tiddler.fields.type,
                text = tiddler.fields.text,
                _canonical_uri = tiddler.fields._canonical_uri;
            // If the tiddler has body text then it doesn't need to be lazily loaded
            if(text) {
                // Render the appropriate element for the image type
                switch(type) {
                    case "application/pdf":
                        tag = "embed";
                        src = "data:application/pdf;base64," + text;
                        break;
                    case "image/svg+xml":
                        src = "data:image/svg+xml," + encodeURIComponent(text);
                        break;
                    default:
                        src = "data:" + type + ";base64," + text;
                        break;
                }
            } else if(_canonical_uri) {
                switch(type) {
                    case "application/pdf":
                        tag = "embed";
                        src = _canonical_uri;
                        break;
                    case "image/svg+xml":
                        src = _canonical_uri;
                        break;
                    default:
                        src = _canonical_uri;
                        break;
                }   
            } else this.wiki.getTiddlerText(this.imageSource);
        }
    }

showing extra else this.wiki.getTiddlerText(this.imageSource); at the bottom

buggyj commented 8 years ago

@Jermolene maybe you could add this?

Jermolene commented 8 years ago

Fixed in e3415796b238a0af9dbb4e63a8691e3d7e78142b

tgrosinger commented 7 years ago

This issue is still open, though it says it was fixed. I'm wondering if it is related to the issue I am having and detailed in this GoogleGroup post: https://groups.google.com/forum/#!topic/tiddlywiki/_W0gscNx5mk