MediaWiki:Common.js: Difference between revisions

From Vision
No edit summary
(Added searchable tables)
 
(18 intermediate revisions by 2 users 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. */


    mwCustomEditButtons.push({
// Javascript/jQuery code for searching tables
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
function search_table(tableID, value){ 
        "speedTip": "Strike",
$('#'+tableID+' tr').each(function(){ 
        "tagOpen": "<s>",
var found = 'false'; 
        "tagClose": "</s>",
if (!$(this).hasClass('non-searchable')) {
        "sampleText": "Strike-through text"
$(this).each(function(){
    });
if ($(this).find('td.non-searchable').length > 0) {
  found = 'true'; 
    mwCustomEditButtons.push({
} else if (!$(this).find('th').length > 0) {
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
  if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0) 
        "speedTip": "Line break",
  { 
        "tagOpen": "<br />",
  found = 'true'; 
        "tagClose": "",
  }
        "sampleText": ""
} else {
    });
// Always keep the header row
found = 'true';
    mwCustomEditButtons.push({
}
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
});
        "speedTip": "Superscript",
if(found == 'true')  
        "tagOpen": "<sup>",
{
        "tagClose": "</sup>",
  $(this).show(); 
        "sampleText": "Superscript text"
    });
else 
    mwCustomEditButtons.push({
  $(this).hide(); 
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
        "speedTip": "Subscript",
}
        "tagOpen": "<sub>",
});
        "tagClose": "</sub>",
}  
        "sampleText": "Subscript text"
$(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) {
    mwCustomEditButtons.push({
$("table.apt-searchable").each(function(index, element) {
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
var tableID = this.id;
        "speedTip": "Small",
if (tableID == '') {
        "tagOpen": "<small>",
tableID = "aptSearchableTable_" + (index + 1);
        "tagClose": "</small>",
$(this).attr("id", tableID);
        "sampleText": "Small Text"
}
    });
$('<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+'\',\'\')" title="Clear Entry" class="apt-search-clear">').insertBefore($(this));
 
});
    mwCustomEditButtons.push({
});
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
        "speedTip": "Insert hidden Comment",
        "tagOpen": "<!-- ",
        "tagClose": " -->",
        "sampleText": "Comment"
    });
   
    mwCustomEditButtons.push({
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
        "speedTip": "Insert a picture gallery",
        "tagOpen": "\n<gallery>\n",
        "tagClose": "\n</gallery>",
        "sampleText": "Image:Example.jpg|Caption1\nImage:Example.jpg|Caption2"
    });
    mwCustomEditButtons.push({
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
        "speedTip": "Insert an Estimate template",
        "tagOpen": "{{EstimateCostDetails\n|REQ=Requirements Days\n|EST=Estimation Days\n|FS=Functional Specification Days\n|TS=Technical Specification Days\n|DEV=Development Days\n|ST=Testing and Release Days\n|IMP=Implementation Days\n}}",
        "tagClose": "",
        "sampleText": ""
    });
    mwCustomEditButtons.push({
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png",
        "speedTip": "Insert a table",
        "tagOpen": '{| class="wikitable"\n|',
        "tagClose": "\n|}",
        "sampleText": "-\n! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"
    });
    mwCustomEditButtons.push({
        "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png",
        "speedTip": "Insert a reference",
        "tagOpen": "<ref>",
        "tagClose": "</ref>",
        "sampleText": "Insert footnote text here"
    });

Latest revision as of 11:35, 21 August 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+'\',\'\')" title="Clear Entry" class="apt-search-clear">').insertBefore($(this));
	});
});