Diferencia entre revisiones de «MediaWiki:Gadget-Versalitas.js»

De EIFA - Estudios Interdisciplinares de las Fuentes Avilistas
Etiqueta: Revertido
(Se ha deshecho la revisión 679 de Juancc (disc.))
Etiqueta: Deshacer
 
(No se muestran 35 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
/**
ve.ui.VersalitasCommand = function VeUiVersalitasCommand() {
* Adds dialog for selecting citation tempalte.
ve.ui.VersalitasCommand.super.call( this, 'Versalitas' );
* Written by: [[User:ערן]] and [[User:Ravid ziv]]
};
*/
OO.inheritClass( ve.ui.VersalitasCommand, ve.ui.Command );
(function () {


/************* Configuration section *******************************************/
ve.ui.VersalitasCommand.prototype.execute = function ( surface ) {
var model = surface.getModel(),
fragment = model.getFragment(),
doc = model.getDocument(),
range = fragment.getSelection().getRange();


var DialogTitle = 'Select citation template';
// Obtener el contenido seleccionado
//Configurate the most common citation templates and their parameters here
var selectedContent = doc.getData( range );
var CitationTemplates = {
'Cite Web ': { template: {
// Crear el contenido para {{versal}}
target: {
var versalStart = [
href: 'Template:cite web',
{
wt: 'cite web'
type: 'mwTransclusionInline',
},
attributes: {
params: {
mw: {
'first': {wt: ''},
parts: [{
'last': {wt: ''},
template: {
'title': {wt: ''},
target: {
'url': {wt: ''},
href: 'Template:Versal',
'publisher': {wt: ''},
wt: 'versal'
'accessdate': {wt: ''}
},
params: {}
}
}]
}
}
}
},
{
type: '/mwTransclusionInline'
}
}
},
];
'Cite news': { template: {
 
target: {
// Crear el contenido para {{fin}}
href: 'Template:cite news',
var versalEnd = [
wt: 'cite news'
{
},
type: 'mwTransclusionInline',
params: {
attributes: {
'first': {wt: ''},
mw: {
'last': {wt: ''},
parts: [{
'title': {wt: ''},
template: {
'url': {wt: ''},
target: {
'accessdate': {wt: ''},
href: 'Template:Fin',
'newspaper': {wt: ''}
wt: 'fin'
}
},
}
params: {}
},
}
'Cite book': { template: {
}]
target: {
href: 'Template:cite book',
wt: 'cite book'
},
params: {
'first': {wt: ''},
'last': {wt: ''},
'date': {wt: ''},
'publisher': {wt: ''},
'location': {wt: ''},
'isbn': {wt: ''},
'page': {wt: ''},
'url': {wt: ''}
}
}
},
'Cite journal ': { template: {
target: {
href: 'Template:cite journal',
wt: 'cite journal'
},
params: {
'first': {wt: ''},
'last': {wt: ''},
'coauthors': {wt: ''},
'journal': {wt: ''},
'date': {wt: ''},
'volume': {wt: ''},
'series': {wt: ''},
'issue': {wt: ''},
'page': {wt: ''},
'doi': {wt: ''},
'pmid': {wt: ''},
'url': {wt: ''},
'accessdate': {wt: ''}
}
}
}
}
},
{
type: '/mwTransclusionInline'
}
}
}
];


/*************************** end of configuration section *********************/
// Combinar todo: {{versal}} + contenido seleccionado + {{fin}}
ve.ui.VeUiMWCiteDialog = function VeUiMWCiteDialog( surface, config ) {
var newContent = versalStart.concat( selectedContent ).concat( versalEnd );
// Configuration initialization
 
config = ve.extendObject( { 'size': 'medium' }, config );
// Reemplazar el contenido seleccionado
// Parent constructor
fragment.insertContent( newContent );
ve.ui.MWReferenceDialog.call( this, surface, config );
this.followTransactions  = false;
};
};
/* Inheritance */
OO.inheritClass( ve.ui.VeUiMWCiteDialog, ve.ui.MWReferenceDialog );
/* Static Properties */
ve.ui.VeUiMWCiteDialog.static.name = 'Cite';
ve.ui.VeUiMWCiteDialog.static.title = DialogTitle;


ve.ui.commandRegistry.register( new ve.ui.VersalitasCommand() );


ve.ui.VeUiMWCiteDialog.prototype.initialize = function ( ) {
ve.ui.VersalitasTool = function VeUiVersalitasTool() {
ve.ui.MWReferenceDialog.prototype.initialize.call(this);
ve.ui.VersalitasTool.super.apply( this, arguments );
// hide reference panel
this.editPanel.$element.hide()
this.$foot.hide();
 
this.templatesPanel = new OO.ui.PanelLayout( {
'$': this.$, 'scrollable': true, 'padded': true
} );
 
this.panels.addItems( [ this.templatesPanel ] );
 
var buttons = [];
for (var buttonName in CitationTemplates) {
var button = new OO.ui.ButtonWidget( {
'$': this.$,
'label': buttonName,
} );
button.connect( this, { 'click': [ 'citeWeb', CitationTemplates[buttonName] ] } );
buttons.push(button.$element);
}
this.templatesPanel.$element.append(buttons).show();
 
}
 
ve.ui.VeUiMWCiteDialog.prototype.useReference = function ( ref ) {
 
this.followTransactions  = false;
ve.ui.MWReferenceDialog.prototype.useReference.call(this, ref);
}
ve.ui.VeUiMWCiteDialog.prototype.citeWeb = function( emptyTemplate ){
this.referenceSurface.getSurface().getModel().getFragment().collapseRangeToEnd().insertContent([{'type': 'mwTransclusionInline','attributes': {'mw':
{
parts: [ emptyTemplate ]
}}}]);
this.followTransactions  = true;
this.referenceSurface.getSurface().execute('dialog', 'open', 'transclusion', null);
var self = this;
this.referenceSurface.getSurface().getDialogs().getWindow('transclusion').on(
'close',function (data){
if (data.action=='cancel')
{
self.close({ 'action': 'cancel' });
}
});
}
ve.ui.VeUiMWCiteDialog.prototype.onDocumentTransact = function () {
if (!this.followTransactions) return;
var data = this.referenceSurface.getSurface().getModel().getDocument().getFullData();
for (var j=0;j<data.length;j++)
{
var node = data[j];
if (node.type ==="mwTransclusionInline" && node.hasOwnProperty('attributes') )
{
var params = node.attributes.mw.parts[0].template.params;
this.close( { 'action': 'insert' } );
}
}
};
/* Registration */
ve.ui.dialogFactory.register( ve.ui.VeUiMWCiteDialog );
function CiteTool( toolGroup, config ) {
OO.ui.Tool.call( this, toolGroup, config );
}
OO.inheritClass( CiteTool, OO.ui.Tool );
CiteTool.static.name = 'CiteTool';
CiteTool.static.title = 'Cite'
CiteTool.prototype.onSelect = function () {
this.toolbar.getSurface().execute('dialog', 'open', 'Cite', null);
};
CiteTool.prototype.onUpdateState = function () {
this.setActive( false );
};
};
OO.inheritClass( ve.ui.VersalitasTool, ve.ui.Tool );
ve.ui.toolFactory.register( CiteTool );
ve.ui.VersalitasTool.static.name = 'Versalitas';
ve.ui.VersalitasTool.static.group = 'textStyle';
})();
ve.ui.VersalitasTool.static.icon = 'largerText';
ve.ui.VersalitasTool.static.title = 'Versalitas';
ve.ui.VersalitasTool.static.commandName = 'Versalitas';
ve.ui.toolFactory.register( ve.ui.VersalitasTool );

Revisión actual - 19:29 29 jun 2025

ve.ui.VersalitasCommand = function VeUiVersalitasCommand() {
	ve.ui.VersalitasCommand.super.call(	this, 'Versalitas' );
};
OO.inheritClass( ve.ui.VersalitasCommand, ve.ui.Command );

ve.ui.VersalitasCommand.prototype.execute = function ( surface ) {
	var model = surface.getModel(),
		fragment = model.getFragment(),
		doc = model.getDocument(),
		range = fragment.getSelection().getRange();

	// Obtener el contenido seleccionado
	var selectedContent = doc.getData( range );
	
	// Crear el contenido para {{versal}}
	var versalStart = [
		{
			type: 'mwTransclusionInline',
			attributes: {
				mw: {
					parts: [{
						template: {
							target: {
								href: 'Template:Versal',
								wt: 'versal'
							},
							params: {}
						}
					}]
				}
			}
		},
		{
			type: '/mwTransclusionInline'
		}
	];

	// Crear el contenido para {{fin}}
	var versalEnd = [
		{
			type: 'mwTransclusionInline',
			attributes: {
				mw: {
					parts: [{
						template: {
							target: {
								href: 'Template:Fin',
								wt: 'fin'
							},
							params: {}
						}
					}]
				}
			}
		},
		{
			type: '/mwTransclusionInline'
		}
	];

	// Combinar todo: {{versal}} + contenido seleccionado + {{fin}}
	var newContent = versalStart.concat( selectedContent ).concat( versalEnd );

	// Reemplazar el contenido seleccionado
	fragment.insertContent( newContent );
};

ve.ui.commandRegistry.register( new ve.ui.VersalitasCommand() );

ve.ui.VersalitasTool = function VeUiVersalitasTool() {
	ve.ui.VersalitasTool.super.apply( this, arguments );
};
OO.inheritClass( ve.ui.VersalitasTool, ve.ui.Tool );
ve.ui.VersalitasTool.static.name = 'Versalitas';
ve.ui.VersalitasTool.static.group = 'textStyle';
ve.ui.VersalitasTool.static.icon = 'largerText';
ve.ui.VersalitasTool.static.title = 'Versalitas';
ve.ui.VersalitasTool.static.commandName = 'Versalitas';
ve.ui.toolFactory.register( ve.ui.VersalitasTool );