MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m fix vari |
Altre semplificazioni piccoline |
||
(9 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 10:
* author Rotpunkt (http://it.wikipedia.org/wiki/Utente:Rotpunkt)
*/
/* jshint maxerr: 10000, curly: true */
LiveRC_Config.InstalledLiveRCExtensions.push( "InserisciTemplate" );
importStylesheetURI( '//it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.css&action=raw&ctype=text/css' );
var templateArguments = {
Riga 626 ⟶ 621:
}
};
function getTemplateList() {
return Object.keys( Custom_lstMyTemplate ).length
? Custom_lstMyTemplate
: lstMyTemplate;
}
// ####################################################################################################################
// ####################################################################################################################
/**
* Add options in the "Tag" form
*/
function lrcRunInsertTemplate( data ) {
var TagSelect = document.getElementById( 'LiveTagReason' )
TemplateList = getTemplateList();
$.each( TemplateList, function( i, val ) {
var optTag = document.createElement( 'option' );
Riga 644 ⟶ 645:
TagSelect.appendChild( optTag );
} );
.attr( 'id', 'gtb-dialog' )
}
LiveRC_AddHook( "AfterPreviewArticle", lrcRunInsertTemplate );
/**
* Function launched when choosing one of this extension options
*/
getLiveTagFunctions.InserisciTemplateExtension = function( page, option ) {
lrcDisableLink( "LiveTagReason" );
lrcDisableLink( "LiveTagLink" );
var TemplateList =
format: 'json',
prop: 'info',
inprop: 'protection',
titles: page
} )
.done( function ( res ) {
InserisciTemplate_PostTagPage( res, page, message );
} );
return false;
};
function InserisciTemplate_PostTagPage(
var resPage = Object.values( res.query.pages )[0];
if ( !resPage ) {
return;
}
for ( var prEntry in resPage.protection ) {
if ( prEntry.type === "edit" && mw.config.get( 'wgUserGroups' ).indexOf( prEntry.level ) === -1 ) {
LiveRC_alert( "<b>" + lrcMakeText( "PROTECTEDPAGE" ).split( "$1" ).join( page ) + "</b>" );
return;
}
}
InserisciTemplate_showDialog( message, page );
}
/**
* Show the dialog in order to ask for the template parameters.
*/
function InserisciTemplate_showDialog( data, page ) {
var $dialog, $fieldset;
$dialog = $( '#gtb-dialog' ).html( lrcMakeText( "IT_InsertTemplate1" ) );
$( '<a>' )
.attr( 'href', mw.
.attr( 'target', '_blank' )
.attr( 'tabindex', '-1' )
Riga 727 ⟶ 717:
.append( '<br/>' );
} );
var
var Buttons
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 );
$( this ).dialog( 'close' );
}
};
$dialog.dialog( {
Riga 754 ⟶ 746:
function InserisciTemplate_buildInputEl( id, data ) {
var label
inputEl;
if ( data.type == 'string' ) {
inputEl = $( '<input/>' )
.attr( 'id', id )
Riga 763 ⟶ 755:
.attr( 'value', ( data.value || '' ) );
} else if ( data.type == 'select' ) {
inputEl = $( '<select>' )
.attr( 'id', id )
Riga 779 ⟶ 770:
}
/**
* Check the dialog box and create the wikitext from the template and its params
*/
function InserisciTemplate_dumpTemplate( template, params ) {
return ( template.noinclude ? '<noinclude>' : '' ) +
'{{' + ( template.subst ? 'subst:' : '' ) +
template.template + '|' +
LiveRC_FormatTemplateParams( params ) +
'}}' +
( template.noinclude ? '</noinclude>' : '' ) + '\n';
}
Riga 796 ⟶ 785:
var text = [];
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 =
action: 'edit',
summary: lrcMakeText( "RESUMESTART" ) + lrcMakeText( "TAG_RESUME" ) + ' ' + data.template,
title: page,
watchlist: lrcMakeParam( "BypassWatchdefault" ) ? 'nochange' : "preferences",
notminor: 1,
nocreate: 1
};
if ( data.where == 'bottom' ) {
} else { // top, or default = top
}
new mw.Api().postWithEditToken( EditParam )
.done( function () {
LiveRC_alert( "<b>" + page + " : " + lrcMakeText( "TAG_DONE" ) + "</b> <small>(" + text + ")</small>" );
} );
}
Riga 848 ⟶ 822:
/**
* Create a fieldset in the configuration panel
*/
function InserisciTemplate_CreateConfigPanel() {
var InserisciTemplateUl = LiveRC_ManageParams_CreateNewListMenu( "InserisciTemplateLegend", LiveRC_ManageParams_CreateActionButtons() )
for ( var temp in Templates ) {
if (
}
}
var NewTemplate = document.createElement( 'p' );
Riga 875 ⟶ 849:
var ThisFieldset = document.getElementById( "LiveRC_OptionsContent_InserisciTemplateLegend" );
var TargetFieldset = document.getElementById( "LiveRC_OptionsContent_lstParamMenuTabs" );
if ( ThisFieldset && TargetFieldset ) {
TargetFieldset.parentNode.insertBefore( ThisFieldset, TargetFieldset ); }
}
LiveRC_AddHook( "AfterCreateParamPanel", InserisciTemplate_CreateConfigPanel );
Riga 881 ⟶ 857:
function InserisciTemplate_AddNewTemplate() {
var P = document.getElementById( "InserisciTemplate_AddNeTemplateP" );
if ( !P ) {
return; }
var BlankTemplate = {
template: '',
Riga 897 ⟶ 875:
var Div = DeleteLink;
while ( Div ) {
if (
break; }
Div = Div.parentNode;
}
if ( !Div ) {
return; }
$( Div ).remove();
}
Riga 908 ⟶ 890:
TemplateDiv.className = "InserisciTemplate_TemplateDiv ParamMenuLi";
var Legend = document.createElement( 'p' );
var Title = document.createElement( 'a' );
Title.className = "InserisciTemplate_template";
Title.innerHTML = "{{" + Template.template + "}} ";
Title.target = "_blank";
Title.href =
Title.title =
Title.onclick = function() {
liveArticle(
return false;
};
Riga 974 ⟶ 956:
Opt.innerHTML = OptValue;
Opt.value = OptValue;
if ( OptValue == Template.where ) {
Opt.selected = "selected"; }
Select_where.appendChild( Opt );
}
Riga 988 ⟶ 972:
Input_noinclude.id = 'noinclude';
Input_noinclude.type = "checkbox";
if ( Template.noinclude ) {
Input_noinclude.checked = "checked"; }
LI_Template.appendChild( Input_noinclude );
LI_Template.appendChild( document.createTextNode( " - " ) );
Riga 1 000 ⟶ 986:
Input_subst.id = 'subst';
Input_subst.type = "checkbox";
if ( Template.subst ) {
Input_subst.checked = "checked"; }
LI_Template.appendChild( Input_subst );
Riga 1 014 ⟶ 1 002:
LI_parameters.appendChild( ParamsUL );
for ( var param in Template.parameters ) {
if ( !Template.parameters.hasOwnProperty( param ) ) {
continue; }
var LI_Param = InserisciTemplate_CreateNewParam( param, Template.parameters[ param ] );
ParamsUL.appendChild( LI_Param );
Riga 1 032 ⟶ 1 022:
function InserisciTemplate_AddParamToTemplate( AddParamLink ) {
var NewParams = {
name: '',
Riga 1 039 ⟶ 1 028:
};
var NewParamLi = InserisciTemplate_CreateNewParam( "", NewParams );
}
function InserisciTemplate_CreateNewParam( param, Params ) {
var ParamType = Params.type;
var ParamValue = Params.value;
Riga 1 054 ⟶ 1 042:
DeleteParamLink.href = "javascript:;";
DeleteParamLink.onclick = function() {
$( this.parentNode ).remove();
};
LI_Param.appendChild( DeleteParamLink );
Riga 1 079 ⟶ 1 067:
Input_name.id = 'Param_name';
Input_name.type = "text";
Input_name.value = (
LI_Param.appendChild( Input_name );
LI_Param.appendChild( document.createTextNode( " - " ) );
Riga 1 096 ⟶ 1 084:
Opt.innerHTML = OptValue;
Opt.value = OptValue;
if ( OptValue == ParamType ) {
Opt.selected = "selected"; }
Select_type.appendChild( Opt );
}
Select_type.onchange = function() {
};
LI_Param.appendChild( Select_type );
LI_Param.appendChild( document.createTextNode( " - " ) );
Riga 1 153 ⟶ 1 143:
}
function
var
var LastLabel = Labels[ ( Labels.length - 1 ) ];
while ( LastLabel.nextSibling ) {
}
if (
var Input_value = document.createElement( 'input' );
Input_value.id = 'Param_value';
Riga 1 199 ⟶ 1 187:
function InserisciTemplate_DeleteOptionFromSelect( DeleteOptionLink ) {
var
for ( var a = 0, l = Selects.length; a < l; a++ ) {
var Select = Selects[ a ];
if ( !Select.id || Select.id != 'Param_value' ) {
continue; }
var SelectedOpt = Select.value;
var Options = Select.getElementsByTagName( 'option' );
for ( var b = 0, m = Options.length; b < m; b++ ) {
var thisOpt = Options[ b ];
if ( thisOpt.value != SelectedOpt ) {
continue; }
thisOpt.parentNode.removeChild( thisOpt );
}
Riga 1 246 ⟶ 1 237:
var Span = AddOptionInputCancel.parentNode;
var Link = Span.nextSibling;
Link.style.display = "";
}
Riga 1 257 ⟶ 1 248:
for ( var a = 0, l = Selects.length; a < l; a++ ) {
var Select = Selects[ a ];
if ( !Select.id || Select.id != 'Param_value' ) {
continue; }
var Option = document.createElement( 'option' );
Option.innerHTML = NewOption;
Riga 1 263 ⟶ 1 256:
Select.appendChild( Option );
}
InserisciTemplate_AddOptionToSelect_Cancel( AddOptionInputOK );
}
/**
* Check the fieldset and add a text to be saved in /LiveRCparam.js page
*/
function InserisciTemplate_CheckConfigPanel() {
var $ITConfigPanel =
if ( !$ITConfigPanel.length ) {
return; }
var Items = {};
$ITConfigPanel.find( 'form.InserisciTemplate_TemplateForm' ).each( function () {
var
template: this.getElementById( 'template' ).value,
string: this.getElementById( 'string' ).value,
where: this.getElementById( 'where' ).value,
noinclude: this.getElementById( 'noinclude' ).checked,
subst: this.getElementById( 'subst' ).checked
};
NewItem.parameters = {};
var ParamLIs =
var
name: this.getElementById( 'Param_name' ).value,
type: this.getElementById( 'Param_type' ).value
};
if ( NewParam.type == "string" ) {
if (
NewParam.value = value;
}
} else {
NewParam.value = [];
var
Opt.each( function () {
NewParam.value.push( this.value.unhtmlize() );
} );
}
NewItem.parameters[
} );
Items[ NewItem.template ] = NewItem;
} );
var TextToSave = InserisciTemplate_CompareNewParams( Items );
if ( !TextToSave ) {
return; }
var SavedText = "\nCustom_lstMyTemplate = {\n";
var SavedItems = [];
Riga 1 350 ⟶ 1 342:
SavedText += SavedItems.join( ",\n" );
SavedText += "};\n\n";
LiveRC_Config
}
LiveRC_AddHook( "BeforeParamPanelSaved", InserisciTemplate_CheckConfigPanel );
Riga 1 356 ⟶ 1 348:
function InserisciTemplate_CompareNewParams( NewItems ) {
var OldItems = lstMyTemplate;
if ( JSON.stringify( Object.keys( OldItems ).sort() ) !== JSON.stringify( Object.keys( NewItems ).sort() ) ) {
return true;
}
for ( var template in OldItems ) {
for ( var item in OldItems[ template ] ) {
if ( item !== "parameters" && OldItems[ template ][ item ] !== NewItems[ template ][ item ] ) {
return true;
}
}
if ( Object.keys( oldParams ).length !== Object.keys( newParams ).length ) {
}
if ( !newParams[ param ] ) {
}
for ( var paramitem in oldParams[ param ] ) {
if ( paramitem != "value" || ( typeof( oldParams[ param ][ paramitem ] ) != "object" && typeof( newParams[ param ][ paramitem ] ) != "object" ) ) {
if ( oldParams[ param ][ paramitem ] !== newParams[ param ][ paramitem ] ) {
return true;
}
} else {
if ( oldParams[ param ][ paramitem ].length != newParams[ param ][ paramitem ].length ) {
return true;
}
for ( var a = 0, l = oldParams[ param ][ paramitem ].length; a < l; a++ ) {
if ( oldParams[ param ][ paramitem ][ a ] != newParams[ param ][ paramitem ][ a ] ) {
return true;
}
}
Riga 1 378 ⟶ 1 387:
}
}
}
return false;
}
/
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";
lrcTexts.IT_AddParam = "Aggiungi un nuovo parametro";
lrcTexts.IT_DeleteParam = "Cancella questo parametro";
lrcTexts.IT_DeleteOption = "Cancella l'opzione selezionata";
lrcTexts.IT_AddOption = "Aggiungi una nuova opzione";
lrcParamDesc.DescIT_InsertTemplate1 = "[InserisciTemplate] Inserisci la parte 1 della frase del template";
lrcParamDesc.DescIT_InsertTemplate2 = "[InserisciTemplate] Inserisci la parte 2 della frase del template";
lrcParamDesc.DescIT_InsertTemplateParams = "[InserisciTemplate] Parametri";
lrcParamDesc.DescIT_AddTemplate = "[InserisciTemplate] Frase Aggiungi un nuovo template";
lrcParamDesc.DescIT_DeleteTemplate = "[InserisciTemplate] Frase Cancella questo template";
lrcParamDesc
lrcParamDesc
lrcParamDesc
lrcParamDesc.DescIT_AddOption = "[InserisciTemplate] Frase Aggiungi una nuova opzione";
lrcParamDesc
lrcParamDesc
// Hide/Show tabs panel item
addParamMenuTab( "InserisciTemplateLegend", true );
|