MediaWiki:Gadget-formattapassi.js
Vai alla navigazione
Vai alla ricerca
Nota: Dopo aver salvato le preferenze, perché i cambi abbiano effetto, devi bypassare la cache del tuo browser. Mozilla / Firefox / Safari: tieni premuto Shift mentre clicchi Reload, o premi Ctrl-Shift-R (Cmd-Shift-R per Apple Mac); Google Chrome: premi Ctrl o Shift mentre clicchi F5; IE: premi Ctrl mentre clicchi Refresh, o premi Ctrl-F5; Konqueror:: clicca semplicemente il pulsante di Reload, o premi F5; se usi Opera devi cancellare completamente la chache nel menu Tools→Preferences.
/** * Gadget-strumentivari.js */ /*global mediaWiki, jQuery */ ( function ( mw, $ ) { 'use strict'; // Gestore del click su "Formatta" function formatHandler() { $( '#wpTextbox1' ).val( $( '#wpTextbox1' ).val() .replace( /\’/g, "'" ) .replace( / '([\w\ ]+)' /g, ' "$1" ' ) .replace( /“/g, '"' ) .replace( /”/g, '"' ); $( '#wpSummary' ).val( $( '#wpSummary' ).val() + '+formattazione ' ); $( '#wpMinoredit' ).prop( 'checked', true ); } // Gestore del click su "sostituisci" function replaceHandler() { var $find, $replace, $div = $( '<div>' ); $( '<label>' ).text( 'Cerca:' ).appendTo( $div ); $find = $( '<input/>' ).attr( 'type', 'text' ).attr( 'size', 50 ).appendTo( $div ); $( '<label>' ).text( 'Sostituisci con:' ).appendTo( $div ); $replace = $( '<input/>' ).attr( 'type', 'text' ).attr( 'size', 50 ).appendTo( $div ); $div.find( 'label, input' ).css( 'display', 'block' ); $( '#gsv-dialog' ).html( $div ).dialog( { title: 'Strumenti vari - sostituisci', width: 400, modal: true, buttons: { 'Sostituisci': function () { if ( $find.val() !== '' ) { $( '#wpTextbox1' ).val( $( '#wpTextbox1' ).val() .replace( new RegExp( $find.val(), 'g' ), $replace.val() ) ); } $( this ).dialog( 'close' ); }, 'Annulla': function () { $( this ).dialog( 'close' ); } } } ); } $( function () { var portletLink, $format, $replace, $span; if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) { // setup tab $format = $( '<a>' ).attr( 'href', '#' ).text( 'Form' ); $format.click( function ( event ) { event.preventDefault(); formatHandler(); } ); $replace = $( '<a>' ).attr( 'href', '#' ).text( 'Sost' ); $replace.click( function ( event ) { event.preventDefault(); mw.loader.using( ['jquery.ui.dialog'], function () { replaceHandler(); } ); } ); $span = $( '<span>' ).css( 'white-space', 'nowrap' ).append( $format, '<small>e</small>', $replace ); portletLink = mw.util.addPortletLink( 'p-cactions', '#', '' ); $( portletLink ).find( 'a' ).replaceWith( $span ); // setup dialog $( '<div>' ).attr( 'id', 'gsv-dialog' ).appendTo( 'body' ); } } ); }( mediaWiki, jQuery ) );