r79868 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79867‎ | r79868 | r79869 >
Date:16:43, 8 January 2011
Author:krinkle
Status:ok
Tags:
Comment:
Clean up mediawiki.special.upload.js
* (Whitespace) conventions [[Manual:Coding conventions]]
* Single quotes where possible
* Removing useless parens in some cases
* Missing semicolons (JSLint)
(Kindafollowupon r79867)
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.colorUtil.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.colorUtil.js
@@ -19,7 +19,7 @@
2020 // Check if we're already dealing with an array of colors
2121 if ( color && color.constructor == Array && color.length == 3 ){
2222 return color;
23 - }
 23+ }
2424
2525 // Look for rgb(num,num,num)
2626 if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) {
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js
@@ -3,12 +3,12 @@
44 * Note that additional code still lives in skins/common/upload.js
55 */
66
7 -$(function() {
 7+$( function() {
88 /**
99 * Is the FileAPI available with sufficient functionality?
1010 */
11 - function hasFileAPI() {
12 - return (typeof window.FileReader != "undefined");
 11+ function hasFileAPI(){
 12+ return typeof window.FileReader !== 'undefined';
1313 }
1414
1515 /**
@@ -20,10 +20,10 @@
2121 * @param {File} file
2222 * @return boolean
2323 */
24 - function fileIsPreviewable(file) {
 24+ function fileIsPreviewable( file ) {
2525 var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'];
2626 var tooHuge = 10 * 1024 * 1024;
27 - return ($.inArray(file.type, known) != -1) && (file.size > 0) && (file.size < tooHuge);
 27+ return ($.inArray( file.type, known ) !== -1) && file.size > 0 && file.size < tooHuge;
2828 }
2929
3030 /**
@@ -38,28 +38,28 @@
3939 *
4040 * @param {File} file
4141 */
42 - function showPreview(file) {
 42+ function showPreview( file ) {
4343 var previewSize = 180;
4444
45 - var thumb = $("<div id='mw-upload-thumbnail' class='thumb tright'>" +
46 - "<div class='thumbinner'>" +
47 - "<canvas width=" + previewSize + " height=" + previewSize + " ></canvas>" +
48 - "<div class='thumbcaption'><div class='filename'></div><div class='fileinfo'></div></div>" +
49 - "</div>" +
50 - "</div>");
51 - thumb.find('.filename').text(file.name).end()
52 - .find('.fileinfo').text(prettySize(file.size)).end();
 45+ var thumb = $( '<div id="mw-upload-thumbnail" class="thumb tright">' +
 46+ '<div class="thumbinner">' +
 47+ '<canvas width="' + previewSize + '" height="' + previewSize + '" ></canvas>' +
 48+ '<div class="thumbcaption"><div class="filename"></div><div class="fileinfo"></div></div>' +
 49+ '</div>' +
 50+ '</div>' );
 51+ thumb.find( '.filename' ).text( file.name ).end()
 52+ .find( '.fileinfo' ).text( prettySize( file.size ) ).end();
5353
54 - var ctx = thumb.find('canvas')[0].getContext('2d');
 54+ var ctx = thumb.find( 'canvas' )[0].getContext( '2d' );
5555 var spinner = new Image();
56 - spinner.onload = function () {
 56+ spinner.onload = function() {
5757 ctx.drawImage( spinner, (previewSize - spinner.width) / 2,
5858 (previewSize - spinner.height) / 2 );
5959 };
6060 spinner.src = wgScriptPath + '/skins/common/images/spinner.gif';
61 - $('#mw-htmlform-source').parent().prepend(thumb);
 61+ $( '#mw-htmlform-source' ).parent().prepend( thumb );
6262
63 - fetchPreview(file, function(dataURL) {
 63+ fetchPreview( file, function( dataURL ) {
6464 var img = new Image();
6565 var rotation = 0;
6666 img.onload = function() {
@@ -74,7 +74,7 @@
7575 // Determine the offset required to center the image
7676 dx = (180 - width) / 2;
7777 dy = (180 - height) / 2;
78 - switch (rotation) {
 78+ switch ( rotation ) {
7979 // If a rotation is applied, the direction of the axis
8080 // changes as well. You can derive the values below by
8181 // drawing on paper an axis system, rotate it and see
@@ -102,10 +102,10 @@
103103 ctx.drawImage( img, x, y, width, height );
104104
105105 // Image size
106 - var info = mediaWiki.msg('widthheight', img.width, img.height) +
107 - ', ' + prettySize(file.size);
108 - $('#mw-upload-thumbnail .fileinfo').text(info);
109 - }
 106+ var info = mw.msg( 'widthheight', img.width, img.height ) +
 107+ ', ' + prettySize( file.size );
 108+ $( '#mw-upload-thumbnail .fileinfo' ).text( info );
 109+ };
110110 img.src = dataURL;
111111 });
112112 }
@@ -117,12 +117,12 @@
118118 * @param {File} file
119119 * @param {function} callback
120120 */
121 - function fetchPreview(file, callback) {
 121+ function fetchPreview( file, callback ) {
122122 var reader = new FileReader();
123123 reader.onload = function() {
124 - callback(reader.result);
 124+ callback( reader.result );
125125 };
126 - reader.readAsDataURL(file);
 126+ reader.readAsDataURL( file );
127127 }
128128
129129 /**
@@ -132,32 +132,32 @@
133133 * @param {number} s
134134 * @return string
135135 */
136 - function prettySize(s) {
 136+ function prettySize( s ) {
137137 var sizes = ['size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes'];
138 - while (s >= 1024 && sizes.length > 1) {
 138+ while ( s >= 1024 && sizes.length > 1 ) {
139139 s /= 1024;
140 - sizes = sizes.slice(1);
 140+ sizes = sizes.slice( 1 );
141141 }
142 - return mediaWiki.msg(sizes[0], Math.round(s))
 142+ return mw.msg( sizes[0], Math.round( s ) );
143143 }
144144
145145 /**
146146 * Clear the file upload preview area.
147147 */
148148 function clearPreview() {
149 - $('#mw-upload-thumbnail').remove();
 149+ $( '#mw-upload-thumbnail' ).remove();
150150 }
151151
152152
153 - if (hasFileAPI()) {
 153+ if ( hasFileAPI() ) {
154154 // Update thumbnail when the file selection control is updated.
155 - $('#wpUploadFile').change(function() {
 155+ $( '#wpUploadFile' ).change( function() {
156156 clearPreview();
157 - if (this.files && this.files.length) {
 157+ if ( this.files && this.files.length ) {
158158 // Note: would need to be updated to handle multiple files.
159159 var file = this.files[0];
160 - if (fileIsPreviewable(file)) {
161 - showPreview(file);
 160+ if ( fileIsPreviewable( file ) ) {
 161+ showPreview( file );
162162 }
163163 }
164164 });

Follow-up revisions

RevisionCommit summaryAuthorDate
r79869Follow-up r79868krinkle17:14, 8 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79867Follow-up r79845: Add rotation support to the upload preview using the <canva...btongminh16:24, 8 January 2011

Status & tagging log