Usor:Alex brollo/Gadget-pulsanti-FI.js

E Wikisource

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* inserimento  template FI standard */
if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' && mw.config.get("wgCanonicalNamespace")==="Page") {$( function() {
    var nomeBase, numeroPagina, nomeImmagine, fi;
    nomeBase=mw.config.get("wgTitle").match(/(.+)\./)[1].replace("Pagina:","");
    numeroPagina=mw.config.get("wgTitle").match(/\/(\d+)$/)[1];
    nomeImmagine=nomeBase+" (page #1 crop).jpg".replace("#1",numeroPagina);
    fi="{{FI\n|file = #1\n| width = 400px\n| float = floating-center\n| caption = \n}}".replace("#1",nomeImmagine);
    // console.log(nomeImmagine);
    
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'advanced',
      'group': 'insert',
      'tools': {'FI': {
          label: 'Inserisci template FI',
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/6/68/Pulsante_img.png',
          action: {type: 'callback',
            execute: function() {
            	/* nomeBase=mw.config.get("wgTitle").match(/(.+)\./)[1];
    			numeroPagina=mw.config.get("wgTitle").match(/\/(\d+)$/)[1];
    			nomeImmagine=nomeBase+" (page #1 crop).jpg".replace("#1",numeroPagina);*/
    			fi="{{FI\n|file = #1\n| width = 400px\n| float = floating-center\n| caption = \n}}".replace("#1",nomeImmagine);
				// console.log("Nuova versione gadget FI");
				//mw.toolbar.insertTags(fi,"");
				$(mw.activeElement).textSelection( 'encapsulateSelection', { pre: fi, post: '' } );
            	} 
          }
       }
}});});}