MediaWiki:Common.js: Difference between revisions
From CTMS
(Added autofocus back to search when clearing table searches) |
m (1 revision imported) |
||
(One intermediate revision by one other user not shown) | |||
Line 42: | Line 42: | ||
}); | }); | ||
}); | }); | ||
// Check if we're editing a page. | |||
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) { | |||
// Add a hook handler. | |||
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) { | |||
// Configure a new toolbar entry on the given $textarea jQuery object. | |||
$textarea.wikiEditor( 'addToToolbar', { | |||
/* Your code goes here */ | |||
section: 'advanced', | |||
group: 'format', | |||
tools: { | |||
"code": { | |||
label: 'Code', | |||
type: 'button', | |||
oouiIcon: 'code', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: "<code>", | |||
post: "</code>" | |||
} | |||
} | |||
} | |||
} | |||
} ); | |||
} ); | |||
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) { | |||
// Configure a new toolbar entry on the given $textarea jQuery object. | |||
$textarea.wikiEditor( 'addToToolbar', { | |||
/* Your code goes here */ | |||
section: 'advanced', | |||
group: 'format', | |||
tools: { | |||
"noinclude": { | |||
label: 'Noinclude', | |||
type: 'button', | |||
oouiIcon: 'markup', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: "<noinclude>", | |||
post: "</noinclude>" | |||
} | |||
} | |||
} | |||
} | |||
} ); | |||
} ); | |||
} |
Latest revision as of 15:58, 6 September 2024
/* Any JavaScript here will be loaded for all users on every page load. */
// Javascript/jQuery code for searching tables
function search_table(tableID, value){
$('#'+tableID+' tr').each(function(){
var found = 'false';
if (!$(this).hasClass('non-searchable')) {
$(this).each(function(){
if ($(this).find('td.non-searchable').length > 0) {
found = 'true';
} else if (!$(this).find('th').length > 0) {
if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
{
found = 'true';
}
} else {
// Always keep the header row
found = 'true';
}
});
if(found == 'true')
{
$(this).show();
}
else
{
$(this).hide();
}
}
});
}
$(document).ready(function(){
// Alternative method - makes all tables with 10 or more rows (including header) searchable automatically
// $("table > tbody > tr:nth-child(10)").closest("table").each(function(index, element) {
$("table.apt-searchable").each(function(index, element) {
var tableID = this.id;
if (tableID == '') {
tableID = "aptSearchableTable_" + (index + 1);
$(this).attr("id", tableID);
}
$('<input type="text" id="'+tableID+'_'+index+'" onkeyup="search_table(\''+tableID+'\',$(this).val())" placeholder="Search the table..."><input type="button" onclick="$(\'#'+tableID+'_'+index+'\').val(\'\');search_table(\''+tableID+'\',\'\');$(\'#'+tableID+'_'+index+'\').focus();" title="Clear Entry" class="apt-search-clear">').insertBefore($(this));
});
});
// Check if we're editing a page.
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
/* Your code goes here */
section: 'advanced',
group: 'format',
tools: {
"code": {
label: 'Code',
type: 'button',
oouiIcon: 'code',
action: {
type: 'encapsulate',
options: {
pre: "<code>",
post: "</code>"
}
}
}
}
} );
} );
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
/* Your code goes here */
section: 'advanced',
group: 'format',
tools: {
"noinclude": {
label: 'Noinclude',
type: 'button',
oouiIcon: 'markup',
action: {
type: 'encapsulate',
options: {
pre: "<noinclude>",
post: "</noinclude>"
}
}
}
}
} );
} );
}