We use cookies to ensure you get the best experience on our website. By using the IFPA wiki, you consent to our use of cookies.

MediaWiki:Common.js

From IFPA wiki

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
// install [[User:Cacycle/wikEd]] in-browser text editor
//document.write('<script type="text/javascript" src="'
//+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');
/*** Place in MediaWiki:Common.js ****/
function makeRequest(url) {
var httpRequest;				

if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!httpRequest) {
alert("Giving up :( Cannot create an XMLHTTP instance");
return false;
}
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
httpRequest.open("GET", url, true);
httpRequest.send(null);
}

function alertContents(httpRequest) {

if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
document.getElementById("p-calendar").innerHTML = httpRequest.responseText;
} else {
document.getElementById("p-calendar").innerHTML = "<p>There was a problem with the request.</p>";
}
}
}

/* IFPA Wiki customisation */
/* Additional WikiEditor buttons */



var customizeToolbar = function () {
	/* Your code goes here */
	
	/* Strikethrough button */
	$('#wpTextbox1').wikiEditor('addToToolbar', {
		section: 'advanced',
		group: 'format',
		tools: {
			"strikethrough": {
				label: 'Strike',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/1/1a/Toolbaricon_strike.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<s>",
						post: "</s>"
					}
				}
			}
		}
	});


$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	section: 'advanced',
	groups: {
		list: {
			tools: {
				templates: {
					label: 'Common Snippets',
					type: 'select',
					list: {
						"math": {
							label: '<math>Math</math>',
							action: {
								type: 'encapsulate',
								options: {
									pre: "<math>",
									post: "</math>"
								}
							}
						},
						"dmat": {
							label: 'Centred Math Expression',
							action: {
								type: 'encapsulate',
								options: {
									pre: '\\[',
									post: '\\]'
								}
							}
						},
						"neq" : {
							label: 'Numbered Equation',
							action: {
								type: 'encapsulate',
								options: {
									pre: '{{NumberedEqn | <math>',
									post: ' </math>}}'
								}
							}
						},
						"code": {
							label: 'Code block',
							action: {
								type: 'encapsulate',
								options: {
									pre:  '<syntaxhighlight lang="text" line>',
									post: '</syntaxhighlight>'
								}
							}
						},
						"incode": {
							label: 'Inline Code',
							action: {
								type: 'encapsulate',
								options: {
									pre:  '<syntaxhighlight lang="text" inline>',
									post: '</syntaxhighlight>'
								}
							}
						},
						"nameref" : {
							label: '<ref name="name" />',
							action: {
								type: 'encapsulate',
								options: {
									pre: '<ref name="',
									peri: 'name',
									post: '"/>'
								}
							}
						},
						"refs": {
							label: 'References',
							action: {
								type: 'encapsulate',
								options: {
									pre: '<references>',
									post: '</references>'
								}
							}
						},
						"bibit" : {
							label: 'Bibitem',
							action: {
								type: 'encapsulate',
								options: {
									pre: '<bibitem>',
									post: '</bibitem>'
								}
							}
						}
					}
				}
			}
		}
	}
} );

/* End of function */   
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
			).then( customizeToolbar );
		}
	} );
}

/**
 * @source mediawiki.org/wiki/Snippets/Open_specific_external_links_in_new_window
 * @version 3
 */
$(function( $ )  {
	$( '#mw-content-text' ).on( 'click', '.newwin > a', function( e ) {
		var otherWindow = window.open();
		otherWindow.opener = null;
		otherWindow.location = this;
		return false;
	} );
} );

About

Contact

IFPA Wiki maintained by Atri B.

ULgLogo.png     STAR Institute logo.svg