„MediaWiki:Gadget-uploadtools.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
K updateTooltipAccessKeys ist deprecated, ersetzt - Leerzeichen und Zeilumbrüche zur besseren Lesbarkeit gesetzt - https://de.wikipedia.org/?oldid=138553538#updateTooltipAccessKeys_in_MediaWiki:Onlyifuploading.js |
K Vermeide doppelten accesskey - https://de.wikipedia.org/w/index.php?title=Wikipedia:Technik/Werkstatt&oldid=138572868#updateTooltipAccessKeys_in_MediaWiki:Onlyifuploading.js |
||
Zeile 51: | Zeile 51: | ||
}); //getJSON |
}); //getJSON |
||
})); //click |
})); //click |
||
$( '# |
$( '#t-print a' ).removeAttr( 'accesskey' ); // T58786 |
||
$( '#t-print a, #wpPreview' ).updateTooltipAccessKeys(); |
|||
});}); //ready |
});}); //ready |
||
//</nowiki> |
//</nowiki> |
Version vom 7. Februar 2015, 11:29 Uhr
/**
* Ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]]
* siehe auch [[phab:T4537]]
* wird in [[MediaWiki:Common.js]] eingebunden
* Code von [[Benutzer:Schnark]]
* <nowiki>
*/
mw.loader.using( [ 'mediawiki.util', 'jquery.accessKeyLabel' ], function() { $( function() {
var $editbox = $( '#wpUploadDescription' );
if ( $editbox.length !== 1 ) {
return; // exits silently if not exactly one #wpUploadDescription is found
}
var parseAsSummary; // Fallunterscheidung für Vorschaufunktion
if ( mw.util.getParamValue( 'wpForReUpload' ) !== '1' ) { // Kein Upload von neuer Dateiversion?
parseAsSummary = false; // bei Upload der ersten Dateiversion wird eingegebener Text auf der Seite erscheinen
} else {
parseAsSummary = true; // bei Upload von neuer Dateiversion wird eingegebener Text nur im Log erscheinen
}
if ( !mw.config.get( 'wgEnableAPI' ) ) {
return;
}
var previewText = 'Vorschau';
if ( $( '#mw-description-preview' ).length === 0 ) {
$( '#mw-htmlform-description' ).before( $( mw.html.element( 'div', { id: 'mw-description-preview' } ) ) );
}
$( 'input[name="wpUpload"]' ).after( $( mw.html.element( 'input', {
value: previewText,
type: 'button',
id: 'wpPreview',
title: previewText,
accesskey: 'p'
})).click( function() {
if ( typeof wikEd !== 'undefined' && wikEd.useWikEd ) { // if WikEd is active
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
}
var param = {action: 'parse',
title: 'Datei:' + ( $( '#wpDestFile' ).val() || 'Beispiel.jpg' ), //Titel, Datei:Beispiel.jpg als Standard
prop: 'text',
pst: '',
text: '', //text wird benötigt, wenn title angegeben (bug 48319), wird eventuell überschrieben
format: 'json'};
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen
$.getJSON( mw.util.wikiScript( 'api' ), param, function ( json ) {
var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text
if ( !json || !json.parse || !json.parse[content] || !json.parse[content]['*'] ) {
return;
}
var html = '<p><strong>' + previewText + ':</strong></p><div>' + json.parse[content]['*'] + '</div>';
$( '#mw-description-preview' ).html( html );
}); //getJSON
})); //click
$( '#t-print a' ).removeAttr( 'accesskey' ); // T58786
$( '#t-print a, #wpPreview' ).updateTooltipAccessKeys();
});}); //ready
//</nowiki>