Vés al contingut

Usuari:Gerardduenas/vextris/toolbar.js

De la Viquipèdia, l'enciclopèdia lliure

Nota: Després de desar, heu de netejar la memòria cau del navegador per veure els canvis. En la majoria de navegadors amb Windows o Linux, premeu Ctrl+F5 o bé premeu Shift i cliqueu el botó "Actualitza" (Ctrl i "Actualitza" amb Internet Explorer). Vegeu més informació i instruccions per a cada navegador a Viquipèdia:Neteja de la memòria cau.

/*
Returns the specified button from config.tools
*/
function getButton(i){
	configButton = config.tools[i];
	buttons = {
		redireccionar: {
			group: 'edicio',
			label: 'Redireccionar!',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/Button_redirect.png',
			action: {
				type: 'callback',
				execute: function(context){
					var textArea = $('#wpTextbox1');
					var pag = prompt("A quina pàgina voleu redireccionar?");
					if (input === null) {
						return; //break out of the function early (do not write anything or select)
					}
					textArea.select();
					textArea.textSelection('encapsulateSelection', {pre: "#REDIRECT [["+pag+"]]<!--", post: "-->", replace: false});
				}
			}
		},
		comment: {
			group: 'edicio',
			label: 'Comentar text (ocultar)',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/3/3b/Comment-button-bg.png',
			action: {
				type: 'callback',
				execute: function(context){
					$('#wpTextbox1').textSelection('encapsulateSelection', {pre: "<!--", post: "-->", replace: false});
				}
			}
		},
		link: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/9/97/Button_int_link.png',
			action: {
				type: 'callback',
				execute: function(context){
					var textArea = $('#wpTextbox1');
					if ( textArea.textSelection( 'getSelection' ).length > 0 ){
						textArea.textSelection('encapsulateSelection', {pre: "[[", post: "]]", replace: false});
					} else {
						var title = prompt("Quin és el títol de la pàgina?")
						var desc = prompt("Descripció de l'enllaç (en blanc per mostrar el títol de la pàgina)")
						if ( desc.length <= 0 ) {
							textArea.textSelection('encapsulateSelection', {pre: "[["+title, post: "]]", replace: false});
						}else if (title === null || desc === null){
							return
						}else{
							textArea.textSelection('encapsulateSelection', {pre: "[["+title+"|"+desc, post: "]]", replace: false});
						}
					}
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		comment: {
			group: 'edicio',
			label: '',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/',
			action: {
				type: 'callback',
				execute: function(context){
				}
			}
		},
		error: {
			group:'articles',
			label: 'Error!',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Arbcom_ru_declined.svg/22px-Arbcom_ru_declined.svg.png',
			action: {
				type: 'callback',
				execute: function(context){alert("Això és un botó que substitueix una eina que no existeix");}
			}
		}
	};
	button = buttons[configButton];
	if ( button === undefined ){
		mw.notify("Una de les eines configurades de vextris no és vàlida, reviseu la configuració");
		button = buttons.error;
	}
	group = button['group'];
	delete button['group'];
	return [group, button];
}

function customTools(){
	var tools = {
		'edicio':{},
		'articles':{},
		'imatges':{},
		'vot':{},
		'avis':{}
	};
	for (i=0; i < config.tools.length; i++){
		var btn = getButton(i);
		var group = btn[0];
		tools[btn[0]][i] = btn[1];
	}
	return tools;
}

var customizeToolbar = function() {
	mw.loader.using('jquery.textSelection'); //it's loaded by default but just in case
	var tools = customTools();
	var vextrisToolbar = {
		'sections': {
			'vextris': {
				'type': 'toolbar',
				'label': 'Vextris',
				'groups': {
					'edicio': {
						'label': 'Edició',
						'tools': tools.edicio
					},
					'articles': {
						'label': 'Manteniment d\'articles',
						'tools': tools.articles
					},
					'imatges': {
						'label': 'Manteniment d\'imatges',
						'tools': tools.imatges
					},
					'vot': {
						'label': 'Eines de votacions',
						'tools': tools.vot
					},
					'avis': {
						'label': 'Avisos als usuaris',
						'tools': tools.avis
					}
				}
			}
		}
	};
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', vextrisToolbar );
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { //WikiEditor has to be enabled in user prefs (already enabled by default)
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}