Browse Source

image/wikimedia: use reasonable image size

master
parent
commit
c452ae8125
  1. 26
      src/image.js

26
src/image.js

@ -9,7 +9,11 @@ function showImage (image, dom) {
dom.appendChild(div)
}
function showWikimediaImage (image, dom) {
function showWikimediaImage (image, options, dom) {
if (!options.size) {
options.size = 800
}
httpGet(
'https://commons.wikimedia.org/wiki/File:' + encodeURIComponent(image.id),
{
@ -22,7 +26,7 @@ function showWikimediaImage (image, dom) {
let m = result.body.match(/<a href="([^"]+\/)([0-9]+)(px-[^"\/]+)" class="mw-thumbnail-link"/)
if (m) {
let src = m[1] + '800' + m[3]
let src = m[1] + options.size + m[3]
var div = document.createElement('div')
div.innerHTML = '<a target="_blank" href="https://commons.wikimedia.org/wiki/File:' + encodeURIComponent(image.id) + '"><img src="' + src + '"/></a>'
@ -39,7 +43,7 @@ function show (img, options, div) {
switch (img.type) {
case 'wikimedia':
showWikimediaImage(img, div)
showWikimediaImage(img, options, div)
break
case 'url':
showImage(img, div)
@ -53,6 +57,7 @@ register_hook('show-details', function (data, category, dom, callback) {
div.className = 'images loading'
var imageWrapper
var nextImageWrapper = document.createElement('div')
let options
dom.appendChild(div)
@ -87,9 +92,13 @@ register_hook('show-details', function (data, category, dom, callback) {
imageWrapper.className = 'imageWrapper'
div.appendChild(imageWrapper)
options = {
size: Math.max(imageWrapper.offsetWidth, imageWrapper.offsetHeight)
}
showTimer = window.setInterval(showNext, 5000)
show(img, {}, imageWrapper)
show(img, options, imageWrapper)
loadNext()
})
@ -102,7 +111,7 @@ register_hook('show-details', function (data, category, dom, callback) {
return console.log("Can't load next image", err)
}
show(img, {}, nextImageWrapper)
show(img, options, nextImageWrapper)
})
}
@ -151,7 +160,12 @@ register_hook('show-popup', function (data, category, dom, callback) {
imageWrapper.className = 'imageWrapper'
div.appendChild(imageWrapper)
show(img, {}, imageWrapper)
let options = {
size: 150
}
console.log(options)
show(img, options, imageWrapper)
callback(null)
})

Loading…
Cancel
Save