More actions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 354: | Line 354: | ||
}); | }); | ||
}); | }); | ||
}); | |||
mw.loader.using(['jquery', 'mediawiki.api'], function () { | |||
$(function () { | |||
$('.main-banner[data-files]').each(function () { | |||
var $box = $(this); | |||
var list = String($box.attr('data-files')) | |||
.split(/\s*\|\s*|\s*,\s*/) | |||
.filter(Boolean); | |||
if (!list.length) return; | |||
var pick = list[Math.floor(Math.random() * list.length)]; | |||
// Use MediaWiki API to resolve actual file path | |||
new mw.Api().get({ | |||
action: 'query', | |||
titles: 'File:' + pick, | |||
prop: 'imageinfo', | |||
iiprop: 'url', | |||
format: 'json' | |||
}).done(function (data) { | |||
var pages = data.query.pages; | |||
for (var pageId in pages) { | |||
if (pages.hasOwnProperty(pageId) && pages[pageId].imageinfo) { | |||
var url = pages[pageId].imageinfo[0].url; | |||
var $img = $('<img>', { | |||
src: url, | |||
width: 2450, | |||
height: 450, | |||
alt: '' | |||
}); | |||
$box.empty().append($img); | |||
} | |||
} | |||
}); | |||
}); | |||
}); | |||
}); | }); | ||