http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99735
Revision: 99735
Author: tparscal
Date: 2011-10-13 21:32:15 +0000 (Thu, 13 Oct 2011)
Log Message:
-----------
Fixed some things that jshint was complaining about
Modified Paths:
--------------
trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
Modified: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js 2011-10-13
20:49:45 UTC (rev 99734)
+++ trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js 2011-10-13
21:32:15 UTC (rev 99735)
@@ -114,7 +114,7 @@
}
// Automatically clean up attributes object
var empty = true;
- for ( key in element.attributes ) {
+ for ( var key in element.attributes ) {
empty = false;
break;
}
@@ -127,11 +127,15 @@
}
function annotate( to ) {
+ var i,
+ j,
+ length,
+ annotation;
// Handle annotations
if ( this.set.length ) {
- for ( var i = 0, length = this.set.length; i < length;
i++ ) {
- var annotation = this.set[i];
- for ( var j = this.cursor; j < to; j++ ) {
+ for ( i = 0, length = this.set.length; i < length; i++
) {
+ annotation = this.set[i];
+ for ( j = this.cursor; j < to; j++ ) {
if ( $.isArray( this.data[j] ) ) {
this.data[j].push( annotation );
} else {
@@ -143,9 +147,9 @@
}
}
if ( this.clear.length ) {
- for ( var i = 0, length = this.clear.length; i <
length; i++ ) {
- var annotation = this.clear[i];
- for ( var j = this.cursor; j < to; j++ ) {
+ for ( i = 0, length = this.clear.length; i < length;
i++ ) {
+ annotation = this.clear[i];
+ for ( j = this.cursor; j < to; j++ ) {
var index =
es.DocumentModel.getIndexOfAnnotation( this.data[j], annotation );
if ( index !== -1 ) {
this.data[j].splice( index, 1 );
@@ -261,7 +265,7 @@
es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) {
if ( annotation === undefined || annotation.type === undefined ) {
- throw 'Invalid annotation error. Can not find non-annotation
data in character.'
+ throw 'Invalid annotation error. Can not find non-annotation
data in character.';
}
if ( $.isArray( character ) ) {
// Find the index of a comparable annotation (checking for same
value, not reference)
@@ -333,7 +337,9 @@
}
for ( var j = src.start; j < src.end; j++ ) {
// Auto-convert to array
- typeof data[j] === 'string' && (
data[j] = [data[j]] );
+ if ( typeof data[j] === 'string' ) {
+ data[j] = [data[j]];
+ }
// Append
data[j].push( dst );
}
@@ -424,7 +430,7 @@
*/
es.DocumentModel.prototype.getData = function( range, deep ) {
var start = 0,
- end = undefined;
+ end;
if ( range !== undefined ) {
range.normalize();
start = Math.max( 0, Math.min( this.data.length, range.start )
);
@@ -481,8 +487,8 @@
for ( var i = 0, length = this.length; i < length; i++ ) {
nodeLength = this[i].getElementLength();
if ( offset >= nodeOffset && offset < nodeOffset + nodeLength )
{
- return this[i].length
- ? es.DocumentModel.prototype.getNode.call(
this[i], offset - nodeOffset ) : this[i];
+ return this[i].length ?
+ es.DocumentModel.prototype.getNode.call(
this[i], offset - nodeOffset ) : this[i];
}
nodeOffset += nodeLength;
}
@@ -525,7 +531,7 @@
range = {
'start': 0,
'end': length
- }
+ };
}
var offset = this.getOffsetFromNode( node );
if ( offset !== -1 ) {
@@ -583,7 +589,6 @@
* }
* }
*/
- return tx;
};
/**
@@ -718,10 +723,10 @@
tx.pushRetain( offset );
}
if ( this.data[offset].type === undefined ) {
- throw 'Invalid element offset error. Can not set attributes to
non-element data.'
+ throw 'Invalid element offset error. Can not set attributes to
non-element data.';
}
if ( this.data[offset].type[0] === '/' ) {
- throw 'Invalid element offset error. Can not set attributes on
closing element.'
+ throw 'Invalid element offset error. Can not set attributes on
closing element.';
}
tx.pushChangeElementAttribute( method, key, value );
if ( offset < this.data.length ) {
Modified: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
===================================================================
--- trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js 2011-10-13
20:49:45 UTC (rev 99734)
+++ trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js 2011-10-13
21:32:15 UTC (rev 99735)
@@ -22,7 +22,7 @@
var obj = {
'type': 'document',
'children': [
- {
+ {
'type': 'paragraph',
'content': {
'text': 'abc',
@@ -49,51 +49,51 @@
{
'type': 'tableCell',
'children': [
- {
- 'type':
'paragraph',
- 'content': {
- 'text':
'a'
- }
- },
- {
- 'type': 'list',
- 'children': [
- {
-
'type': 'listItem',
-
'attributes': {
-
'styles': ['bullet']
-
},
-
'content': {
-
'text': 'a'
-
}
- },
- {
-
'type': 'listItem',
-
'attributes': {
-
'styles': ['bullet', 'bullet']
-
},
-
'content': {
-
'text': 'b'
-
}
- },
- {
-
'type': 'listItem',
-
'attributes': {
-
'styles': ['number']
-
},
-
'content': {
-
'text': 'c'
-
}
- }
- ]
- }
- ]
+ {
+ 'type':
'paragraph',
+
'content': {
+
'text': 'a'
+ }
+ },
+ {
+ 'type':
'list',
+
'children': [
+
{
+
'type': 'listItem',
+
'attributes': {
+
'styles': ['bullet']
+
},
+
'content': {
+
'text': 'a'
+
}
+
},
+
{
+
'type': 'listItem',
+
'attributes': {
+
'styles': ['bullet', 'bullet']
+
},
+
'content': {
+
'text': 'b'
+
}
+
},
+
{
+
'type': 'listItem',
+
'attributes': {
+
'styles': ['number']
+
},
+
'content': {
+
'text': 'c'
+
}
+
}
+ ]
+ }
+ ]
}
]
}
]
},
- {
+ {
'type': 'paragraph',
'content': {
'text': 'a'
@@ -120,8 +120,8 @@
* [attributes]: {Object} List of symbolic attribute name and literal
value pairs
*/
var data = [
- // 0 - Beginning of paragraph
- { 'type': 'paragraph' },
+ // 0 - Beginning of paragraph
+ { 'type': 'paragraph' },
// 1 - Plain content
'a',
// 2 - Annotated content
@@ -130,39 +130,39 @@
['c', { 'type': 'italic', 'hash': '#italic' }],
// 4 - End of paragraph
{ 'type': '/paragraph' },
- // 5 - Beginning of table
+ // 5 - Beginning of table
{ 'type': 'table' },
- // 6 - Beginning of row
+ // 6 - Beginning of row
{ 'type': 'tableRow' },
- // 7 - Beginning of cell
+ // 7 - Beginning of cell
{ 'type': 'tableCell' },
- // 8 - Beginning of paragraph
+ // 8 - Beginning of paragraph
{ 'type': 'paragraph' },
// 9 - Plain content
'a',
- // 10 - End of paragraph
+ // 10 - End of paragraph
{ 'type': '/paragraph' },
- // 11 - Beginning of list
+ // 11 - Beginning of list
{ 'type': 'list' },
- // 12 - Beginning of bullet list item
+ // 12 - Beginning of bullet list item
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
// 13 - Plain content
'a',
- // 14 - End of item
+ // 14 - End of item
{ 'type': '/listItem' },
- // 15 - Beginning of nested bullet list item
+ // 15 - Beginning of nested bullet list item
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] }
},
// 16 - Plain content
'b',
- // 17 - End of item
+ // 17 - End of item
{ 'type': '/listItem' },
- // 18 - Beginning of numbered list item
+ // 18 - Beginning of numbered list item
{ 'type': 'listItem', 'attributes': { 'styles': ['number'] } },
// 19 - Plain content
'c',
- // 20 - End of item
+ // 20 - End of item
{ 'type': '/listItem' },
- // 21 - End of list
+ // 21 - End of list
{ 'type': '/list' },
// 22 - End of cell
{ 'type': '/tableCell' },
@@ -170,11 +170,11 @@
{ 'type': '/tableRow' },
// 24 - End of table
{ 'type': '/table' },
- // 25 - Beginning of paragraph
+ // 25 - Beginning of paragraph
{ 'type': 'paragraph' },
// 26 - Plain content
'a',
- // 27 - End of paragraph
+ // 27 - End of paragraph
{ 'type': '/paragraph' }
];
@@ -231,13 +231,13 @@
try {
documentModel[0].getContent( new es.Range( -1, 3 ) );
- } catch ( err ) {
+ } catch ( negativeIndexError ) {
ok( true, 'getContent throws exceptions when given a range with
start < 0' );
}
try {
documentModel[0].getContent( new es.Range( 0, 4 ) );
- } catch ( err ) {
+ } catch ( outOfRangeError ) {
ok( true, 'getContent throws exceptions when given a range with
end > length' );
}
@@ -286,8 +286,8 @@
);
try {
- documentModel.prepareElementAttributeChange( 1, 'set', 'test',
1234 )
- } catch ( err ) {
+ documentModel.prepareElementAttributeChange( 1, 'set', 'test',
1234 );
+ } catch ( invalidOffsetError ) {
ok(
true,
'prepareElementAttributeChange throws an exception when
offset is not an element'
@@ -295,8 +295,8 @@
}
try {
- documentModel.prepareElementAttributeChange( 4, 'set', 'test',
1234 )
- } catch ( err ) {
+ documentModel.prepareElementAttributeChange( 4, 'set', 'test',
1234 );
+ } catch ( closingElementError ) {
ok(
true,
'prepareElementAttributeChange throws an exception when
offset is a closing element'
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
