MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica |
Dr. Brains modif |
||
Riga 18:
* Licence : ...?
* Documentation :
* Auteur : [[:it:User:Jalo]] [[:it:User:Rotpunkt]] [[:fr:User:Dr Brains]]
*
* This script contains functions (InserisciTemplate_showDialog, InserisciTemplate_dumpTemplate and InserisciTemplate_buildInputEl)
Riga 144:
/* Template list:
*
* 'template': (string) name of the template to be inserted
* 'string': (string) option label in the template combo box
* 'where': (string) where to insert the template in the page.
* 'noinclude': (boolean) whether the template shall be tagged with "noinclude"
* 'subst': (boolean) whether the template shall be "substed"
* 'parameters': (object) list of the parameters of the template
* 'name': (string) parameter name shown in the popup dialog
* 'type': (string) type of the argument. Accepted values are: string
* 'value':
* type==string
* type==
*/
Riga 170 ⟶ 168:
argomento: {name: 'Argomento', type: 'select', value: templateArguments_A},
argomento2: {name: 'Argomento2', type: 'select', value: templateArguments_A},
mese: {name: 'Mese', type: 'string'
}
},
Riga 397 ⟶ 395:
}
};
// ####################################################################################################################
// ####################################################################################################################
// Add options in the "Tag" form
function lrcRunInsertTemplate(data){
var TagSelect = document.getElementById('LiveTagReason');
jQuery.each(lstMyTemplate, function(i, val) {
var optTag = document.createElement('option');
Riga 419 ⟶ 410:
TagSelect.appendChild(optTag);
});
// setup dialog
mw.loader.using(['jquery.ui.dialog'], function () {
Riga 427 ⟶ 417:
});
}
LiveRC_AddHook("AfterPreviewArticle", lrcRunInsertTemplate);
// Function launched when choosing one of this extension options
getLiveTagFunctions["InserisciTemplateExtension"] = function(page, option){
lrcDisableLink("LiveTagReason");
lrcDisableLink("LiveTagLink");
var message = lstMyTemplate[option.value];
wpajax.http({ url: wgServer + wgScriptPath + '/api.php?format=xml'
Riga 446 ⟶ 435:
}
// Get page edit token and protection status
function InserisciTemplate_PostTagPage(xmlreq, data){
Riga 464 ⟶ 453:
}
var Page = ObjetXML.getElementsByTagName("page")[0];
LiveRC_Config["edittoken"] = Page.getAttribute("edittoken");
// show dialog
var tpl = InserisciTemplate_showDialog(message, page);
}
// Show the dialog in order to ask for the template parameters.
function InserisciTemplate_showDialog(data, page) {
var $dialog, $fieldset;
// create the dialog html
$dialog = $('#gtb-dialog').html(lrcMakeText("IT_InsertTemplate1"));
Riga 494 ⟶ 473:
$dialog.append(lrcMakeText("IT_InsertTemplate2"));
$fieldset = $('<fieldset>').css('border-color', 'gray').appendTo($dialog);
$('<legend>').text(lrcMakeText('
$.each(data.parameters, function (id, val) {
var inputEl = InserisciTemplate_buildInputEl(id, val);
Riga 506 ⟶ 485:
.append('<br/>');
});
// show the dialog
var Buttons = new Object();
var OKText = lrcMakeText('OK');
var CancelText = lrcMakeText('Cancel');
Buttons[OKText] = function () {
var params = {};
$dialog.find('input:text,select').each(function () {
params[$(this).attr('id')] = $.trim($(this).val());
});
text = InserisciTemplate_dumpTemplate(data, params);
$(this).dialog('close');
InserisciTemplate_postTemplate(data, text, page);
}
Buttons[CancelText]
$(this).dialog('close');
};
$dialog.dialog({
title: lrcMakeIcon("LogoIcon") + ' ' + data.string,
width: 500,
resizable: false,
modal: true,
zIndex: 10000,
buttons: Buttons
});
}
function InserisciTemplate_buildInputEl(id, data) {
var label, inputEl;
if (data.type == 'string') {
label = data.name;
inputEl = $('<input/>')
.attr('id', id)
.attr('type', 'text')
.attr('size', 50)
.attr('value', (data.value || ''));
} else if (data.type == 'select') {
label = data.name;
inputEl = $('<select>')
.attr('id', id)
.css('width', '200px');
$.each(data.value, function (i, option) {
$('<option>')
.html(option)
.appendTo(inputEl);
});
}
return { label: label, el: inputEl };
}
// Check the dialog box and create the wikitext from the template and its params
function InserisciTemplate_dumpTemplate(template, params) {
Riga 543 ⟶ 545:
'}}' +
(template.noinclude ? '</noinclude>' : '') + '\n';
return text;
}
function LiveRC_FormatTemplateParams(params) {
var text = new Array();
for(var arg in params){
if(params.hasOwnProperty(arg)) text.push(arg+"="+params[arg]);
}
return text.join("|");
}
// Save the edit
function InserisciTemplate_postTemplate (data, text, page){
lrcDisableLink("LiveTagReason");
lrcDisableLink("LiveTagLink");
var EditParam = new Array();
EditParam["token"] = LiveRC_Config["edittoken"];
if (data.where == 'top')
EditParam["prependtext"] = text+"\n";
Riga 564 ⟶ 574:
EditParam["notminor"] = "1";
EditParam["nocreate"] = "1";
if(lrcMakeParam("BypassWatchdefault")) EditParam["watchlist"] = "nochange";
var Params = new Array();
for(var Param in EditParam){
Riga 581 ⟶ 590:
});
}
function
var params = data.params;
var where = data.where;
var text = "<b>" +params["title"]+ " : " + lrcMakeText("TAG_DONE") + "</b> <small>("+params[(where=='bottom')?"appendtext":"prependtext"]+")</small>";
LiveRC_alert(text);
}
/* ########################################## CONFIGURATION PANEL ################################## */
Riga 1 028 ⟶ 1 012:
NewParam.type = getElementWithId('Param_type', 'select', ParamLi).value;
if(NewParam.type == "string"){
NewParam.value = getElementWithId('Param_value', 'input', ParamLi).value.unhtmlize();
if(!NewParam.value) delete NewParam.value;
}else{
NewParam.value = new Array();
Riga 1 034 ⟶ 1 019:
var Opt = ParamValueSelect.getElementsByTagName('option');
for(var c=0,k=Opt.length;c<k;c++){
NewParam.value.push(Opt[c].value.unhtmlize());
}
}
Riga 1 041 ⟶ 1 026:
Items[NewItem.template] = NewItem;
}
var TextToSave = InserisciTemplate_CompareNewParams(Items);
if(!TextToSave) return;
var SavedText = "\nCustom_lstMyTemplate = {\n";
var SavedItems = new Array();
Riga 1 050 ⟶ 1 037:
var tempParamValue = ThisTemplate[tempParam];
if(tempParam!="parameters"){
SavedItem += ( typeof(tempParamValue)=="string" ?
}else{
SavedItem += "{\n";
Riga 1 060 ⟶ 1 047:
var thisparamItemValue = thisparam[paramItem];
if(paramItem!="value" || typeof(thisparamItemValue)=="string"){
ParamItems.push( paramItem + ":" +
}else{
var ThisParamValue = new Array();
for(var a=0,l=thisparamItemValue.length;a<l;a++){
ThisParamValue.push(
}
ParamItems.push( paramItem +": [" + ThisParamValue.join(",") + "]" );
}
}
tempParameters.push(" " +
}
SavedItem += tempParameters.join(",\n");
Riga 1 084 ⟶ 1 071:
LiveRC_AddHook("BeforeParamPanelSaved", InserisciTemplate_CheckConfigPanel);
function InserisciTemplate_CompareNewParams(NewItems){
var OldItems = lstMyTemplate;
for(var template in OldItems){
if(typeof(NewItems[template])==="undefined") return true;
for(var item in OldItems[template]){
if(item != "parameters"){
if(OldItems[template][item] !== NewItems[template][item]) return true;
}else{
if(lrcGetObjectLength(OldItems[template][item]) != lrcGetObjectLength(NewItems[template][item])) return true;
for(var param in OldItems[template][item]){
if(!NewItems[template][item][param]) return true;
for(var paramitem in OldItems[template][item][param]){
if(paramitem != "value" || (typeof(OldItems[template][item][param][paramitem]) != "object" && typeof(NewItems[template][item][param][paramitem]) != "object")){
if(OldItems[template][item][param][paramitem] !== NewItems[template][item][param][paramitem]) return true;
}else{
if(OldItems[template][item][param][paramitem].length != NewItems[template][item][param][paramitem].length) return true;
for(var a=0, l=OldItems[template][item][param][paramitem].length;a<l;a++){
if(OldItems[template][item][param][paramitem][a] != NewItems[template][item][param][paramitem][a]) return true;
}
}
}
}
}
}
}
for(var template in NewItems){
if(typeof(OldItems[template])==="undefined") return true;
}
return false;
}
// ===== Vars for configuration panel fieldset =====
Riga 1 091 ⟶ 1 107:
try{
lrcTexts["IT_InsertTemplate1"] = "Inserisce il template {{";
lrcTexts["IT_InsertTemplate2"] = "}} nella pagina.";
lrcTexts["IT_InsertTemplateParams"] = "Parametri";
lrcTexts["IT_AddTemplate"] = "Aggiungi un nuovo template";
lrcTexts["IT_DeleteTemplate"] = "Cancella questo template";
Riga 1 104 ⟶ 1 121:
// Descriptions
try{
lrcParamDesc["DescIT_InsertTemplate1"] = "[InserisciTemplate] Inserisci la parte 1 della frase del template";
lrcParamDesc["DescIT_InsertTemplate2"] = "[InserisciTemplate] Inserisci la parte
lrcParamDesc["DescIT_InsertTemplateParams"] = "[InserisciTemplate] Parametri";
lrcParamDesc["DescIT_AddTemplate"] = "[InserisciTemplate] Frase Aggiungi un nuovo template";
lrcParamDesc["DescIT_DeleteTemplate"] = "[InserisciTemplate] Frase Cancella questo template";
|