-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.js
28 lines (24 loc) · 1.1 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {renderComic} from './lib/index.js'
const getConfig = (imageConfig) => {
const el = document.getElementById("comic-web")
const config = el ? el.dataset : {}
//The if no URL for resources is specified, use the image src
const urlDir = imageConfig.urlDir || config.urlDir || panel.src.split('/').slice(0, -1).join('/')
const fileType = imageConfig.fileType || config.fileType || panel.src.split('.').at(-1)
const width = imageConfig.width || config.width || 500
const height = imageConfig.height || config.height || 500
const textSize = imageConfig.textSize || config.textSize || 15
return {urlDir, fileType, width, height, textSize}
}
window.comicWebRender = (text) => renderComic(text, getConfig({}))
const panels =
Array.prototype.slice.call(document.getElementsByClassName("comic-web-panel"))
panels.forEach((panel) => {
if (panel.height < 100) { // When the image isn't loaded
panel.replaceWith(renderComic(panel.alt, getConfig(panel.dataset)))
} else {
panel.addEventListener('error', () => {
panel.replaceWith(renderComic(panel.alt, getConfig(panel.dataset)))
});
}
})