MediaWiki:Gadget-EDTitle.js
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 ( mw.config.get( 'wgAction' ) === 'edit' ) {
return;
}
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();
}
} );
if ( mw.config.get( 'skin' ) === "vector" ) {
// #firstHeading serve visibile a VisualEditor
// perciò il testo va racchiuso nello span per poter essere nascosto
$( '#firstHeading' )
.wrapInner( '<span>' );
// un .hide() non basta, riapparirebbe con VisualEditor
// #section-0 per l'id assegnato da QuickEdit
mw.util.addCSS(
'/** \n' +
' * aggiunto da it:w:MediaWiki:Gadget-EDTitle.js \n' +
' * per compatibilità con QuickEdit e VisualEditor \n' +
' **/ \n' +
'#firstHeading > span, #section-0 { \n' +
' display: none !important; \n' +
'} \n' +
'#firstHeading { \n' +
' border: none !important; \n' +
'}'
);
} else {
// un .hide() non basta, riapparirebbe con VisualEditor
// #section-0 per l'id assegnato da QuickEdit
mw.util.addCSS(
'/** \n' +
' * aggiunto da it:w:MediaWiki:Gadget-EDTitle.js \n' +
' * per compatibilità con QuicEdit e VisualEditor \n' +
' **/ \n' +
'#firstHeading > span, #section-0 { \n' +
' display: none !important; \n' +
'}'
);
}
$staticTitle
.after( $editableTitle );
} );