X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fmediawiki.special%2Fmediawiki.special.upload.js;h=f7a4b1f76e3312b38e4e727aacb35b0727b0b973;hb=fcd74e5dd3299926be0a41b55e2ed24424568948;hp=3fc9481a4cb09cebecbc06e4dab19d055d4fda57;hpb=b085bb81d455227d335150ce963d7ba4a58152fb;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/mediawiki.special/mediawiki.special.upload.js b/resources/mediawiki.special/mediawiki.special.upload.js index 3fc9481a4c..f7a4b1f76e 100644 --- a/resources/mediawiki.special/mediawiki.special.upload.js +++ b/resources/mediawiki.special/mediawiki.special.upload.js @@ -46,20 +46,15 @@ jQuery( function( $ ) { var previewSize = 180, thumb = $( '
' + '
' + - '' + + '
' + '
' + '
' + '
' ); thumb.find( '.filename' ).text( file.name ).end() .find( '.fileinfo' ).text( prettySize( file.size ) ).end(); - var ctx = thumb.find( 'canvas' )[0].getContext( '2d' ), - spinner = new Image(); - spinner.onload = function() { - ctx.drawImage( spinner, (previewSize - spinner.width) / 2, - (previewSize - spinner.height) / 2 ); - }; - spinner.src = mw.config.get( 'wgScriptPath' ) + '/skins/common/images/spinner.gif'; + var $canvas = $(''), + ctx = $canvas[0].getContext( '2d' ); $( '#mw-htmlform-source' ).parent().prepend( thumb ); var meta; @@ -131,6 +126,7 @@ jQuery( function( $ ) { 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); // Image size var info = mw.msg( 'widthheight', logicalWidth, logicalHeight ) + @@ -160,17 +156,33 @@ jQuery( function( $ ) { */ function fetchPreview( file, callback, callbackBinary ) { var reader = new FileReader(); - if ( callbackBinary ) { + if ( callbackBinary && 'readAsBinaryString' in reader ) { // To fetch JPEG metadata we need a binary string; start there. // todo: reader.onload = function() { callbackBinary( reader.result ); // Now run back through the regular code path. - fetchPreview(file, callback ); + fetchPreview( file, callback ); }; reader.readAsBinaryString( file ); - } else if ('URL' in window && 'createObjectURL' in window.URL) { + } else if ( callbackBinary && 'readAsArrayBuffer' in reader ) { + // readAsArrayBuffer replaces readAsBinaryString + // However, our JPEG metadata library wants a string. + // So, this is going to be an ugly conversion. + reader.onload = function() { + var buffer = new Uint8Array( reader.result ), + string = ''; + for ( var i = 0; i < buffer.byteLength; i++ ) { + string += String.fromCharCode( buffer[i] ); + } + callbackBinary( string ); + + // Now run back through the regular code path. + fetchPreview( file, callback ); + }; + reader.readAsArrayBuffer( file ); + } else if ( 'URL' in window && 'createObjectURL' in window.URL ) { // Supported in Firefox 4.0 and above // WebKit has it in a namespace for now but that's ok. ;) // @@ -180,7 +192,7 @@ jQuery( function( $ ) { // // Prefer this over readAsDataURL for Firefox 7 due to bug reading // some SVG files from data URIs - callback(window.URL.createObjectURL(file)); + callback( window.URL.createObjectURL( file ) ); } else { // This ends up decoding the file to base-64 and back again, which // feels horribly inefficient.