MediaWiki:Gadget-ezcopy.js

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 02:02, 13 October 2024 (Created page with "$(function () { function try_copy(x, $el) { var txt = document.createElement('textarea'), $txt = $(txt); $txt.text(x).css({ position: 'fixed', top: 0, left: 0, width: '2em', heigh: '2em', padding: 0, border: 'none', outline: 'none', boxShadow: 'none', background: 'transparent' }).appendTo('body'); txt.select(); try { document.execCommand('copy'); //mw.notify('Copied "'+x+'" to the clipboard', {tag: 'ezcopy'}); $el.addClas..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

After saving, you may need to bypass your browser's cache to see the changes. For further information, see Wikipedia:Bypass your cache.

  • In most Windows and Linux browsers: Hold down Ctrl and press F5.
  • In Safari: Hold down ⇧ Shift and click the Reload button.
  • In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
$(function () {
	function try_copy(x, $el) {
		var txt = document.createElement('textarea'), $txt = $(txt);
		$txt.text(x).css({
			position: 'fixed',
			top: 0,
			left: 0,
			width: '2em',
			heigh: '2em',
			padding: 0,
			border: 'none',
			outline: 'none',
			boxShadow: 'none',
			background: 'transparent'
		}).appendTo('body');
		txt.select();
		try {
			document.execCommand('copy');
			//mw.notify('Copied "'+x+'" to the clipboard', {tag: 'ezcopy'});
			$el.addClass('rsw-ezcopy-copied');
			setTimeout(function(){$el.removeClass('rsw-ezcopy-copied')}, 2500)
		} catch (err) {}
		$txt.remove();
	}
	function init() {
		var $copy_fullpagename, $copy_pagename, $copy_displaytitle, $container,
			FULLPAGENAME, PAGENAME, DISPLAYTITLE;
		PAGENAME = mw.config.get('wgTitle');
		$container = $('<span>').addClass('rsw-ezcopy-container');
		$copy_pagename = $('<span>')
			.addClass('rsw-ezcopy-button rsw-ezcopy-pagename')
			.append('<span class="rsw-ezcopy-icon">','<span class="rsw-ezcopy-label">Page\nname</span>')
			.attr('title', 'Copy "'+PAGENAME+'"');
		
		$copy_pagename.click(function(){try_copy(PAGENAME, $copy_pagename);});
		$container.append($copy_pagename);
		FULLPAGENAME = PAGENAME;
		if (mw.config.get('wgCanonicalNamespace') !== '') {
			var ns = mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceNumber')];
			if (ns !== undefined) {
				FULLPAGENAME = ns+':'+PAGENAME;
				$copy_fullpagename = $('<span>')
					.addClass('rsw-ezcopy-button rsw-ezcopy-fullpagename')
					.append('<span class="rsw-ezcopy-icon">','<span class="rsw-ezcopy-label">Full</span>')
					.attr('title', 'Copy "'+FULLPAGENAME+'"');
				$copy_fullpagename.click(function(){try_copy(FULLPAGENAME, $copy_fullpagename);});
				$container.append($copy_fullpagename);
			}
		}
		if (mw.config.get('wgAction') === 'view' && mw.config.get('wgDiffOldId') === null) { // wgDiffOldId is either an ID or false if in a diff, null if not a diff
			DISPLAYTITLE = $('#firstHeading').text();
			if (FULLPAGENAME !== DISPLAYTITLE) {
				$copy_displaytitle = $('<span>')
					.addClass('rsw-ezcopy-button rsw-ezcopy-displaytitle')
					.append('<span class="rsw-ezcopy-icon">','<span class="rsw-ezcopy-label">Display\ntitle</span>')
					.attr('title', 'Copy "'+DISPLAYTITLE+'"');
				$copy_displaytitle.click(function(){try_copy(DISPLAYTITLE, $copy_displaytitle)});
				$container.append($copy_displaytitle);
			}
		}
		$('#firstHeading').append($container);
	}
	init()
})