Skip to content

Commit

Permalink
refactor(thumbnail): Moving webp checker outside of packaging
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Jul 28, 2022
1 parent f45b462 commit e277ae8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
20 changes: 0 additions & 20 deletions cmd/fibr/static/scripts/thumbnail.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
// from https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp
async function isWebPCompatible() {
const animatedImage =
'UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA';

return new Promise((resolve, reject) => {
var image = new Image();
image.onload = () => {
if (image.width > 0 && image.height > 0) {
resolve();
} else {
reject();
}
};

image.onerror = reject;
image.src = `data:image/webp;base64,${animatedImage}`;
});
}

// From https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader/read#example_2_-_handling_text_line_by_line
async function* readLineByLine(response) {
const utf8Decoder = new TextDecoder('utf-8');
Expand Down
2 changes: 1 addition & 1 deletion cmd/fibr/static/scripts/thumbnail/web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/fibr/static/scripts/thumbnail/web.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions cmd/fibr/templates/async-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@
picture.alt = 'Image file';
}

// from https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp
function isWebPCompatible() {
const animatedImage =
'UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA';

return new Promise((resolve, reject) => {
var image = new Image();
image.onload = () => {
if (image.width > 0 && image.height > 0) {
resolve();
} else {
reject();
}
};

image.onerror = reject.bind(null, true);
image.src = `data:image/webp;base64,${animatedImage}`;
});
}

resolveScript('/scripts/modern_detection.js?v={{ .Version }}')
.then(() => {
if (window.modernBrowser) {
Expand Down

0 comments on commit e277ae8

Please sign in to comment.