MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Semplificazioni varie
Altre semplificazioni piccoline
 
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 621:
}
};
 
function getTemplateList() {
return Object.keys( Custom_lstMyTemplate ).length
? Custom_lstMyTemplate
: lstMyTemplate;
}
 
// ####################################################################################################################
Riga 630 ⟶ 636:
function lrcRunInsertTemplate( data ) {
var TagSelect = document.getElementById( 'LiveTagReason' ),
TemplateList = Custom_lstMyTemplategetTemplateList();
 
if ( !Object.keys( TemplateList ).length ) {
TemplateList = lstMyTemplate;
}
$.each( TemplateList, function( i, val ) {
var optTag = document.createElement( 'option' );
Riga 641 ⟶ 645:
TagSelect.appendChild( optTag );
} );
 
// setup dialog
mw.loader.using$( 'jquery.ui<div>' )
.attr( 'id', 'gtb-dialog' )
.done( function() {
$.appendTo( '<div>body' );
.attr( 'id', 'gtb-dialog' )
.appendTo( 'body' );
} )
.fail( function() {
console.warn( 'Errore del RL con l\'estensione InserisciTemplate di LiveRC' );
} );
}
LiveRC_AddHook( "AfterPreviewArticle", lrcRunInsertTemplate );
Riga 661 ⟶ 659:
lrcDisableLink( "LiveTagLink" );
 
var TemplateList = Custom_lstMyTemplate;getTemplateList(),
if message ( !Object.keys(= TemplateList[ )option.length )value {];
TemplateList = lstMyTemplate;
}
var message = TemplateList[ option.value ];
 
new mw.Api().get( {
Riga 682 ⟶ 677:
function InserisciTemplate_PostTagPage( res, page, message ) {
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;
Riga 696 ⟶ 694:
function InserisciTemplate_showDialog( data, page ) {
var $dialog, $fieldset;
 
// create the dialog html
$dialog = $( '#gtb-dialog' ).html( lrcMakeText( "IT_InsertTemplate1" ) );
$( '<a>' )
Riga 719 ⟶ 717:
.append( '<br/>' );
} );
 
// show the dialog
var ButtonsOKText = {};lrcMakeText( 'OK' ),
var OKText CancelText = lrcMakeText( 'OKCancel' );
 
var CancelText = lrcMakeText( 'Cancel' );
var Buttons[ OKText ] = function() {
varOKText: params =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 ] =: function() {
$( this ).dialog( 'close' );
}
};
$dialog.dialog( {
Riga 746:
 
function InserisciTemplate_buildInputEl( id, data ) {
var label, inputEl;= data.name,
inputEl;
if ( data.type == 'string' ) {
label = data.name;
inputEl = $( '<input/>' )
.attr( 'id', id )
Riga 755:
.attr( 'value', ( data.value || '' ) );
} else if ( data.type == 'select' ) {
label = data.name;
inputEl = $( '<select>' )
.attr( 'id', id )
Riga 775 ⟶ 774:
*/
function InserisciTemplate_dumpTemplate( template, params ) {
var templateParams = LiveRC_FormatTemplateParams( params || {} );
return ( template.noinclude ? '<noinclude>' : '' ) +
'{{' + ( template.subst ? 'subst:' : '' ) +
template.template + '|' +
LiveRC_FormatTemplateParams( params ) +
( templateParams ) +
'}}' +
( template.noinclude ? '</noinclude>' : '' ) + '\n';
Riga 804 ⟶ 802:
summary: lrcMakeText( "RESUMESTART" ) + lrcMakeText( "TAG_RESUME" ) + ' ' + data.template,
title: page,
watchlist: lrcMakeParam( "BypassWatchdefault" ) ? 'nochange' : "preferences",
notminor: 1,
nocreate: 1
Riga 811 ⟶ 809:
if ( data.where == 'bottom' ) {
EditParam.appendtext = "\n" + text;
} else { // top, or default = top
EditParam.prependtext = text + "\n";
}
 
if ( lrcMakeParam( "BypassWatchdefault" ) ) {
EditParam.watchlist = "nochange";
}
 
Riga 832 ⟶ 826:
*/
function InserisciTemplate_CreateConfigPanel() {
var InserisciTemplateUl = LiveRC_ManageParams_CreateNewListMenu( "InserisciTemplateLegend", LiveRC_ManageParams_CreateActionButtons() );,
var Target = InserisciTemplateUl.parentNode;,
var Templates = Custom_lstMyTemplategetTemplateList();
 
if ( !Templates || !Object.keys( Templates ).length ) {
Templates = lstMyTemplate;
}
for ( var temp in Templates ) {
if ( !Templates.hasOwnProperty( temp ) ) {
Target.appendChild( InserisciTemplate_CreateTemplateConfigPanel( Templates[ temp ] ) );
continue;
}
var Template = Templates[ temp ];
var TemplateForm = InserisciTemplate_CreateTemplateConfigPanel( Template );
Target.appendChild( TemplateForm );
}
var NewTemplate = document.createElement( 'p' );
Riga 1 033 ⟶ 1 022:
 
function InserisciTemplate_AddParamToTemplate( AddParamLink ) {
var Li = AddParamLink.parentNode;
var NewParams = {
name: '',
Riga 1 040 ⟶ 1 028:
};
var NewParamLi = InserisciTemplate_CreateNewParam( "", NewParams );
Li.parentNode.insertBefore$( NewParamLi, Li).insertBefore( AddParamLink.parentNode );
}
 
function InserisciTemplate_CreateNewParam( param, Params ) {
var ParamName = Params.name;
var ParamType = Params.type;
var ParamValue = Params.value;
Riga 1 055 ⟶ 1 042:
DeleteParamLink.href = "javascript:;";
DeleteParamLink.onclick = function() {
$( this.parentNode ).remove();
InserisciTemplate_DeleteParamFromTemplate( this );
};
LI_Param.appendChild( DeleteParamLink );
Riga 1 080 ⟶ 1 067:
Input_name.id = 'Param_name';
Input_name.type = "text";
Input_name.value = ( ParamNameParams.name || "" );
LI_Param.appendChild( Input_name );
LI_Param.appendChild( document.createTextNode( " - " ) );
Riga 1 157 ⟶ 1 144:
 
function InserisciTemplate_ChangeValueType( Select ) {
var NewTypeLabels = Select.valueparentNode.getElementsByTagName( 'label' );
var Li = Select.parentNode;
var Labels = Li.getElementsByTagName( 'label' );
var LastLabel = Labels[ ( Labels.length - 1 ) ];
while ( LastLabel.nextSibling ) {
LastLabel.nextSibling.parentNode.removeChild$( LastLabel.nextSibling ).remove();
}
if ( NewTypeSelect.value == "string" ) {
var Input_value = document.createElement( 'input' );
Input_value.id = 'Param_value';
Riga 1 202 ⟶ 1 187:
 
function InserisciTemplate_DeleteOptionFromSelect( DeleteOptionLink ) {
var LiSelects = DeleteOptionLink.parentNode.getElementsByTagName( 'select' );
var Selects = Li.getElementsByTagName( 'select' );
for ( var a = 0, l = Selects.length; a < l; a++ ) {
var Select = Selects[ a ];
Riga 1 253 ⟶ 1 237:
var Span = AddOptionInputCancel.parentNode;
var Link = Span.nextSibling;
Span.parentNode.removeChild$( Span ).remove();
Link.style.display = "";
}
Riga 1 273 ⟶ 1 257:
}
InserisciTemplate_AddOptionToSelect_Cancel( AddOptionInputOK );
}
 
function InserisciTemplate_DeleteParamFromTemplate( DeleteParamLink ) {
var Li = DeleteParamLink.parentNode;
Li.parentNode.removeChild( Li );
}
 
Riga 1 284 ⟶ 1 263:
*/
function InserisciTemplate_CheckConfigPanel() {
var $ITConfigPanel = document.getElementById$( '#LiveRC_OptionsContent_InserisciTemplateLegend' );
if ( !$ITConfigPanel.length ) {
return;
}
var ElementForms = $( ITConfigPanel ).find( 'form.InserisciTemplate_TemplateForm' );
var Items = {};
$ITConfigPanel.find( 'form.InserisciTemplate_TemplateForm' ).each( function () {
for ( var a = 0, l = ElementForms.length; a < l; a++ ) {
var ThisFormNewItem = ElementForms[ a ];{
template: this.getElementById( 'template' ).value,
var NewItem = {};
string: this.getElementById( 'string' ).value,
NewItem.template = getElementWithId( 'template', 'input', ThisForm ).value;
where: this.getElementById( 'where' ).value,
NewItem.string = getElementWithId( 'string', 'input', ThisForm ).value;
noinclude: this.getElementById( 'noinclude' ).checked,
NewItem.where = getElementWithId( 'where', 'select', ThisForm ).value;
subst: this.getElementById( 'subst' ).checked
NewItem.noinclude = ( getElementWithId( 'noinclude', 'input', ThisForm ).checked ? true : false );
};
NewItem.subst = ( getElementWithId( 'subst', 'input', ThisForm ).checked ? true : false );
NewItem.parameters = {};
var ParamLIs = $( ThisFormthis ).find( 'li.LI_parameters_li' );
for ( var b = 0, m = ParamLIs.length;each( b < m; b++function () {
var ParamLiNewParam = ParamLIs[ b ];{
name: this.getElementById( 'Param_name' ).value,
var NewParam = {};
type: this.getElementById( 'Param_type' ).value
var NewParamId = getElementWithId( 'Param_id', 'input', ParamLi ).value;
};
NewParam.name = getElementWithId( 'Param_name', 'input', ParamLi ).value;
NewParam.type = getElementWithId( 'Param_type', 'select', ParamLi ).value;
if ( NewParam.type == "string" ) {
NewParam.var value = getElementWithIdthis.getElementById( 'Param_value', 'input', ParamLi ).value.unhtmlize();
if ( !NewParam.value ) {
delete NewParam.value = value;
}
} else {
NewParam.value = [];
var ParamValueSelect$Opt = getElementWithId$( this.getElementById( 'Param_value', ) ).find( 'select.option', ParamLi );
Opt.each( function () {
var Opt = ParamValueSelect.getElementsByTagName( 'option' );
NewParam.value.push( this.value.unhtmlize() );
for ( var c = 0, k = Opt.length; c < k; c++ ) {
} );
NewParam.value.push( Opt[ c ].value.unhtmlize() );
}
}
NewItem.parameters[ NewParamIdthis.getElementById( 'Param_id' ).value ] = NewParam;
} );
Items[ NewItem.template ] = NewItem;
} );
var TextToSave = InserisciTemplate_CompareNewParams( Items );
if ( !TextToSave ) {
Riga 1 372 ⟶ 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 ) {
iffor ( typeof(var NewItemsitem in OldItems[ template ] ) === "undefined" ) {
if ( item !== "parameters" && OldItems[ template ][ item ] !== NewItems[ template ][ item ] ) {
return true;
}
}
 
var oldParams = OldItems[ template ].parameters,
newParams = NewItems[ template ].parameters;
 
if ( Object.keys( oldParams ).length !== Object.keys( newParams ).length ) {
return true;
}
for ( var itemparam in OldItems[ template ]oldParams ) {
if ( item !=newParams[ param "parameters"] ) {
return true;
if ( OldItems[ template ][ item ] !== NewItems[ template ][ item ] ) {
}
return true;
for ( var paramitem in oldParams[ param ] ) {
}
if ( paramitem != "value" || ( typeof( oldParams[ param ][ paramitem ] ) != "object" && typeof( newParams[ param ][ paramitem ] ) != "object" ) ) {
} else {
if ( Object.keys( OldItemsoldParams[ templateparam ][ itemparamitem ] ).length !== Object.keys( NewItemsnewParams[ templateparam ][ itemparamitem ] ).length ) {
return true;
}
for ( var param in OldItems[ template ][ item ] ) {
if ( !NewItems[ template ][ item ][ param ] ) {
return true;
}
} else {
for ( var paramitem in OldItems[ template ][ item ][ param ] ) {
if ( paramitem != "value" || ( typeof( OldItems[ template ][ item ]oldParams[ param ][ paramitem ] ).length != "object" && typeof( NewItems[ template ][ item ]newParams[ param ][ paramitem ] ) != "object" ).length ) {
return true;
if ( OldItems[ template ][ item ][ param ][ paramitem ] !== NewItems[ template ][ item ][ param ][ paramitem ] ) {
return true;}
for ( var a = 0, l = oldParams[ param ][ paramitem ].length; a < l; a++ ) {
}
if ( oldParams[ param ][ paramitem ][ a ] != newParams[ param ][ paramitem ][ a ] ) {
} else {
return true;
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;
}
}