MediaWiki:Gadget-GlobalUsageUI.js
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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/**
* GlobalUsage badges for Wikimedia Commons
* Displays a red label in the corners of
* gallery boxes
* This is an UI gadget. It's not a library.
*
* @rev 1 (2012-12-12)
* @author Rillke, 2012
*/
// List the global variables for jsHint-Validation. Please make sure that it passes http://jshint.com/
// Scheme: globalVariable:allowOverwriting[, globalVariable:allowOverwriting][, globalVariable:allowOverwriting]
/*global jQuery:false, mediaWiki:false*/
// Set jsHint-options. You should not set forin or undef to false if your script does not validate.
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, curly:false, browser:true*/
(function($, mw) {
"use strict";
var toQuery = {},
_onClick,
gus = [],
$gus;
var launch = function($c) {
$c.find('.gallery > li.gallerybox').each(function(i, el) {
var $el = $(el),
$th = $el.find('div.thumb').addClass('guThumb'),
$gu = $('<div>').attr({
'class': 'guGU',
title: "GlobalUsage"
}),
src = $th.find('img:first, video:first'),
t = src[0] && mw.Title.newFromImg(src);
if (!t) return;
if($gu.badge)$th.append($gu.badge('?', 'bottom'));
toQuery[t.toText()] = $gu;
gus = gus.concat($gu.get());
return $th.find('img:first');
});
$gus = $(gus);
_onClick = function() {
$gus.off('click', _onClick);
var gu = mw.libs.GlobalUsage(5, 20, 2, true);
gu.tipsyGravity = ($('body').hasClass('rtl') ? 'sw' : 'se');
gu.query(toQuery);
};
$gus.on('click', _onClick);
};
mw.hook( 'wikipage.content' ).add( launch );
}(jQuery, mediaWiki));