summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.special/mediawiki.special.upload.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/src/mediawiki.special/mediawiki.special.upload.js')
-rw-r--r--resources/src/mediawiki.special/mediawiki.special.upload.js79
1 files changed, 42 insertions, 37 deletions
diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js b/resources/src/mediawiki.special/mediawiki.special.upload.js
index eeccda59..677d26d7 100644
--- a/resources/src/mediawiki.special/mediawiki.special.upload.js
+++ b/resources/src/mediawiki.special/mediawiki.special.upload.js
@@ -6,6 +6,7 @@
* @singleton
*/
( function ( mw, $ ) {
+ /*jshint latedef:false */
var uploadWarning, uploadLicense,
ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
$license = $( '#wpLicense' );
@@ -35,7 +36,7 @@
}
// Check response cache
if ( this.responseCache.hasOwnProperty( this.nameToCheck ) ) {
- this.setWarning( this.responseCache[this.nameToCheck] );
+ this.setWarning( this.responseCache[ this.nameToCheck ] );
return;
}
@@ -71,7 +72,7 @@
} ).done( function ( result ) {
var resultOut = '';
if ( result.query ) {
- resultOut = result.query.pages[result.query.pageids[0]].imageinfo[0];
+ resultOut = result.query.pages[ result.query.pageids[ 0 ] ].imageinfo[ 0 ];
}
$spinnerDestCheck.remove();
uploadWarning.processResult( resultOut, uploadWarning.nameToCheck );
@@ -80,7 +81,7 @@
processResult: function ( result, fileName ) {
this.setWarning( result.html );
- this.responseCache[fileName] = result.html;
+ this.responseCache[ fileName ] = result.html;
},
setWarning: function ( warning ) {
@@ -107,7 +108,7 @@
return;
}
if ( this.responseCache.hasOwnProperty( license ) ) {
- this.showPreview( this.responseCache[license] );
+ this.showPreview( this.responseCache[ license ] );
return;
}
@@ -126,8 +127,8 @@
},
processResult: function ( result, license ) {
- this.responseCache[license] = result.parse.text['*'];
- this.showPreview( this.responseCache[license] );
+ this.responseCache[ license ] = result.parse.text[ '*' ];
+ this.showPreview( this.responseCache[ license ] );
},
showPreview: function ( preview ) {
@@ -228,7 +229,7 @@
fname = fname.replace( / /g, '_' );
// Capitalise first letter if needed
if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
- fname = fname.charAt( 0 ).toUpperCase().concat( fname.slice( 1 ) );
+ fname = fname[ 0 ].toUpperCase() + fname.slice( 1 );
}
// Output result
@@ -265,15 +266,32 @@
* TODO: Put SVG back after working around Firefox 7 bug <https://bugzilla.wikimedia.org/show_bug.cgi?id=31643>
*
* @param {File} file
- * @return boolean
+ * @return {boolean}
*/
function fileIsPreviewable( file ) {
- var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'],
+ var known = [ 'image/png', 'image/gif', 'image/jpeg', 'image/svg+xml' ],
tooHuge = 10 * 1024 * 1024;
return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge;
}
/**
+ * Format a file size attractively.
+ *
+ * TODO: Match numeric formatting
+ *
+ * @param {number} s
+ * @return {string}
+ */
+ function prettySize( s ) {
+ var sizeMsgs = [ 'size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes' ];
+ while ( s >= 1024 && sizeMsgs.length > 1 ) {
+ s /= 1024;
+ sizeMsgs = sizeMsgs.slice( 1 );
+ }
+ return mw.msg( sizeMsgs[ 0 ], Math.round( s ) );
+ }
+
+ /**
* Show a thumbnail preview of PNG, JPEG, GIF, and SVG files prior to upload
* in browsers supporting HTML5 FileAPI.
*
@@ -291,13 +309,17 @@
ctx,
meta,
previewSize = 180,
+ $spinner = $.createSpinner( { size: 'small', type: 'block' } )
+ .css( { width: previewSize, height: previewSize } ),
thumb = mw.template.get( 'mediawiki.special.upload', 'thumbnail.html' ).render();
- thumb.find( '.filename' ).text( file.name ).end()
- .find( '.fileinfo' ).text( prettySize( file.size ) ).end();
+ thumb
+ .find( '.filename' ).text( file.name ).end()
+ .find( '.fileinfo' ).text( prettySize( file.size ) ).end()
+ .find( '.thumbinner' ).prepend( $spinner ).end();
- $canvas = $( '<canvas width="' + previewSize + '" height="' + previewSize + '" ></canvas>' );
- ctx = $canvas[0].getContext( '2d' );
+ $canvas = $( '<canvas>' ).attr( { width: previewSize, height: previewSize } );
+ ctx = $canvas[ 0 ].getContext( '2d' );
$( '#mw-htmlform-source' ).parent().prepend( thumb );
fetchPreview( file, function ( dataURL ) {
@@ -369,7 +391,7 @@
ctx.clearRect( 0, 0, 180, 180 );
ctx.rotate( rotation / 180 * Math.PI );
ctx.drawImage( img, x, y, width, height );
- thumb.find( '.mw-small-spinner' ).replaceWith( $canvas );
+ $spinner.replaceWith( $canvas );
// Image size
info = mw.msg( 'widthheight', logicalWidth, logicalHeight ) +
@@ -421,7 +443,7 @@
buffer = new Uint8Array( reader.result ),
string = '';
for ( i = 0; i < buffer.byteLength; i++ ) {
- string += String.fromCharCode( buffer[i] );
+ string += String.fromCharCode( buffer[ i ] );
}
callbackBinary( string );
@@ -451,23 +473,6 @@
}
/**
- * Format a file size attractively.
- *
- * TODO: Match numeric formatting
- *
- * @param {number} s
- * @return {string}
- */
- function prettySize( s ) {
- var sizeMsgs = ['size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes'];
- while ( s >= 1024 && sizeMsgs.length > 1 ) {
- s /= 1024;
- sizeMsgs = sizeMsgs.slice( 1 );
- }
- return mw.msg( sizeMsgs[0], Math.round( s ) );
- }
-
- /**
* Clear the file upload preview area.
*/
function clearPreview() {
@@ -483,10 +488,10 @@
function getMaxUploadSize( type ) {
var sizes = mw.config.get( 'wgMaxUploadSize' );
- if ( sizes[type] !== undefined ) {
- return sizes[type];
+ if ( sizes[ type ] !== undefined ) {
+ return sizes[ type ];
}
- return sizes['*'];
+ return sizes[ '*' ];
}
$( '.mw-upload-source-error' ).remove();
@@ -511,7 +516,7 @@
clearPreview();
if ( this.files && this.files.length ) {
// Note: would need to be updated to handle multiple files.
- var file = this.files[0];
+ var file = this.files[ 0 ];
if ( !checkMaxUploadSize( file ) ) {
return;
@@ -578,7 +583,7 @@
} );
$uploadForm.submit( function () {
- allowCloseWindow();
+ allowCloseWindow.release();
} );
} );
}( mediaWiki, jQuery ) );