r112845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112844‎ | r112845 | r112846 >
Date:22:14, 1 March 2012
Author:inez
Status:deferred
Tags:
Comment:
Cleanup for JSLint
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -32,7 +32,7 @@
3333 $document.bind( {
3434 'keydown.ce-surfaceView': function( e ) {
3535 // return _this.onKeyDown( e );
36 - },
 36+ }
3737 } );
3838 },
3939 'blur': function( e ) {
@@ -76,7 +76,6 @@
7777
7878 ve.es.Surface.prototype.onCompositionStart = function( e ) {
7979 this.stopPolling();
80 -
8180 var rangySel = rangy.getSelection();
8281 this.poll.compositionStart = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false );
8382 };
@@ -84,7 +83,6 @@
8584 ve.es.Surface.prototype.onCompositionEnd = function( e ) {
8685 var rangySel = rangy.getSelection();
8786 this.poll.compositionEnd = this.getOffset( rangySel.focusNode, rangySel.focusOffset, false );
88 -
8987 this.startPolling();
9088 };
9189
@@ -122,11 +120,13 @@
123121 };
124122
125123 ve.es.Surface.prototype.pollContent = function() {
 124+ var localOffset, text, hash;
 125+
126126 if ( this.poll.compositionStart !== null && this.poll.compositionEnd !== null ) {
127127
128 - var text = ve.es.Surface.getDOMText2( this.poll.node ),
129 - hash = ve.es.Surface.getDOMHash( this.poll.node ),
130 - localOffset = this.poll.compositionEnd;
 128+ text = ve.es.Surface.getDOMText2( this.poll.node );
 129+ hash = ve.es.Surface.getDOMHash( this.poll.node );
 130+ localOffset = this.poll.compositionEnd;
131131 this.poll.compositionStart = null;
132132 this.poll.compositionEnd = null;
133133
@@ -137,14 +137,14 @@
138138 return;
139139 }
140140
141 - var node = this.getLeafNode( rangySel.anchorNode )[0],
142 - text = ve.es.Surface.getDOMText2( node ),
143 - hash = ve.es.Surface.getDOMHash( node );
 141+ var node = this.getLeafNode( rangySel.anchorNode )[0];
 142+ text = ve.es.Surface.getDOMText2( node );
 143+ hash = ve.es.Surface.getDOMHash( node );
144144
145145 if ( rangySel.anchorNode !== rangySel.focusNode || rangySel.anchorOffset !== rangySel.focusOffset ) {
146 - var localOffset = null;
 146+ localOffset = null;
147147 } else {
148 - var localOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false );
 148+ localOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false );
149149 }
150150
151151 if ( node !== this.poll.node ) {
@@ -155,6 +155,8 @@
156156 return;
157157 }
158158 }
 159+
 160+ var newData, annotations;
159161
160162 if ( text !== this.poll.prevText ) {
161163 var nodeOffset = this.documentView.getOffsetFromNode( $( this.poll.node ).data( 'view' ) ),
@@ -162,8 +164,8 @@
163165 offsetDiff = ( localOffset !== null && this.poll.prevOffset !== null ) ? localOffset - this.poll.prevOffset : null;
164166
165167 if ( lengthDiff === offsetDiff && this.poll.prevText.substring( 0, this.poll.prevOffset ) === text.substring( 0, this.poll.prevOffset ) ) {
166 - var newData = text.substring( this.poll.prevOffset, localOffset ).split( '' );
167 - var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 );
 168+ newData = text.substring( this.poll.prevOffset, localOffset ).split( '' );
 169+ annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 );
168170 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
169171 this.model.transact( this.documentView.model.prepareInsertion(
170172 nodeOffset + 1 + this.poll.prevOffset,
@@ -173,19 +175,19 @@
174176 var sameFromLeft = 0,
175177 sameFromRight = 0,
176178 l = text.length > this.poll.prevText.length ? this.poll.prevText.length : text.length;
177 - while ( sameFromLeft < l && this.poll.prevText[sameFromLeft] == text[sameFromLeft] ) {
 179+ while ( sameFromLeft < l && this.poll.prevText[sameFromLeft] === text[sameFromLeft] ) {
178180 ++sameFromLeft;
179181 }
180182 l = l - sameFromLeft;
181 - while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] == text[text.length - 1 - sameFromRight] ) {
 183+ while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] === text[text.length - 1 - sameFromRight] ) {
182184 ++sameFromRight;
183185 }
184186 this.model.transact( this.documentView.model.prepareRemoval( new ve.Range(
185187 nodeOffset + 1 + sameFromLeft,
186188 nodeOffset + 1 + this.poll.prevText.length - sameFromRight
187189 ) ) );
188 - var newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' );
189 - var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft );
 190+ newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' );
 191+ annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft );
190192 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
191193 this.model.transact( this.documentView.model.prepareInsertion(
192194 nodeOffset + 1 + sameFromLeft,
@@ -250,22 +252,21 @@
251253 };
252254
253255 ve.es.Surface.prototype.showCursorAt = function( offset ) {
254 - var $node = this.documentView.getNodeFromOffset( offset ).$;
255 - var current = [$node.contents(), 0];
256 - var stack = [current];
257 - var node;
258 - var localOffset;
259 -
260 - var index = 1 + this.documentView.getOffsetFromNode( $node.data('view') );
261 -
 256+ var $node = this.documentView.getNodeFromOffset( offset ).$,
 257+ current = [$node.contents(), 0],
 258+ stack = [current],
 259+ node,
 260+ localOffset,
 261+ index = this.documentView.getOffsetFromNode( $node.data('view') ) + 1;
 262+
262263 while ( stack.length > 0 ) {
263264 if ( current[1] >= current[0].length ) {
264265 stack.pop();
265266 current = stack[ stack.length - 1 ];
266267 continue;
267268 }
268 - var item = current[0][current[1]];
269 - var $item = current[0].eq( current[1] );
 269+ var item = current[0][current[1]],
 270+ $item = current[0].eq( current[1] );
270271
271272 if ( item.nodeType === 3 ) {
272273 var length = item.textContent.length;
@@ -290,11 +291,10 @@
291292 }
292293 var range = document.createRange();
293294 range.collapsed = true;
294 - range.setStart(node, localOffset);
295 -
 295+ range.setStart( node, localOffset );
296296 var sel = window.getSelection();
297297 sel.removeAllRanges();
298 - sel.addRange(range);
 298+ sel.addRange( range );
299299 };
300300
301301 ve.es.Surface.prototype.getSelection = function() {
@@ -351,15 +351,16 @@
352352
353353 ve.es.Surface.getDOMHash = function( elem ) {
354354 var nodeType = elem.nodeType,
355 - nodeName = elem.nodeName,
 355+ nodeName = elem.nodeName,
356356 ret = '';
357357
358358 if ( nodeType === 3 || nodeType === 4 ) {
359359 return '#';
360360 } else if ( nodeType === 1 || nodeType === 9 ) {
361361 ret += '<' + nodeName + '>';
 362+ // Traverse it's children
362363 for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
363 - ret += ve.es.Surface.getDOMHash( elem );
 364+ ret += ve.es.Surface.getDOMHash( elem );
364365 }
365366 ret += '</' + nodeName + '>';
366367 }
@@ -368,4 +369,4 @@
369370
370371 /* Inheritance */
371372
372 -ve.extendClass( ve.es.Surface, ve.EventEmitter );
 373+ve.extendClass( ve.es.Surface, ve.EventEmitter );
\ No newline at end of file

Status & tagging log