Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4123332
ImageGateway.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ImageGateway.js
View Options
const
sizeBuckets
=
[
320
,
640
,
800
,
1024
,
1280
,
1920
,
2560
,
2880
],
actionParams
=
require
(
'./../mobile.startup/actionParams'
),
util
=
require
(
'./../mobile.startup/util'
);
/**
* Gets the first size larger than or equal to the provided size
*
* @memberof ImageGateway
* @param {number} size
* @return {number}
*/
function
findSizeBucket
(
size
)
{
let
i
=
0
;
while
(
size
>
sizeBuckets
[
i
]
&&
i
<
sizeBuckets
.
length
-
1
)
{
++
i
;
}
return
sizeBuckets
[
i
];
}
/**
* API for retrieving image thumbnails for a given page
*
* @param {Object} options Configuration options
* @param {mw.Api} options.api
* @private
*/
function
ImageGateway
(
options
)
{
this
.
_cache
=
{};
this
.
api
=
options
.
api
;
}
/**
* Get thumbnail via the API and cache it. Return the result from the cache if exists.
*
* @param {string} title Url of image
* @return {jQuery.Deferred} with the image info
*/
ImageGateway
.
prototype
.
getThumb
=
function
(
title
)
{
const
cachedThumb
=
this
.
_cache
[
title
],
$window
=
util
.
getWindow
(),
imageSizeMultiplier
=
(
window
.
devicePixelRatio
&&
window
.
devicePixelRatio
>
1
)
?
window
.
devicePixelRatio
:
1
;
if
(
!
cachedThumb
)
{
this
.
_cache
[
title
]
=
this
.
api
.
get
(
actionParams
(
{
prop
:
'imageinfo'
,
titles
:
title
,
iiprop
:
[
'url'
,
'extmetadata'
],
// request an image devicePixelRatio times bigger than the reported screen size
// for retina displays and zooming
iiurlwidth
:
findSizeBucket
(
$window
.
width
()
*
imageSizeMultiplier
),
iiurlheight
:
findSizeBucket
(
$window
.
height
()
*
imageSizeMultiplier
)
}
)
).
then
(
function
(
resp
)
{
// imageinfo is undefined for missing pages.
if
(
resp
.
query
&&
resp
.
query
.
pages
&&
resp
.
query
.
pages
[
0
]
&&
resp
.
query
.
pages
[
0
].
imageinfo
)
{
return
resp
.
query
.
pages
[
0
].
imageinfo
[
0
];
}
throw
new
Error
(
'The API failed to return any pages matching the titles.'
);
}
);
}
return
this
.
_cache
[
title
];
};
ImageGateway
.
_findSizeBucket
=
findSizeBucket
;
module
.
exports
=
ImageGateway
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 06:05 (2 d, 19 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
75/d1/a027280a66b7e9bf598531f454c4
Default Alt Text
ImageGateway.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment