MediaWiki:Gadget-DeferredDisplay.js

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 01:47, 4 February 2023 by Vish (talk | contribs)
Jump to navigation Jump to search

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.
/**
 * Deferred display of {{tl|nsfw}}-tagged images.
 * jshint validation
 * @author Dschwen, 2013
 */

(function ($, mw) {
	var ti = mw.config.get("wgTitle");
	if ($.inArray(mw.config.get('wgNamespaceNumber'), [0, 1, 2, 3, 4, 5, 6, 10, 11, 14, 15]) === -1)
		return;
	// wrap non thumb images first
	$('img[alt*=NSFWTAG]').each(function (i, e) {
		$(e).wrap($('<div>').css({
				display: 'block',
				width: $(e).width() + 'px',
				height: $(e).height() + 'px',
				backgroundColor: '#eee'
			}));
	}).parent().add($('.thumbinner,.gallerybox').has('.nsfwelement').find('.image').parent())
	.one('click', function (e) {
		var nImg = $(this);
		$($(nImg).css('background', 'none').find('img')).unwrap();
		console.log(nImg);
		$(this).css('background', 'none').find('img').css({
			visibility: ''
		});
		e.preventDefault();
	})
	.css({
		backgroundImage: 'url("https://static.jojowiki.com/images/customizations/Dialog-warning-yellow.png")',
		backgroundRepeat: 'no-repeat',
		backgroundPosition: 'center'
	})
	.find('img').css({
		visibility: 'hidden'
	});
}(jQuery, mediaWiki));