r113201 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113200‎ | r113201 | r113202 >
Date:23:51, 6 March 2012
Author:tparscal
Status:ok
Tags:
Comment:
Fixed some jshint complaints and enforced 100char line endings
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
@@ -44,11 +44,11 @@
4545
4646 this.$
4747 .on( 'cut copy', function( e ) {
48 - _this.onCutCopy( e );
49 - } )
 48+ _this.onCutCopy( e );
 49+ } )
5050 .on( 'paste', function( e ) {
51 - _this.onPaste( e );
52 - } )
 51+ _this.onPaste( e );
 52+ } )
5353 .on( 'mousedown', function( e ) {
5454 return _this.onMouseDown( e );
5555 } )
@@ -62,20 +62,20 @@
6363 } )
6464 .on('dragover drop', function( e ) {
6565 e.preventDefault();
66 - });
 66+ } );
6767
6868 // Initialization
6969 this.documentView.renderContent();
7070
7171 this.poll = {
72 - interval: null,
73 - frequency: 75,
74 - node: null,
75 - prevText: null,
76 - prevHash: null,
77 - prevOffset: null,
78 - compositionStart: null,
79 - compositionEnd: null
 72+ 'interval': null,
 73+ 'frequency': 75,
 74+ 'node': null,
 75+ 'prevText': null,
 76+ 'prevHash': null,
 77+ 'prevOffset': null,
 78+ 'compositionStart': null,
 79+ 'compositionEnd': null
8080 };
8181 };
8282
@@ -113,8 +113,8 @@
114114
115115 ve.ce.Surface.prototype.onCutCopy = function( e ) {
116116 var _this = this,
117 - rangySel = rangy.getSelection(),
118 - key = rangySel.getRangeAt(0).toString().replace(/\s/gm,"");
 117+ sel = rangy.getSelection(),
 118+ key = sel.getRangeAt(0).toString().replace( /\s/gm, '' );
119119
120120 _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) );
121121
@@ -134,7 +134,10 @@
135135 _this.getLeafNode( node ).data( 'view' ).renderContent();
136136
137137 // clear the prev information from poll object (probably a better way to do this)
138 - _this.poll.prevText = _this.poll.prevHash = _this.poll.prevOffset = _this.poll.node = null;
 138+ _this.poll.prevText =
 139+ _this.poll.prevHash =
 140+ _this.poll.prevOffset =
 141+ _this.poll.node = null;
139142
140143 // place cursor
141144 _this.showCursorAt( selection.start );
@@ -147,21 +150,31 @@
148151 insertionPoint = _this.getSelection().start,
149152 node = rangy.getSelection().anchorNode;
150153
151 - $('#paste').html('').show().css( 'top', $(window).scrollTop() ).css(' left', $(window).scrollLeft() ).focus();
 154+ $('#paste')
 155+ .html('')
 156+ .show()
 157+ .css( 'top', $(window).scrollTop() )
 158+ .css(' left', $(window).scrollLeft() )
 159+ .focus();
152160
153161 setTimeout( function() {
154 - var key = $('#paste').hide().text().replace(/\s/gm,"");
 162+ var key = $('#paste').hide().text().replace( /\s/gm, '' );
155163
156164 if ( _this.clipboard[key] ) {
157165 // transact
158 - var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]);
 166+ var tx = _this.documentView.model.prepareInsertion(
 167+ insertionPoint, _this.clipboard[key]
 168+ );
159169 _this.model.transact( tx );
160170
161171 // re-render
162172 _this.getLeafNode( node ).data( 'view' ).renderContent();
163173
164174 // clear the prev information from poll object (probably a better way to do this)
165 - _this.poll.prevText = _this.poll.prevHash = _this.poll.prevOffset = _this.poll.node = null;
 175+ _this.poll.prevText =
 176+ _this.poll.prevHash =
 177+ _this.poll.prevOffset =
 178+ _this.poll.node = null;
166179
167180 // place cursor
168181 _this.showCursorAt( insertionPoint + _this.clipboard[key].length );
@@ -173,13 +186,13 @@
174187
175188 ve.ce.Surface.prototype.onCompositionStart = function( e ) {
176189 this.stopPolling();
177 - var rangySel = rangy.getSelection();
178 - this.poll.compositionStart = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false );
 190+ var sel = rangy.getSelection();
 191+ this.poll.compositionStart = this.getOffset( sel.anchorNode, sel.anchorOffset, false );
179192 };
180193
181194 ve.ce.Surface.prototype.onCompositionEnd = function( e ) {
182 - var rangySel = rangy.getSelection();
183 - this.poll.compositionEnd = this.getOffset( rangySel.focusNode, rangySel.focusOffset, false );
 195+ var sel = rangy.getSelection();
 196+ this.poll.compositionEnd = this.getOffset( sel.focusNode, sel.focusOffset, false );
184197 this.startPolling();
185198 };
186199
@@ -230,20 +243,20 @@
231244 this.poll.compositionEnd = null;
232245
233246 } else {
234 - var rangySel = rangy.getSelection();
 247+ var sel = rangy.getSelection();
235248
236 - if ( rangySel.anchorNode === null ) {
 249+ if ( sel.anchorNode === null ) {
237250 return;
238251 }
239252
240 - var node = this.getLeafNode( rangySel.anchorNode )[0];
 253+ var node = this.getLeafNode( sel.anchorNode )[0];
241254 text = ve.ce.Surface.getDOMText2( node );
242255 hash = ve.ce.Surface.getDOMHash( node );
243256
244 - if ( rangySel.anchorNode !== rangySel.focusNode || rangySel.anchorOffset !== rangySel.focusOffset ) {
 257+ if ( sel.anchorNode !== sel.focusNode || sel.anchorOffset !== sel.focusOffset ) {
245258 localOffset = null;
246259 } else {
247 - localOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false );
 260+ localOffset = this.getOffset( sel.anchorNode, sel.anchorOffset, false );
248261 }
249262
250263 if ( node !== this.poll.node ) {
@@ -261,11 +274,18 @@
262275 if ( text !== this.poll.prevText ) {
263276 var nodeOffset = this.documentView.getOffsetFromNode( $( this.poll.node ).data( 'view' ) ),
264277 lengthDiff = text.length - this.poll.prevText.length,
265 - offsetDiff = ( localOffset !== null && this.poll.prevOffset !== null ) ? localOffset - this.poll.prevOffset : null;
 278+ offsetDiff = ( localOffset !== null && this.poll.prevOffset !== null ) ?
 279+ localOffset - this.poll.prevOffset : null;
266280
267 - if ( lengthDiff === offsetDiff && this.poll.prevText.substring( 0, this.poll.prevOffset ) === text.substring( 0, this.poll.prevOffset ) ) {
 281+ if (
 282+ lengthDiff === offsetDiff &&
 283+ this.poll.prevText.substring( 0, this.poll.prevOffset ) ===
 284+ text.substring( 0, this.poll.prevOffset )
 285+ ) {
268286 newData = text.substring( this.poll.prevOffset, localOffset ).split( '' );
269 - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1, true );
 287+ annotations = this.model.getDocument().getAnnotationsFromOffset(
 288+ nodeOffset + 1 + this.poll.prevOffset - 1, true
 289+ );
270290 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
271291 this.model.transact( this.documentView.model.prepareInsertion(
272292 nodeOffset + 1 + this.poll.prevOffset,
@@ -274,15 +294,22 @@
275295 } else {
276296 var sameFromLeft = 0,
277297 sameFromRight = 0,
278 - l = text.length > this.poll.prevText.length ? this.poll.prevText.length : text.length;
 298+ l = text.length > this.poll.prevText.length ?
 299+ this.poll.prevText.length : text.length;
279300 while ( sameFromLeft < l && this.poll.prevText[sameFromLeft] === text[sameFromLeft] ) {
280301 ++sameFromLeft;
281302 }
282303 l = l - sameFromLeft;
283 - while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] === text[text.length - 1 - sameFromRight] ) {
284 - ++sameFromRight;
 304+ while (
 305+ sameFromRight < l &&
 306+ this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] ===
 307+ text[text.length - 1 - sameFromRight]
 308+ ) {
 309+ ++sameFromRight;
285310 }
286 - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft, true );
 311+ annotations = this.model.getDocument().getAnnotationsFromOffset(
 312+ nodeOffset + 1 + sameFromLeft, true
 313+ );
287314 this.model.transact( this.documentView.model.prepareRemoval( new ve.Range(
288315 nodeOffset + 1 + sameFromLeft,
289316 nodeOffset + 1 + this.poll.prevText.length - sameFromRight
@@ -319,6 +346,11 @@
320347 this.pollContent();
321348 this.startPolling();
322349 }
 350+ var sel,
 351+ globalOffset,
 352+ newOffset,
 353+ node,
 354+ nodeOffset;
323355 switch ( e.keyCode ) {
324356 // Enter
325357 case 13:
@@ -337,13 +369,15 @@
338370 break;
339371 // Left arrow
340372 case 37:
341 - var rangySel = rangy.getSelection();
342 - if ( rangySel.anchorOffset === 0 ) {
343 - var globalOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ),
344 - node = this.documentView.getNodeFromOffset( globalOffset ),
345 - nodeOffset = surfaceView.documentView.getOffsetFromNode( node );
 373+ sel = rangy.getSelection();
 374+ if ( sel.anchorOffset === 0 ) {
 375+ globalOffset = this.getOffset( sel.anchorNode, sel.anchorOffset, true );
 376+ node = this.documentView.getNodeFromOffset( globalOffset );
 377+ nodeOffset = surfaceView.documentView.getOffsetFromNode( node );
346378 if ( nodeOffset + 1 === globalOffset ) {
347 - var newOffset = this.documentView.model.getRelativeContentOffset( globalOffset, -1 );
 379+ newOffset = this.documentView.model.getRelativeContentOffset(
 380+ globalOffset, -1
 381+ );
348382 this.showCursorAt(newOffset);
349383 e.preventDefault();
350384 }
@@ -351,13 +385,15 @@
352386 break;
353387 // Right arrow
354388 case 39:
355 - var rangySel = rangy.getSelection();
356 - if ( rangySel.anchorOffset === rangySel.anchorNode.length ) {
357 - var globalOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ),
358 - node = this.documentView.getNodeFromOffset( globalOffset ),
359 - nodeOffset = surfaceView.documentView.getOffsetFromNode( node );
 389+ sel = rangy.getSelection();
 390+ if ( sel.anchorOffset === sel.anchorNode.length ) {
 391+ globalOffset = this.getOffset( sel.anchorNode, sel.anchorOffset, true );
 392+ node = this.documentView.getNodeFromOffset( globalOffset );
 393+ nodeOffset = surfaceView.documentView.getOffsetFromNode( node );
360394 if ( nodeOffset + 1 + node.getContentLength() === globalOffset ) {
361 - var newOffset = this.documentView.model.getRelativeContentOffset( globalOffset, 1 );
 395+ newOffset = this.documentView.model.getRelativeContentOffset(
 396+ globalOffset, 1
 397+ );
362398 this.showCursorAt(newOffset);
363399 e.preventDefault();
364400 }
@@ -393,7 +429,7 @@
394430 localOffset += item.textContent.length;
395431 }
396432 } else if ( item.nodeType === 1 ) {
397 - if ( $( item ).attr( 'contentEditable' ) === "false" ) {
 433+ if ( $( item ).attr( 'contentEditable' ) === 'false' ) {
398434 offset += 1;
399435 } else {
400436 if ( item === elem ) {
@@ -443,7 +479,7 @@
444480 index += length;
445481 }
446482 } else if ( item.nodeType === 1 ) {
447 - if ( $( item ).attr('contentEditable') === "false" ) {
 483+ if ( $( item ).attr('contentEditable') === 'false' ) {
448484 index += 1;
449485 } else {
450486 stack.push( [$item.contents(), 0] );
@@ -463,16 +499,16 @@
464500 };
465501
466502 ve.ce.Surface.prototype.getSelection = function() {
467 - var rangySel = rangy.getSelection(),
 503+ var sel = rangy.getSelection(),
468504 range;
469505
470 - if ( rangySel.anchorNode === rangySel.focusNode && rangySel.anchorOffset === rangySel.focusOffset ) {
471 - var offset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true );
 506+ if ( sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset ) {
 507+ var offset = this.getOffset( sel.anchorNode, sel.anchorOffset, true );
472508 range = new ve.Range( offset, offset );
473509 } else {
474510 range = new ve.Range(
475 - this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ),
476 - this.getOffset( rangySel.focusNode, rangySel.focusOffset, true )
 511+ this.getOffset( sel.anchorNode, sel.anchorOffset, true ),
 512+ this.getOffset( sel.focusNode, sel.focusOffset, true )
477513 );
478514 }
479515 range.normalize();
@@ -489,38 +525,38 @@
490526
491527 ve.ce.Surface.getDOMText2 = function( elem ) {
492528 // TODO: there must be some better way to write this regex replace
493 - var regex = new RegExp("[" + String.fromCharCode(32) + String.fromCharCode(160) + "]", "g");
494 - return ve.ce.Surface.getDOMText( elem ).replace( regex, " " );
 529+ var regex = new RegExp('[' + String.fromCharCode(32) + String.fromCharCode(160) + ']', 'g');
 530+ return ve.ce.Surface.getDOMText( elem ).replace( regex, ' ' );
495531 };
496532
497533 ve.ce.Surface.getDOMText = function( elem ) {
498 - var nodeType = elem.nodeType,
499 - ret = '';
 534+ var nodeType = elem.nodeType,
 535+ ret = '';
500536
501 - if ( nodeType === 1 || nodeType === 9 ) {
502 - // Use textContent || innerText for elements
503 - if ( typeof elem.textContent === 'string' ) {
504 - return elem.textContent;
505 - } else if ( typeof elem.innerText === 'string' ) {
506 - // Replace IE's carriage returns
507 - return elem.innerText.replace( /\r\n/g, '' );
508 - } else {
509 - // Traverse it's children
510 - for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
511 - ret += ve.ce.Surface.getDOMText( elem );
512 - }
513 - }
514 - } else if ( nodeType === 3 || nodeType === 4 ) {
515 - return elem.nodeValue;
516 - }
 537+ if ( nodeType === 1 || nodeType === 9 ) {
 538+ // Use textContent || innerText for elements
 539+ if ( typeof elem.textContent === 'string' ) {
 540+ return elem.textContent;
 541+ } else if ( typeof elem.innerText === 'string' ) {
 542+ // Replace IE's carriage returns
 543+ return elem.innerText.replace( /\r\n/g, '' );
 544+ } else {
 545+ // Traverse it's children
 546+ for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
 547+ ret += ve.ce.Surface.getDOMText( elem );
 548+ }
 549+ }
 550+ } else if ( nodeType === 3 || nodeType === 4 ) {
 551+ return elem.nodeValue;
 552+ }
517553
518 - return ret;
 554+ return ret;
519555 };
520556
521557 ve.ce.Surface.getDOMHash = function( elem ) {
522 - var nodeType = elem.nodeType,
 558+ var nodeType = elem.nodeType,
523559 nodeName = elem.nodeName,
524 - ret = '';
 560+ ret = '';
525561
526562 if ( nodeType === 3 || nodeType === 4 ) {
527563 return '#';
@@ -529,8 +565,8 @@
530566 // Traverse it's children
531567 for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
532568 ret += ve.ce.Surface.getDOMHash( elem );
533 - }
534 - ret += '</' + nodeName + '>';
 569+ }
 570+ ret += '</' + nodeName + '>';
535571 }
536572 return ret;
537573 };

Sign-offs

UserFlagDate
Krinkleinspected23:53, 6 March 2012

Status & tagging log