MediaWiki

Common.js: Difference between revisions

(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: window.os_max_lines_per_suggest = 5;")
 
No edit summary
 
(115 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
window.os_max_lines_per_suggest = 5;
 
/* Ping when tick that a "To do" has been done */
$( ".ping" ).on( "click", function() {
  const audio = new Audio("/media/Ping.mp3");
  audio.play();
});
 
/* Hide some CategoryTree text */
$(document).ready(function() {
  $("span:contains('(empty)')").hide();
});
 
/* TreeAndMenu: Opening a tree to the current page */
$(document).ready( function() {
    $('#tree,#historical,#miscellaneous,#elsewhere').bind('fancytreeinit', function(event, data) {
        data.tree.makeTitleVisible();
    });
});
 
 
 
/* Can't remember */
$("#resourcesquery table").addClass("responsive");
 
/* Haven't a clue */
function citationDownload(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);
  element.style.display = 'none';
  document.body.appendChild(element);
  element.click();
  document.body.removeChild(element);
}
 
/* Page Forms: so can't edit coordinates field directly (have to use map) */
$( function() {
  $('.pfCoordsInput').prop('readonly', true);
  // $('.pfUpdateMap').hide();
} );
 
 
/* WikiEditor toolbar customisation: see https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization */
 
var customizeToolbar = function () {
/* New group */
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
$textarea.wikiEditor( 'addToToolbar', {
section: 'advanced',
groups: {
extra: {
label: 'Extra'
}
}
} );
} );
 
/* <Blockquote> button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"blockquote": {
label: 'Blockquote',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Toolbar_blockquote.png',
action: {
type: 'encapsulate',
options: {
pre: "<blockquote>",
post: "</blockquote>"
}
}
}
}
} );
 
$( '#free_text' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"blockquote": {
label: 'Blockquote',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Toolbar_blockquote.png',
action: {
type: 'encapsulate',
options: {
pre: "<blockquote>",
post: "</blockquote>"
}
}
}
}
} );
 
 
 
/* "Category:" button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"category": {
label: 'Category',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/2/28/Toolbaricon_category.png',
action: {
type: 'encapsulate',
options: {
pre: "[[Category:",
post: "]]"
}
}
}
}
} );
 
/* "#bailii:" button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"bailii": {
label: 'Bailii',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/P_writing_icon.svg',
action: {
type: 'encapsulate',
options: {
pre: "{{#bailii:",
post: "}}"
}
}
}
}
} );
 
/* "Category:Judgment available offline" button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"offline": {
label: 'Judgment available offline',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/0/0c/Toolbar_no_wiki.png',
action: {
type: 'replace',
options: {
pre: "[[Category:",
post: "Judgment available offline]]"
}
}
}
}
} );
 
/* "Category:Judgment available on MHLO" button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"online": {
label: 'Judgment available on MHLO',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/3/33/Toolbar_welcome.png',
action: {
type: 'replace',
options: {
pre: "[[Category:",
post: "Judgment available on MHLO]]"
}
}
}
}
} );
 
/* em dash */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"online": {
label: 'em dash',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/Button_hr.png',
action: {
type: 'encapsulate',
options: {
pre: "—",
}
}
}
}
} );
 
/* en dash */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'extra',
tools: {
"online": {
label: 'en dash',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/4/41/Button_hr_halfwidth.png',
action: {
type: 'encapsulate',
options: {
pre: "–",
}
}
}
}
} );
};
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -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' ), $.ready
).then( customizeToolbar );
}
} );
}

Latest revision as of 20:21, 26 June 2025

/* Any JavaScript here will be loaded for all users on every page load. */

/* Ping when tick that a "To do" has been done */
$( ".ping" ).on( "click", function() {
  const audio = new Audio("/media/Ping.mp3");
  audio.play();
});

/* Hide some CategoryTree text */
$(document).ready(function() {
  $("span:contains('(empty)')").hide();
});

/* TreeAndMenu: Opening a tree to the current page */
$(document).ready( function() {
    $('#tree,#historical,#miscellaneous,#elsewhere').bind('fancytreeinit', function(event, data) {
        data.tree.makeTitleVisible();
    });
});



/* Can't remember */
$("#resourcesquery table").addClass("responsive");

/* Haven't a clue */
function citationDownload(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);
  element.style.display = 'none';
  document.body.appendChild(element);
  element.click();
  document.body.removeChild(element);
}

/* Page Forms: so can't edit coordinates field directly (have to use map) */
$( function() {
  $('.pfCoordsInput').prop('readonly', true);
  // $('.pfUpdateMap').hide();
} );


/* WikiEditor toolbar customisation: see https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization */

var customizeToolbar = function () {
	
	/* New group */
	mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'advanced',
			groups: {
				extra: {
					label: 'Extra' 
				}
			}
		} );	
	} );

	
	
	
	/* <Blockquote> button */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"blockquote": {
				label: 'Blockquote',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Toolbar_blockquote.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<blockquote>",
						post: "</blockquote>"
					}
				}
			}
		}
	} );

	$( '#free_text' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"blockquote": {
				label: 'Blockquote',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Toolbar_blockquote.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<blockquote>",
						post: "</blockquote>"
					}
				}
			}
		}
	} );



	/* "Category:" button */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"category": {
				label: 'Category',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/2/28/Toolbaricon_category.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "[[Category:",
						post: "]]"
					}
				}
			}
		}
	} );

	/* "#bailii:" button */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"bailii": {
				label: 'Bailii',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/P_writing_icon.svg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{#bailii:",
						post: "}}"
					}
				}
			}
		}
	} );

	/* "Category:Judgment available offline" button */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"offline": {
				label: 'Judgment available offline',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/0/0c/Toolbar_no_wiki.png',
				action: {
					type: 'replace',
					options: {
						pre: "[[Category:",
						post: "Judgment available offline]]"
					}
				}
			}
		}
	} );

	/* "Category:Judgment available on MHLO" button */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"online": {
				label: 'Judgment available on MHLO',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/3/33/Toolbar_welcome.png',
				action: {
					type: 'replace',
					options: {
						pre: "[[Category:",
						post: "Judgment available on MHLO]]"
					}
				}
			}
		}
	} );

	/* em dash */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"online": {
				label: 'em dash',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/Button_hr.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "—",
					}
				}
			}
		}
	} );

	/* en dash */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'extra',
		tools: {
			"online": {
				label: 'en dash',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/4/41/Button_hr_halfwidth.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "–",
					}
				}
			}
		}
	} );
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -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' ), $.ready
			).then( customizeToolbar );
		}
	} );
}