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

Contenuto cancellato Contenuto aggiunto
Semplificazioni varie
+semplificazioni
Riga 641:
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 682 ⟶ 676:
function InserisciTemplate_PostTagPage( res, page, message ) {
var resPage = Object.values( res.query.pages )[0];
if ( !resPage ) {
return true;
}
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 719 ⟶ 716:
.append( '<br/>' );
} );
 
// show the dialog
var Buttons = {};,
var OKText = lrcMakeText( 'OK' );,
var CancelText = lrcMakeText( 'Cancel' );
 
Buttons[ OKText ] = function() {
var params = {};
Riga 746 ⟶ 744:
 
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 ⟶ 753:
.attr( 'value', ( data.value || '' ) );
} else if ( data.type == 'select' ) {
label = data.name;
inputEl = $( '<select>' )
.attr( 'id', id )
Riga 775 ⟶ 772:
*/
function InserisciTemplate_dumpTemplate( template, params ) {
var templateParams = LiveRC_FormatTemplateParams( params || {} );
return ( template.noinclude ? '<noinclude>' : '' ) +
'{{' + ( template.subst ? 'subst:' : '' ) +
template.template + '|' +
var templateParams = LiveRC_FormatTemplateParams( params || {} ); +
( templateParams ) +
'}}' +
( template.noinclude ? '</noinclude>' : '' ) + '\n';
Riga 804 ⟶ 800:
summary: lrcMakeText( "RESUMESTART" ) + lrcMakeText( "TAG_RESUME" ) + ' ' + data.template,
title: page,
watchlist: lrcMakeParam( "BypassWatchdefault" ) ? 'nochange' : "preferences",
notminor: 1,
nocreate: 1
Riga 811 ⟶ 807:
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 ⟶ 824:
*/
function InserisciTemplate_CreateConfigPanel() {
var InserisciTemplateUl = LiveRC_ManageParams_CreateNewListMenu( "InserisciTemplateLegend", LiveRC_ManageParams_CreateActionButtons() );,
var Target = InserisciTemplateUl.parentNode;,
var Templates = Custom_lstMyTemplate;
 
if ( !Templates || !Object.keys( Templates ).length ) {
Templates = lstMyTemplate;
}
for ( var temp in Templates ) {
if ( !Templates.hasOwnProperty( temp ) ) {
var TemplateForm = Target.appendChild( InserisciTemplate_CreateTemplateConfigPanel( TemplateTemplates[ temp ] ) );
continue;
}
var Template = Templates[ temp ];
var TemplateForm = InserisciTemplate_CreateTemplateConfigPanel( Template );
Target.appendChild( TemplateForm );
}
var NewTemplate = document.createElement( 'p' );
Riga 1 033 ⟶ 1 023:
 
function InserisciTemplate_AddParamToTemplate( AddParamLink ) {
var Li = AddParamLink.parentNode;
var NewParams = {
name: '',
Riga 1 040 ⟶ 1 029:
};
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 043:
DeleteParamLink.href = "javascript:;";
DeleteParamLink.onclick = function() {
$( this.parentNode ).remove();
InserisciTemplate_DeleteParamFromTemplate( this );
};
LI_Param.appendChild( DeleteParamLink );
Riga 1 080 ⟶ 1 068:
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 145:
 
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 188:
 
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 238:
var Span = AddOptionInputCancel.parentNode;
var Link = Span.nextSibling;
Span.parentNode.removeChild$( Span ).remove();
Link.style.display = "";
}
Riga 1 273 ⟶ 1 258:
}
InserisciTemplate_AddOptionToSelect_Cancel( AddOptionInputOK );
 
function InserisciTemplate_DeleteParamFromTemplate( DeleteParamLink ) {
var Li = DeleteParamLink.parentNode;
Li.parentNode.removeChild( Li );
}
 
Riga 1 284 ⟶ 1 264:
*/
function InserisciTemplate_CheckConfigPanel() {
var $ITConfigPanel = document.getElementById$( '#LiveRC_OptionsContent_InserisciTemplateLegend' );
if ( !$ITConfigPanel.length ) {
return;
}
var ElementForms = $( ITConfigPanel ).find( 'form.InserisciTemplate_TemplateForm' );
var Items = {};
for ( var a = 0, l = ElementForms.length; a < l; a++ ) {
var ThisForm = ElementForms[ a ];
var NewItem = {};
NewItem. template: = getElementWithIdThisForm.getElementById( 'template', 'input', ThisForm ).value;,
NewItem. string: = getElementWithIdThisForm.getElementById( 'string', 'input', ThisForm ).value;,
NewItem. where: = getElementWithIdThisForm.getElementById( 'where', 'select', ThisForm ).value;,
NewItem. noinclude: = ( getElementWithIdThisForm.getElementById( 'noinclude', 'input', ThisForm ).checked ? true : false );,
NewItem. subst: = ( getElementWithIdThisForm.getElementById( 'subst', 'input', ThisForm ).checked ? true : false );
} );
NewItem.parameters = {};
var ParamLIs = $( ThisForm ).find( 'li.LI_parameters_li' );
Riga 1 303 ⟶ 1 284:
var ParamLi = ParamLIs[ b ];
var NewParam = {};
var NewParamId = getElementWithIdParamLi.getElementById( 'Param_id', 'input', ParamLi ).value;
NewParam.name = getElementWithIdParamLi.getElementById( 'Param_name', 'input', ParamLi ).value;
NewParam.type = getElementWithIdParamLi.getElementById( 'Param_type', 'select', ParamLi ).value;
if ( NewParam.type == "string" ) {
NewParam.value = getElementWithIdParamLi.getElementById( 'Param_value', 'input', ParamLi ).value.unhtmlize();
if ( !NewParam.value ) {
delete NewParam.value;
Riga 1 313 ⟶ 1 294:
} else {
NewParam.value = [];
var ParamValueSelect = getElementWithIdParamLi.getElementById( 'Param_value', 'select', ParamLi );
var Opt = ParamValueSelect.getElementsByTagName( 'option' );
for ( var c = 0, k = Opt.length; c < k; c++ ) {
Riga 1 372 ⟶ 1 353:
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;
} )
}
 
for ( var paramoldParams in= OldItems[ template ][ item ] ) {.parameters,
ifnewParams (= !NewItems[ template ][ item ][ param ] ) {.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 OldItems[ template ][ item ]oldParams[ param ] ) {
}
if ( OldItems[paramitem template!= ]["value" item|| ]( typeof( oldParams[ param ][ paramitem ][ a ]) != NewItems["object" template&& ][typeof( item ]newParams[ param ][ paramitem ][ a) ]!= "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 = OldItems[ template ][ item ]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;
}
}