MediaWiki:Gadget-EDTitle.js

Wikibooks, manuali e libri di testo liberi.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/** Rende il titolo editabile, in modo da usarlo come casella di ricerca **/
$(function() {
  if (typeof correctTitle != 'undefined'){
    correctTitle(); // Rendo compatibile con 'titolo errato'
    window.disableRealTitle = 1; // L'ho già eseguita, evito che venga eseguita di nuovo
  }
  if ((document.title.indexOf('Modifica ') == -1) &&
      (document.title.indexOf('Utente:Wim b/Filtra le ultime modifiche') == -1) &&
      (document.title.indexOf('Utente:Wim b/Tutte le ultime modifiche') == -1) &&
      (document.title.indexOf('Utente:Wim b/Ultime modifiche anonime') == -1) &&
      (document.title.indexOf('Utente:Wim b/Segui gli osservati speciali') == -1) &&
      (document.title.indexOf('Utente:Wim b/Controllo ortografico') == -1))
  {
    var $staticTitle = $('h1').first();
    var titleText = $staticTitle.text();
    titleText = titleText.replace(/\t/g,""); 
    var $editableTitle = $('<input type="text" />')
      .attr('id', 'editable-title')
      .css({
          width: '100%',
          fontSize: 'x-large',
          backgroundColor: 'transparent',
          borderStyle: 'none',
          borderBottomStyle: 'solid',
          borderBottomWidth: '1px'
      })
      .val(titleText)
      .change(function(){
        document.location.href = mw.config.get("wgServer") + '/wiki/' + $(this).val();
      })
      .focus(function(){
        $(this).css('backgroundColor', '#ddf');
      })
      .blur(function(){
        $(this).css('backgroundColor', 'transparent');
      })
      .keypress(function(evt){
        if (evt.which == 13)
          $(this).change();
      });

    $staticTitle.replaceWith($editableTitle);
  }
});