Jump to content

User:V111P/js/smartLinkingLoader.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by V111P (talk | contribs) at 11:41, 21 October 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* smartLinkingLoader.js
 * v. 2013-10
 *
 * This script adds a toolbar button which, when pressed, loads smartLinking.js and calls window.smartLinking().
 *
 * Smart Linking home: http://en.wikipedia.org/wiki/User:V111P/js/smartLinking
 */

(function () {
	"use strict";

	if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) == -1 )
		return;

	var buttonId = 'smartLinkingButton';
	var buttonIconUrl = '/media/wikipedia/commons/9/96/Interpage_icon.png';
	var buttonIconUrlClassic = '/media/wikipedia/commons/5/5a/Interpage_button.png';
	var addToolbarButtons_scriptUrl = '//en.wikipedia.org/w/index.php?title='
		+ 'User:V111P/js/addToolbarButtons.js&action=raw'
		+ '&ctype=text/javascript&smaxage=600&maxage=86400';
	var c = window.smartLinkingConfig = window.smartLinkingConfig || {};

	// after loading, the script replaces this button with its button
	var tempButtonClicked = function () {
		if (window.smartLinking) {
			smartLinking(); // shouldn't happen
		}
		else {
			$.ajax({
				url: '//en.wikipedia.org/w/index.php?title=User:V111P/js/smartLinking.js'
						+ '&action=raw&ctype=text/javascript&smaxage=600&maxage=86400',
				dataType: 'script',
				cache: true,
				success: function () {
					if (window.smartLinking)
						window.smartLinking();
					else
						setTimeout(function () {
							if (window.smartLinking)
								window.smartLinking();
						}, 500);
				}
			});
		}
	};

	var toolbarButtonProps = {
		id: 'smartLinkingButton',
		tooltip: (c.msgs && c.msgs.scriptName) || 'Smart Linking',
		section: 'main',
		group: 'insert',
		callback: tempButtonClicked,
		iconUrl: c.buttonIconUrl || buttonIconUrl,
		iconUrlClassic: c.buttonIconUrlClassic || c.buttonIconUrl || buttonIconUrlClassic
	};

	if (c.addButton !== false) {
		// load the script that adds the toolbar button
		if (window.addToolbarButtons)
			window.addToolbarButtons(toolbarButtonProps);
		else {
			var tbs = window.toolbarButtonsToAdd = window.toolbarButtonsToAdd || [];
			tbs.push(toolbarButtonProps);
			$.ajax({
				url: addToolbarButtons_scriptUrl,
				dataType: 'script',
				cache: true
			});
		}
	}

	if (window.smartLinking) {
		smartLinking.init();
		return;
	};

})();
window.smartLinkingLoader = 1000;