Browse Source

ImageLoader: when available, also save dimensions of image

master
parent
commit
a85e7e233d
  1. 22
      src/ImageLoader.js
  2. 9
      src/ImageLoader.php
  3. 6
      src/wikipedia.js

22
src/ImageLoader.js

@ -112,14 +112,12 @@ ImageLoader.prototype.loadWikimediaCommons = function (src, callback) {
}
ajax('ImageLoaderWikimediaCategoryList', param, function (result) {
if (result.images) {
result.images.forEach(function (d) {
if (this.found.indexOf(d) === -1) {
this.found.push(d)
this.data[d] = {
id: d,
type: 'wikimedia'
}
if (result.imageData) {
result.imageData.forEach(function (d) {
if (this.found.indexOf(d.id) === -1) {
this.found.push(d.id)
d.type = 'wikimedia'
this.data[id] = d
}
}.bind(this))
}
@ -160,11 +158,9 @@ ImageLoader.prototype.loadWikipedia = function (src, callback) {
result.forEach(function (d) {
if (this.found.indexOf(d) === -1) {
this.found.push(d)
this.data[d] = {
id: d,
type: 'wikimedia'
}
this.found.push(d.id)
d.type = 'wikimedia'
this.data[d.id] = d
}
}.bind(this))

9
src/ImageLoader.php

@ -1,6 +1,7 @@
<?php
function ajax_ImageLoaderWikimediaCategoryList ($param) {
$ret = array();
$retData = array();
$wm_url = "https://commons.wikimedia.org/w/index.php?title=" . urlencode(strtr($param['page'], array(" " => "_")));
@ -22,6 +23,11 @@ function ajax_ImageLoaderWikimediaCategoryList ($param) {
for ($j = 0; $j < $imgs->length; $j++) {
$ret[] = $imgs->item($j)->getAttribute('alt');
$retData[] = array(
'id' => $imgs->item($j)->getAttribute('alt'),
'width' => $imgs->item($j)->getAttribute('data-file-width'),
'height' => $imgs->item($j)->getAttribute('data-file-height'),
);
}
}
}
@ -37,7 +43,8 @@ function ajax_ImageLoaderWikimediaCategoryList ($param) {
}
return array(
'images' => $ret,
'images' => $ret, // deprecated as of 2017-09-27
'imageData' => $retData,
'continue' => $continue,
);
}

6
src/wikipedia.js

@ -310,7 +310,11 @@ function getImages (tagValue, callback) {
var m = img.src.match(/^https?:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/\w+\/\w+\/([^\/]+)/)
if (m) {
var file = decodeURIComponent(m[1]).replace(/_/g, ' ')
ret.push(file)
ret.push({
id: file,
width: img.getAttribute('data-file-width'),
height: img.getAttribute('data-file-height')
})
}
}

Loading…
Cancel
Save