User:Simon04/Gadget-locator-tool.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// Locator-tool code begins, see [[Commons:Locator-tool]] for details.
// For MediaWiki.js docs, see https://doc.wikimedia.org/mediawiki-core/master/js/
(function(mw, $) {

  if (mw.config.get('wgAction') !== 'view') return;

  $(function() {
  	
  	var title = new mw.Title(mw.config.get('wgTitle'), mw.config.get('wgNamespaceNumber'));
  	var titleForUrl = encodeURIComponent(title.toString());
  	var url = '//tools.wmflabs.org/locator-tool/#/geolocate';
  	if (mw.config.get('wgNamespaceNumber') === 2) {
  		url += '?user=' + titleForUrl;
  	} else if (mw.config.get('wgNamespaceNumber') === 6) {
  		url += '?files=' + titleForUrl;
  	} else if (mw.config.get('wgNamespaceNumber') === 14) {
  		url += '?category=' + titleForUrl;
  	} else {
  		return;
  	}

    mw.util.addPortletLink(
      'p-tb',
      url,
      'Locator-tool',
      't-locator',
      'Geolocate this image'
    );

  });

})(mediaWiki, jQuery);