Jump to content

MediaWiki:Gadget-gallery.js

From OpenStreetMap Foundation

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Fisher–Yates shuffle
function shuffled(items) {
	const result = [...items];
	for (let i = items.length; i > 0; i--) {
		const j = Math.floor(Math.random() * (i + 1));
		[result[i], result[j]] = [result[j], result[i]];
	}
	return result;
}

$(function() {
	// Shuffle the items in each randomized gallery.
	$(".osm-gallery-random .gallery").each((i, gallery) => {
		const boxes = shuffled($(gallery).children(".gallerybox"));
		$(gallery)
			.remove(".gallerybox")
			.append(boxes);
	});
	// The hero gallery is limited to a single row of unknown height, because the gallery’s heights attribute is merely a suggestion. When hovering over the gallery, force it to show the full first line so that the captions (and any attribution) show up, at the expense of some jumping.
	$("#osm-hero").on("mouseenter", function () {
		$(this).height($(this).find(".gallerybox").height());
	});
});