Clean up mediawiki.special.upload.js
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 8 Jan 2011 16:43:25 +0000 (16:43 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 8 Jan 2011 16:43:25 +0000 (16:43 +0000)
* (Whitespace) conventions [[Manual:Coding conventions]]
* Single quotes where possible
* Removing useless parens in some cases
* Missing semicolons (JSLint)
(Kindafollowupon r79867)

resources/jquery/jquery.colorUtil.js
resources/mediawiki.special/mediawiki.special.upload.js

index d1a9c5d..39c4fc2 100644 (file)
@@ -19,7 +19,7 @@
                        // Check if we're already dealing with an array of colors
                        if ( color && color.constructor == Array && color.length == 3 ){
                                return color;
-                                }
+                       }
 
                        // Look for rgb(num,num,num)
                        if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) {
index 163dbbf..fe538ad 100644 (file)
@@ -3,12 +3,12 @@
  * Note that additional code still lives in skins/common/upload.js
  */
 
-$(function() {
+$( function() {
        /**
         * Is the FileAPI available with sufficient functionality?
         */
-       function hasFileAPI() {
-               return (typeof window.FileReader != "undefined");
+       function hasFileAPI(){
+               return typeof window.FileReader !== 'undefined';
        }
 
        /**
@@ -20,10 +20,10 @@ $(function() {
         * @param {File} file
         * @return boolean
         */
-       function fileIsPreviewable(file) {
+       function fileIsPreviewable( file ) {
                var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'];
                var tooHuge = 10 * 1024 * 1024;
-               return ($.inArray(file.type, known) != -1) && (file.size > 0) && (file.size < tooHuge);
+               return ($.inArray( file.type, known ) !== -1) && file.size > 0 && file.size < tooHuge;
        }
 
        /**
@@ -38,28 +38,28 @@ $(function() {
         *
         * @param {File} file
         */
-       function showPreview(file) {
+       function showPreview( file ) {
                var previewSize = 180;
                
-               var thumb = $("<div id='mw-upload-thumbnail' class='thumb tright'>" +
-                                           "<div class='thumbinner'>" +
-                                             "<canvas width=" + previewSize + " height=" + previewSize + " ></canvas>" +
-                                             "<div class='thumbcaption'><div class='filename'></div><div class='fileinfo'></div></div>" +
-                                           "</div>" +
-                                         "</div>");
-               thumb.find('.filename').text(file.name).end()
-                    .find('.fileinfo').text(prettySize(file.size)).end();
+               var thumb = $( '<div id="mw-upload-thumbnail" class="thumb tright">' +
+                                               '<div class="thumbinner">' +
+                                                       '<canvas width="' + previewSize + '" height="' + previewSize + '" ></canvas>' +
+                                                       '<div class="thumbcaption"><div class="filename"></div><div class="fileinfo"></div></div>' +
+                                               '</div>' +
+                                       '</div>' );
+               thumb.find( '.filename' ).text( file.name ).end()
+                       .find( '.fileinfo' ).text( prettySize( file.size ) ).end();
                
-               var ctx = thumb.find('canvas')[0].getContext('2d');
+               var ctx = thumb.find( 'canvas' )[0].getContext( '2d' );
                var spinner = new Image();
-               spinner.onload = function () { 
+               spinner.onload = function() { 
                        ctx.drawImage( spinner, (previewSize - spinner.width) / 2, 
                                        (previewSize - spinner.height) / 2 ); 
                };
                spinner.src = wgScriptPath + '/skins/common/images/spinner.gif';
-               $('#mw-htmlform-source').parent().prepend(thumb);
+               $( '#mw-htmlform-source' ).parent().prepend( thumb );
 
-               fetchPreview(file, function(dataURL) {  
+               fetchPreview( file, function( dataURL ) {       
                        var img = new Image();
                        var rotation = 0;
                        img.onload = function() {
@@ -74,7 +74,7 @@ $(function() {
                                // Determine the offset required to center the image
                                dx = (180 - width) / 2;
                                dy = (180 - height) / 2;
-                               switch (rotation) {
+                               switch ( rotation ) {
                                        // If a rotation is applied, the direction of the axis
                                        // changes as well. You can derive the values below by 
                                        // drawing on paper an axis system, rotate it and see
@@ -102,10 +102,10 @@ $(function() {
                                ctx.drawImage( img, x, y, width, height );
                                
                                // Image size
-                               var info = mediaWiki.msg('widthheight', img.width, img.height) +
-                                       ', ' + prettySize(file.size);
-                               $('#mw-upload-thumbnail .fileinfo').text(info);
-                       }
+                               var info = mw.msg( 'widthheight', img.width, img.height ) +
+                                       ', ' + prettySize( file.size );
+                               $( '#mw-upload-thumbnail .fileinfo' ).text( info );
+                       };
                        img.src = dataURL;
                });
        }
@@ -117,12 +117,12 @@ $(function() {
         * @param {File} file
         * @param {function} callback
         */
-       function fetchPreview(file, callback) {
+       function fetchPreview( file, callback ) {
                var reader = new FileReader();
                reader.onload = function() {
-                       callback(reader.result);
+                       callback( reader.result );
                };
-               reader.readAsDataURL(file);
+               reader.readAsDataURL( file );
        }
 
        /**
@@ -132,32 +132,32 @@ $(function() {
         * @param {number} s
         * @return string
         */
-       function prettySize(s) {
+       function prettySize( s ) {
                var sizes = ['size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes'];
-               while (s >= 1024 && sizes.length > 1) {
+               while ( s >= 1024 && sizes.length > 1 ) {
                        s /= 1024;
-                       sizes = sizes.slice(1);
+                       sizes = sizes.slice( 1 );
                }
-               return mediaWiki.msg(sizes[0], Math.round(s))
+               return mw.msg( sizes[0], Math.round( s ) );
        }
 
        /**
         * Clear the file upload preview area.
         */
        function clearPreview() {
-               $('#mw-upload-thumbnail').remove();
+               $( '#mw-upload-thumbnail' ).remove();
        }
        
 
-       if (hasFileAPI()) {
+       if ( hasFileAPI() ) {
                // Update thumbnail when the file selection control is updated.
-               $('#wpUploadFile').change(function() {
+               $( '#wpUploadFile' ).change( function() {
                        clearPreview();
-                       if (this.files && this.files.length) {
+                       if ( this.files && this.files.length ) {
                                // Note: would need to be updated to handle multiple files.
                                var file = this.files[0];
-                               if (fileIsPreviewable(file)) {
-                                       showPreview(file);
+                               if ( fileIsPreviewable( file ) ) {
+                                       showPreview( file );
                                }
                        }
                });