From a85e7e233df555ca8e68e8e53c734fd4b28889f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 27 Sep 2017 21:10:34 +0200 Subject: [PATCH] ImageLoader: when available, also save dimensions of image --- src/ImageLoader.js | 22 +++++++++------------- src/ImageLoader.php | 9 ++++++++- src/wikipedia.js | 6 +++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/ImageLoader.js b/src/ImageLoader.js index 4142021e..05f736bf 100644 --- a/src/ImageLoader.js +++ b/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)) diff --git a/src/ImageLoader.php b/src/ImageLoader.php index f96469ff..d6abcf7f 100644 --- a/src/ImageLoader.php +++ b/src/ImageLoader.php @@ -1,6 +1,7 @@ "_"))); @@ -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, ); } diff --git a/src/wikipedia.js b/src/wikipedia.js index 5fbaf9c9..9c42f37d 100644 --- a/src/wikipedia.js +++ b/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') + }) } }