מדיה ויקי:Gadget-showIntroOnHover.js/archive

// gadget depends on user, api and tipsy.
"use strict"
if (mw.config.get('wgAction') == 'view' && ! mw.user.options.get('gadget-popup') && mw.user.options.get('popups') != "1") 
$(function() {
	var
		gravity = function() {
			return (
				($(this).offset().top > ($(document).scrollTop() + $(window).height() * 0.5) ? 's' : 'n') +
				($(this).offset().left > ($(document).scrollLeft() + $(window).width() / 4) ? '' : 'w')
			);
		},
		api = new mw.Api(),
		mouseLeft = function() { $(this).data('mouseLeft', true); },
		createHint = function() {
			var $this = $(this),
				title = $this.data('saveTitle'),
				tipsy = false,
				toRead = window.hoverIntroSize || 420;
				
			if ($this.data('beenHere')) // we only need to set tipsy once per link.
				return;
				
			$this.data('beenHere', true) ;
				
			api.get({prop: 'extracts', exchars: toRead, redirects: 1, exintro: 1, exsectionformat: 'plain', titles: title}) 
				.done(function(data) {
					var content;
					if (data && data.query && data.query.pages)
						for (var p in data.query.pages) 
							content = data.query.pages[p].extract;
					if (content && $.trim($(content).text())) {
						$this.tipsy({
							html: true, 
							delayOut: 500, 
							delayIn: 666, 
							fade: true, 
							opacity: 1, 
						        gravity: gravity,
							className: 'hover-intro',
							title: function() { return content; }
						});
						tipsy = true;
					}
				})
				.always(function() {
					if (! tipsy) 
						$this.attr('title', $this.data('saveTitle'));
					if (! $this.data('mouseLeft')) 
						$this.trigger('mouseenter').trigger('mouseover');
				});
		};
		
	$('a[href^="/wiki/"]:not([class]), a.mw-redirect, a.stub, a.mw-changeslist-title', mw.util.$content).each(function(i, item) {
		item = $(item);
		item.data('saveTitle', item.attr('title')) // prevent initial hint
			.removeAttr('title')
			.hover(createHint, mouseLeft);
	});
});