MediaWiki:LinkThumb.js

/* linkThumb *  shows a brief thumbnail of files when you hover over File: links *  ver 0.1 *  by mfaizsyahmi, 2015 */ var linkThumb = { // the container element $container: $(' ').css({		position:"fixed",		bottom:"30px",		left:"10px",		"z-index":999999}	).appendTo('body'), // the variable that holds the timeout ID	timeoutvar: null, // set image width here imgwidth: 200, // sets event for File: links main: function { $('#mw-content-text').find(':link[href$=".jpg"], :link[href$=".jpeg"], :link[href$=".gif"], :link[href$=".png"]') .on('mouseenter.linkThumb', function(e) { 			clearTimeout(linkThumb.timeoutvar);			linkThumb.timeoutvar = setTimeout( linkThumb.get( $(this).attr('href'), 500));		}).on('mouseleave.linkThumb', function(e) {			clearTimeout(linkThumb.timeoutvar);			linkThumb.$container.empty;		}); },	// queries the API for thumbnail url get: function(href) { var title = href.replace(/^\/wiki\//,''); $.get('/api.php', {			action:'query',			titles: title,			prop: 'imageinfo',			iiprop: 'url',			iiurlwidth: linkThumb.imgwidth,			format:'json'		}).done(function(d) {			// when done, retrieve url and display			for(var wat in d.query.pages) { // should be only one				var url = d.query.pages[wat].imageinfo["0"].thumburl;				linkThumb.$container.empty;				var $img = $(' ').attr('src',url).css('border','2px solid').appendTo(linkThumb.$container);				linkThumb.$container.show.delay(3000).fadeOut(2000);			}		}); } } linkThumb.main;