குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.

  • மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
  • கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
  • இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
  • ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
/**
* Title:Template Helper for Wikipedia. 
* Description:This tool helps to enter values for the template parameters in the dynamically created form. The form then will be wikified back to wiki template with the values for the parameters. You can also preview your work before copying to wiki articles.
* @author Mohamed Mahir ([[user:Mahir78]])
* @date 2010-12-08
* Version: 1.0.1
* License: GPLv3, CC-BY-SA 3.0
*/ 
//$j UI can be removed if it is already imported.

//mw.loader.load("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js");

//TODO:If the rightside value contains pipe symbol then will get wrong output eg Governors=[[TamilNadu Governors|Surjeeth singh]]

//Make sure this will not make any conflict for other javascript.
//$j=jQuery.noConflict();//TODO:remove this in production

var TemplateHelper={}
TemplateHelper.Data=[];
//var UserTemplates=[];


importScript("User:Mdmahir/template helper/titles.js");//Can be changed to mediawiki

BASIC_TEMPLATE="default"; //A must subpage in all the above listed templates in TemplateHelper.Titles, It will have the template structure.

//Instruct user to use the variable UserTemplates=["MyTemplate","MyTemplate2"];//Your template default structure should be in MyTemplate/default etc...

function LoadTemplateData(title){
	url='http://'+ TemplateHelper.lang +'.wikipedia.org/w/api.php';
	
	$.post(url, { "format": "json","action":"parse","text":"{{"+title+"/"+BASIC_TEMPLATE+"}}" },
		function(data){
			var parsed_data=data.parse.text['*'];		
			TemplateHelper.Data.push(parsed_data);
		}, "json"
	);	
}

var incount=0;
function CreateForm(obj){
	words=$('#template_in').val();
	word=words.split("|");
	incount=word.length;
	$('#controls').html('');
	$('#controls').append("Template:");
	lword=word[0].split("=");

	$('#controls').append("<input type='text' id='temptitle' style='width:300px' value='"+lword[0].replace("\{\{",'').trim()+"' /><br/>");

	for(i=1;i<word.length-1;i++){
		lword=word[i].split("=");
		$('#controls').append("<input type='text' id='a"+i+"' value='"+lword[0].trim()+"' /> = ");
		$('#controls').append("<input type='text' id='b"+i+"' style='width:200px' value='"+(lword.length==2?lword[1].trim():'')+"' /><br />");
		
	}
	//obj.disabled=true;
}


function genTemplate(){
	$('#temp_preview').show();
	templ="{{"+$('#temptitle').val();

	for(i=1;i<incount-1;i++){
		if($('#a'+i).val()!='undefined')
		templ +="\n|"+$('#a'+i).val() +"\t\t= "+$('#b'+i).val();
	}
	templ +="\n}}";
	$('#template_out').val(templ);

}

function createIn(){
	$('#controls').append("<input type='text' id='a"+(incount-1)+"' /> = ");
	$('#controls').append("<input type='text' id='b"+(incount-1)+"' style='width:200px' /><br />");
	incount++;
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function copyInfo(obj){
	//if it have backslash(\) remove it before pushing.			
	data=TemplateHelper.Data[$('#templates_select :selected').val()].replace("\\","");
	data=data.replace("<p>","").replace("<\/p>","").replace("<pre>","").replace("<\/pre>","");
	$('#template_in').val(data);
	CreateForm();
}
function customcheck(){
	if($('#customc').is(':checked'))
		$('#customform').show();
	else
		$('#customform').hide();
}

function tempPreview(){
	TempOut=$('#template_out').val();
	if(TempOut!=''){
		//path="?format=json&action=parse&text="+TempOut;
		$('#previewbox').show();
		url='http://'+ TemplateHelper.lang +'.wikipedia.org/w/api.php';
		
		$.post(url, { "format": "json","action":"parse","text":TempOut },
		   function(data){
			var parseddata=data.parse.text['*'];
			$("#previewbox").html(parseddata);                            
		   }, "json"
		);
	}//tempPreview
}

function openTemplateHelper(){
	$dialog.dialog('open');
}

$htm="<br />Step 1: Select a Template(or <input id='customc' type='checkbox' value='1' onclick='customcheck()' /> Custom Template):";
$htm +="<select id='templates_select' onchange='copyInfo(this)'></select><br /><div style='display:none' id='customform'>";
$htm +="<textarea rows='5' id='template_in' name='template_in' cols='60' size='50'></textarea>";
$htm +="<input type='button' id='createform'  value='Create form' onclick='CreateForm(this)' />";
$htm +="<input type='reset' value='reset' onclick=\"CreateForm(this)\" /></div>";
$htm +="<div id='controls'></div>";
$htm +="<input type='button' value='Step 2(Optional):If any parameter is missing click this button to add parameter' onclick='createIn()' /><br />";
$htm +="<input type='button' value='Step 3:Generate Wiki Template' onclick='genTemplate()' /><br />";
$htm +="<textarea rows='5' id='template_out' name='template_out' cols='60' size='50' maxlength='400'></textarea><br />";
$htm +="<input type='button' id='temp_preview' value='Step 4(Optional): Preview the generated code' onclick='tempPreview()' /><br />";
$htm +="Step 5:Copy & Paste the above wiki template text into your wiki article <div id='previewbox' style='display:none'>PREVIEW HERE</div>";


$(document).ready(function(){
try{
	$dialog= $('<div style="overflow-x:scroll;"></div>')
	.html($htm)
	.dialog({autoOpen: false,
	title: 'Template Helper',
	height:500,
	width:600,
	maxHeight:400,
	modal:true});

if($('#wpTextbox1').is(':visible')){
$(".tabs").append("* <span><a href='javascript:void(0)' onclick='openTemplateHelper()' >Template Helper</a></span>");//.insertBefore($('#wpTextbox1'));
}
else{
$(".tabs").append("* <span><a href='javascript:void(0)' onclick='openTemplateHelper()'>Template Helper</a></span>");//.insertBefore($('#wikEdInputWrapper'));
}

	if($('#wpTextbox1').is(':visible') || $('#wikEdInputWrapper').is('.visible')){
	$('#templates_select').empty();
	$("#templates_select").append($("<option value=''>-- Select a Template --</option>") );	
	for(i=0;i<TemplateHelper.Titles.length;i++){
		$("#templates_select").append($("<option value="+i+">"+TemplateHelper.Titles[i]+"</option>") );
	}
	
        if (typeof(UserTemplates) != 'undefined'){
           if(UserTemplates.length>0){
		for(j=0;j<UserTemplates.length;j++){
	          $("#templates_select").append($("<option value="+(i+j)+">"+UserTemplates[j]+"</option>") );
		}
            }
	}
	
	for(i=0;i<TemplateHelper.Titles.length;i++){	
		LoadTemplateData(TemplateHelper.Titles[i]);
	}	
	
	//Load user Templates
       if (typeof(UserTemplates) != 'undefined'){
	  if(UserTemplates.length>0){
		for(i=0;i<UserTemplates.length;i++){
			LoadTemplateData(UserTemplates[i]);
		}
	   }
        }
}

}
catch(err){
//இதற்கு பதில் இந்த வழுவை(dialog is not a function) எப்படி சரி செய்வது என்று பார்க்கவேண்டும்.
}
});
"https://ta.wikipedia.org/w/index.php?title=பயனர்:Mdmahir/template_helper.js&oldid=3355590" இலிருந்து மீள்விக்கப்பட்டது