מדיה ויקי:Gadget-CiteTooltip.js

if ( mw.config.get( 'wgAction' ) === 'view' 
	&& mw.user.options.get('gadget-popup') != '1' // note: do not use !==, as we can't trust the precise type of the option
	&& mw.user.options.get('popupsreferencepreviews') != '1'
	&& mw.user.options.get( 'popups-reference-previews' ) != '1'
	)	//note: this gadget depends on jquery.tipsy. it's consumed here, instead of gadget definition, 
		//in case one of the conditions above is false, to avoid unnecessary load of the library
mw.loader.using(['jquery.tipsy'], function() { 
	var
		createHint = function() {
			var selector = '[id="' + decodeURIComponent( mw.util.escapeRegExp(this.href.replace(/.*#/, '') ) ).replace(/"/g, '\\"') + '"]',
				elem = $(selector),
				html = elem.html(),
				ltr = elem.css('direction') == 'ltr',
				divClass = ltr ? 'class="mw-content-ltr"' : '',
				divCss = 'style="word-wrap:break-word;' + (ltr ? 'text-align:left;' : '') + '"';
			console.log(selector);
			return html ? '<div ' + divClass + divCss + '>' + html + '</div>' : '';
		},
		gravity = function() {
			var loc =
				($(this).offset().top > ($(document).scrollTop() + $(window).height() - 120) ? 's' : 'n') +
				($(this).offset().left > ($(document).scrollLeft() + $(window).width() / 4) ? '' : 'w');
			return loc;
		},
		tipsyParams = {html: true, delayOut: 1500, delayIn: 300, fade: true, opacity: 1, gravity: gravity, title: createHint};

	$(function() {$('sup.reference a').tipsy(tipsyParams);});
});