r92189 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92188‎ | r92189 | r92190 >
Date:20:29, 14 July 2011
Author:hashar
Status:deferred
Tags:
Comment:
fixed some glitched using jslint
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Cursor.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Document.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.TextFlow.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.js (modified) (history)
  • /trunk/parsers/wikidom/lib/wiki.AnnotationRenderer.js (modified) (history)
  • /trunk/parsers/wikidom/lib/wiki.util.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Document.js
@@ -5,7 +5,8 @@
66 */
77 function Document( blocks ) {
88 this.blocks = [];
9 - for( var i = 0; i < blocks.length; i++ ) {
 9+ var i;
 10+ for( i = 0; i < blocks.length; i++ ) {
1011 this.appendBlock(blocks[i]);
1112 }
1213 this.width = null;
@@ -77,7 +78,7 @@
7879 } else {
7980 this.blocks.push( block );
8081 }
81 -}
 82+};
8283
8384 /**
8485 * Removes a block from the document.
@@ -93,7 +94,8 @@
9495 // Remember width, to avoid updates when without width changes
9596 this.width = this.$.innerWidth();
9697 // Render blocks
97 - for ( var i = 0; i < this.blocks.length; i++ ) {
 98+ var i;
 99+ for ( i = 0; i < this.blocks.length; i++ ) {
98100 this.$.append( this.blocks[i].$ );
99101 this.blocks[i].renderContent( offset, callback );
100102 }
Index: trunk/parsers/wikidom/lib/es/es.js
@@ -21,6 +21,8 @@
2222 */
2323 function extend( dst, src ) {
2424 var base = new src();
 25+ var i; // iterator
 26+
2527 for ( i in base ) {
2628 if ( typeof base[i] === 'function' && !( i in dst.prototype ) ) {
2729 dst.prototype[i] = base[i];
@@ -94,7 +96,7 @@
9597 Selection.prototype.through = function() {
9698 var through = [];
9799 if ( this.from !== this.to && this.from.nextBlock() !== this.to ) {
98 - var next = this.from.nextBlock()
 100+ var next = this.from.nextBlock();
99101 while ( next && next !== this.to ) {
100102 through.push( next );
101103 next = next.nextBlock();
@@ -112,10 +114,10 @@
113115 if ( typeof data === 'string' ) {
114116 this.type = 'string';
115117 } else if ( $.isArray( data ) ) {
116 -
 118+ // TODO
117119 } else if ( $.isPlainObject( data ) ) {
118120 if ( 'type' in data && '' ) {
119 -
 121+ // TODO
120122 }
121123 }
122124 this.data = data;
Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -89,8 +89,8 @@
9090 $block = $(this);
9191 } );
9292 }
93 - var block = $block.data( 'block' )
94 - blockPosition = $block.offset()
 93+ var block = $block.data( 'block' ),
 94+ blockPosition = $block.offset(),
9595 mousePosition = new Position( e.pageX - blockPosition.left, e.pageY - blockPosition.top );
9696 return new Location( block, block.getOffset( mousePosition ) );
9797 };
@@ -176,7 +176,7 @@
177177 break;
178178 }
179179 return true;
180 -}
 180+};
181181
182182 Surface.prototype.onKeyUp = function( e ) {
183183 switch ( e.keyCode ) {
@@ -197,7 +197,7 @@
198198 break;
199199 }
200200 return true;
201 -}
 201+};
202202
203203 Surface.prototype.handleBackspace = function() {
204204 var block = this.location.block,
@@ -211,7 +211,7 @@
212212 this.selection = new Selection();
213213 this.drawSelection();
214214 this.location = new Location( block, offset );
215 -}
 215+};
216216
217217 Surface.prototype.handleDelete = function() {
218218 var block = this.location.block,
@@ -265,6 +265,8 @@
266266 * Displays current selection behind document content.
267267 */
268268 Surface.prototype.drawSelection = function() {
 269+ var blockWidth;
 270+
269271 if ( this.selection.from && this.selection.to ) {
270272 this.selection.normalize();
271273 var from = {
@@ -297,7 +299,7 @@
298300 this.$rangeEnd.hide();
299301 } else {
300302 // Multiple line selection
301 - var blockWidth = block.$.width();
 303+ blockWidth = block.$.width();
302304 this.$rangeStart
303305 .css( {
304306 'top': blockOffset.top + from.position.top,
@@ -329,11 +331,11 @@
330332 }
331333 } else {
332334 // Multiple block selection
333 - var blockWidth = Math.max(
 335+ blockWidth = Math.max(
334336 from.location.block.$.width(),
335337 to.location.block.$.width()
336 - )
337 - fromBlockOffset = from.location.block.$.offset(),
 338+ );
 339+ var fromBlockOffset = from.location.block.$.offset(),
338340 toBlockOffset = to.location.block.$.offset(),
339341 blockLeft = Math.min( fromBlockOffset.left, toBlockOffset.left );
340342 this.$rangeStart
@@ -526,6 +528,9 @@
527529 * @param selection {Selection} Range to apply annotation to
528530 */
529531 Surface.prototype.annotateContent= function( method, annotation, selection ) {
 532+ var block;
 533+ var i;
 534+
530535 if ( selection === undefined ) {
531536 selection = this.selection;
532537 }
@@ -542,8 +547,8 @@
543548 } );
544549 } else {
545550 // Multiple block annotation
546 - for ( var i = from.block.getIndex(), end = to.block.getIndex(); i <= end; i++ ) {
547 - var block = this.doc.blocks[i];
 551+ for ( i = from.block.getIndex(), end = to.block.getIndex(); i <= end; i++ ) {
 552+ block = this.doc.blocks[i];
548553 if ( block === from.block ) {
549554 // From offset to length
550555 block.annotateContent( method, annotation, from.offset, block.getLength() );
Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -83,7 +83,8 @@
8484 */
8585 Content.compareObjects = function( a, b, asymmetrical ) {
8686 var aValue, bValue, aType, bType;
87 - for ( var k in a ) {
 87+ var k;
 88+ for ( k in a ) {
8889 aValue = a[k];
8990 bValue = b[k];
9091 aType = typeof aValue;
@@ -91,7 +92,7 @@
9293 if ( aType !== bType
9394 || ( ( aType === 'string' || aType === 'number' ) && aValue !== bValue )
9495 || ( $.isPlainObject( aValue ) && !Content.compareObjects( aValue, bValue ) ) ) {
95 - return false
 96+ return false;
9697 }
9798 }
9899 // If the check is not asymmetrical, recursing with the arguments swapped will verify our result
@@ -106,7 +107,8 @@
107108 */
108109 Content.copyObject = function( source ) {
109110 var destination = {};
110 - for ( var key in source ) {
 111+ var key;
 112+ for ( key in source ) {
111113 sourceValue = source[key];
112114 sourceType = typeof sourceValue;
113115 if ( sourceType === 'string' || sourceType === 'number' ) {
@@ -129,7 +131,8 @@
130132 Content.convertLine = function( line ) {
131133 // Convert string to array of characters
132134 var data = line.text.split('');
133 - for ( var i in line.annotations ) {
 135+ var i;
 136+ for ( i in line.annotations ) {
134137 var src = line.annotations[i];
135138 // Build simplified annotation object
136139 var dst = { 'type': src.type };
@@ -137,7 +140,8 @@
138141 dst.data = Content.copyObject( src.data );
139142 }
140143 // Apply annotation to range
141 - for ( var k = src.range.start; k < src.range.end; k++ ) {
 144+ var k;
 145+ for ( k = src.range.start; k < src.range.end; k++ ) {
142146 // Auto-convert to array
143147 typeof data[k] === 'string' && ( data[k] = [data[k]] );
144148 // Append
@@ -170,7 +174,8 @@
171175 */
172176 Content.newFromLines = function( lines ) {
173177 var data = [];
174 - for ( var i = 0; i < lines.length; i++ ) {
 178+ var i;
 179+ for ( i = 0; i < lines.length; i++ ) {
175180 data = data.concat( Content.convertLine( lines[i] ) );
176181 if ( i < lines.length - 1 ) {
177182 data.push( '\n' );
@@ -217,7 +222,8 @@
218223 throw 'Invalid stack error. An element is missing from the stack.';
219224 }
220225 // Close each already opened annotation
221 - for ( var i = stack.length - 1; i >= depth + 1; i-- ) {
 226+ var i;
 227+ for ( i = stack.length - 1; i >= depth + 1; i-- ) {
222228 out += typeof renderers[stack[i].type]['close'] === 'function'
223229 ? renderers[stack[i].type]['close']( stack[i].data )
224230 : renderers[stack[i].type]['close'];
@@ -227,7 +233,8 @@
228234 ? renderers[type]['close']( annotation.data )
229235 : renderers[type]['close'];
230236 // Re-open each previously opened annotation
231 - for ( var i = depth + 1; i < stack.length; i++ ) {
 237+ var i;
 238+ for ( i = depth + 1; i < stack.length; i++ ) {
232239 out += typeof renderers[stack[i].type]['open'] === 'function'
233240 ? renderers[stack[i].type]['open']( stack[i].data )
234241 : renderers[stack[i].type]['open'];
@@ -257,11 +264,12 @@
258265 if ( end === undefined ) {
259266 end = this.data.length;
260267 } else {
261 - end = Math.min( this.data.length, end )
 268+ end = Math.min( this.data.length, end );
262269 }
263270 // Copy characters
264271 var text = '';
265 - for ( var i = start; i < end; i++ ) {
 272+ var i;
 273+ for ( i = start; i < end; i++ ) {
266274 // If not using in IE6 or IE7 (which do not support array access for strings) use this..
267275 // text += this.data[i][0];
268276 // Otherwise use this...
@@ -296,14 +304,15 @@
297305 var neighbor = this.data[Math.max( start - 1, 0 )];
298306 if ( $.isArray( neighbor ) ) {
299307 var annotations = neighbor.slice( 1 );
300 - for ( var i = 0; i < insert.length; i++ ) {
 308+ var i;
 309+ for ( i = 0; i < insert.length; i++ ) {
301310 if ( typeof insert[i] === 'string' ) {
302311 insert[i] = [insert[i]];
303312 }
304313 insert[i] = insert[i].concat( annotations );
305314 }
306315 }
307 - Array.prototype.splice.apply( this.data, [start, 0].concat( insert ) )
 316+ Array.prototype.splice.apply( this.data, [start, 0].concat( insert ) );
308317 };
309318
310319 /**
@@ -339,8 +348,9 @@
340349 */
341350 Content.prototype.coverageOfAnnotation = function( start, end, annotation, strict ) {
342351 var coverage = [];
343 - for ( var i = start; i < end; i++ ) {
344 - var index = this.indexOfAnnotation( i, annotation );
 352+ var i, index;
 353+ for ( i = start; i < end; i++ ) {
 354+ index = this.indexOfAnnotation( i, annotation );
345355 if ( typeof this.data[i] !== 'string' && index !== -1 ) {
346356 if ( strict ) {
347357 if ( Content.compareObjects( this.data[i][index].data, annotation.data ) ) {
@@ -367,8 +377,9 @@
368378 */
369379 Content.prototype.indexOfAnnotation = function( offset, annotation, strict ) {
370380 var annotatedCharacter = this.data[offset];
 381+ var i;
371382 if ( typeof annotatedCharacter !== 'string' ) {
372 - for ( var i = 1; i < this.data[offset].length; i++ ) {
 383+ for ( i = 1; i < this.data[offset].length; i++ ) {
373384 if ( annotatedCharacter[i].type === annotation.type ) {
374385 if ( strict ) {
375386 if ( Content.compareObjects( annotatedCharacter[i].data, annotation.data ) ) {
@@ -398,6 +409,8 @@
399410 * @param end {Integer} Offset to stop annotating to
400411 */
401412 Content.prototype.annotate = function( method, annotation, start, end ) {
 413+ var i;
 414+
402415 start = Math.max( start, 0 );
403416 end = Math.min( end, this.data.length );
404417 if ( method === 'toggle' ) {
@@ -411,7 +424,7 @@
412425 }
413426 if ( method === 'add' ) {
414427 var duplicate;
415 - for ( var i = start; i < end; i++ ) {
 428+ for ( i = start; i < end; i++ ) {
416429 duplicate = -1;
417430 if ( typeof this.data[i] === 'string' ) {
418431 // Never annotate new lines
@@ -433,7 +446,7 @@
434447 }
435448 }
436449 } else if ( method === 'remove' ) {
437 - for ( var i = start; i < end; i++ ) {
 450+ for ( i = start; i < end; i++ ) {
438451 if ( typeof this.data[i] !== 'string' ) {
439452 if ( annotation.type === 'all' ) {
440453 // Remove all annotations by converting the annotated character to a plain
@@ -466,29 +479,30 @@
467480 right,
468481 leftPlain,
469482 rightPlain,
 483+ i, j, // iterators
470484 stack = [];
471 - for ( var i = 0; i < this.data.length; i++ ) {
 485+ for ( i = 0; i < this.data.length; i++ ) {
472486 right = this.data[i];
473487 leftPlain = typeof left === 'string';
474488 rightPlain = typeof right === 'string';
475489 if ( !leftPlain && rightPlain ) {
476490 // [formatted][plain] pair, close any annotations for left
477 - for ( var j = 1; j < left.length; j++ ) {
 491+ for ( j = 1; j < left.length; j++ ) {
478492 out += Content.renderAnnotation( 'close', left[j], stack );
479493 }
480494 } else if ( leftPlain && !rightPlain ) {
481495 // [plain][formatted] pair, open any annotations for right
482 - for ( var j = 1; j < right.length; j++ ) {
 496+ for ( j = 1; j < right.length; j++ ) {
483497 out += Content.renderAnnotation( 'open', right[j], stack );
484498 }
485499 } else if ( !leftPlain && !rightPlain ) {
486500 // [formatted][formatted] pair, open/close any differences
487 - for ( var j = 1; j < left.length; j++ ) {
 501+ for ( j = 1; j < left.length; j++ ) {
488502 if ( right.indexOf( left[j] ) === -1 ) {
489503 out += Content.renderAnnotation( 'close', left[j], stack );
490504 }
491505 }
492 - for ( var j = 1; j < right.length; j++ ) {
 506+ for ( j = 1; j < right.length; j++ ) {
493507 if ( left.indexOf( right[j] ) === -1 ) {
494508 out += Content.renderAnnotation( 'open', right[j], stack );
495509 }
@@ -498,4 +512,4 @@
499513 left = right;
500514 }
501515 return out;
502 -}
 516+};
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js
@@ -56,7 +56,7 @@
5757 var virtual = line < this.lines.length - 1
5858 && this.boundaryTest.exec( this.lines[line].text.substr( -1 ) ) ? -1 : 0;
5959 line = Math.min( line, this.lines.length - 1 );
60 - var $ruler = $( '<div class="editSurface-ruler"></div>' ).appendTo( this.$ )
 60+ var $ruler = $( '<div class="editSurface-ruler"></div>' ).appendTo( this.$ ),
6161 ruler = $ruler[0],
6262 fit = this.fitCharacters(
6363 this.lines[line].start, this.lines[line].end, ruler, position.left
@@ -112,8 +112,8 @@
113113 }
114114 position.top += this.lines[line].height;
115115 line++;
116 - };
117 -
 116+ }
 117+
118118 /*
119119 * Virtual n+1 position
120120 *
@@ -271,7 +271,7 @@
272272 * container and measure it.
273273 */
274274 rs.$ruler = $( '<div>&nbsp;</div>' ).appendTo( this.$ );
275 - rs.width = rs.$ruler.innerWidth()
 275+ rs.width = rs.$ruler.innerWidth();
276276
277277 // TODO: Take offset into account
278278 // Ignore offset optimization if the width has changed or the text has never been flowed before
Index: trunk/parsers/wikidom/lib/es/es.Cursor.js
@@ -45,5 +45,5 @@
4646 if( this.cursorInterval ) {
4747 clearInterval( this.cursorInterval );
4848 }
49 - this.$.hide()
 49+ this.$.hide();
5050 };
Index: trunk/parsers/wikidom/lib/wiki.util.js
@@ -4,12 +4,13 @@
55 wiki.util = {
66 'str': {
77 'repeat': function( pattern, count ) {
8 - if ( count < 1 ) return '';
 8+ if ( count < 1 ) { return ''; }
99 var result = '';
1010 while ( count > 0 ) {
11 - if ( count & 1 ) result += pattern;
12 - count >>= 1, pattern += pattern;
13 - };
 11+ if ( count & 1 ) { result += pattern; }
 12+ count >>= 1;
 13+ pattern += pattern;
 14+ }
1415 return result;
1516 }
1617 },
@@ -24,8 +25,9 @@
2526 },
2627 'attr': function( attributes, prespace ) {
2728 var attr = [];
 29+ var name;
2830 if ( attributes ) {
29 - for ( var name in attributes ) {
 31+ for ( name in attributes ) {
3032 attr.push( name + '="' + attributes[name] + '"' );
3133 }
3234 }
Index: trunk/parsers/wikidom/lib/wiki.AnnotationRenderer.js
@@ -60,8 +60,8 @@
6161 * @return String: Wrapped text
6262 */
6363 this.apply = function( text ) {
64 - var out = '';
65 - for ( var i = 0, iMax = text.length; i <= iMax; i++ ) {
 64+ var out = '', i;
 65+ for ( i = 0, iMax = text.length; i <= iMax; i++ ) {
6666 if ( i in insertions ) {
6767 out += insertions[i].join( '' );
6868 }

Status & tagging log