From 88782ef9d26c101760ea1d75901e72e849d940ea Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Fri, 18 Mar 2016 15:35:21 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20remnant=20from=20the=20plan=C3=A8te?= =?UTF-8?q?=20sankor=C3=A9=20search;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also added a function to get slightly larger images (though the Pixabay API doesn't give width and hight info about these, so it's not currently used) --- .../library/search/Pixabay.wgs/index.html | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/resources/library/search/Pixabay.wgs/index.html b/resources/library/search/Pixabay.wgs/index.html index ca5e6c12..4d2c821f 100644 --- a/resources/library/search/Pixabay.wgs/index.html +++ b/resources/library/search/Pixabay.wgs/index.html @@ -30,12 +30,14 @@ var minWidth = 150; // Image type to retrieve. Can be "photo", "illustration", "vector" or "all". - var imageType = "all" + var imageType = "all"; // Language code to search in - var searchLanguage = "en" + var searchLanguage = "en"; - + // Fetch 960px images instead of the default 640px. However the API doesn't + // provide size information in this case, so it is disabled by default. + var fetchMediumResImages = false; // --------------------- @@ -46,8 +48,9 @@ $(document).ready(loadPage) + /* Initialize the page layout */ function loadPage() { - //variables + var mode = false; //search or view mode var hide = false; //hide or no main panel @@ -136,8 +139,8 @@ newImg.src = result.previewURL; - var imgWidth = (result.tbWidth > minWidth)?result.tbWidth:minWidth; - var imgHeight = (result.tbHeight > minHeight)?result.tbHeight:minHeight; + var imgWidth = (result.previewWidth > minWidth)?result.previewWidth:minWidth; + var imgHeight = (result.previewHeight > minHeight)?result.previewHeight:minHeight; imgContainer.width(imgWidth).height(imgHeight); imgContainer.append($(newImg)); @@ -149,12 +152,17 @@ var iThumbnailUrl = $(""); var iTitle = $(""); - iUrl.attr("value", result.webformatURL); + var imageURL = result.webformatURL; + if (fetchMediumResImages) + imageURL = getMediumResURL(result); + + iUrl.attr("value", imageURL); iContent.attr("value", result.type); iHeight.attr("value", result.webformatHeight); iWidth.attr("value", result.webformatWidth); iThumbnailUrl.attr("value", result.previewURL); iTitle.attr("value", getImageTitle(result)); + imgContainer.append(iUrl); imgContainer.append(iContent); @@ -258,6 +266,16 @@ return firstTag; } + function getMediumResURL(image) { + // Pixabay automatically returns a 640px "webformat" picture; we can't request a larger one + // in the search request, but we can manually fetch one (up to 960px) + + var url = image.webformatURL; + + medResURL = url.replace("_640.", "_960."); + + return medResURL; + }