r95270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95269‎ | r95270 | r95271 >
Date:22:39, 22 August 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added test for floating objects, annotations that inject HTML content that is floated left or right.
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)
  • /trunk/parsers/wikidom/tests/annotations/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/annotations/test.js
@@ -50,7 +50,6 @@
5151 ]
5252 }
5353 ];
54 -
5554 var content = es.Content.newFromWikiDomLines( lines );
5655
5756 /* Tests */
@@ -318,4 +317,27 @@
319318 ],
320319 'Content.slice returns all data when called without arguments'
321320 );
322 -} );
\ No newline at end of file
 321+} );
 322+
 323+var floating = es.Content.newFromWikiDomLines( [
 324+ {
 325+ "text": "Look, a floating image!",
 326+ "annotations": [
 327+ {
 328+ "type": "template",
 329+ "data": {
 330+ "html": "<div style=\"float: right\">[image goes here]</div>"
 331+ },
 332+ "range": {
 333+ "start": 6,
 334+ "end": 7
 335+ }
 336+ }
 337+ ]
 338+ }
 339+] );
 340+
 341+test( 'Floating objects in Content', 2, function() {
 342+ ok( !content.hasFloatingObjects(), 'Without floating objects' );
 343+ ok( floating.hasFloatingObjects(), 'With floating objects' );
 344+} );
Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -35,38 +35,48 @@
3636 return '<span class="editSurface-format-object">' + data.html;
3737 },
3838 'close': '</span>',
 39+ 'float': function( data ) {
 40+ console.log( data.html );
 41+ return $( data.html ).css( 'float' );
 42+ }
3943 },
4044 'bold': {
4145 'open': '<span class="editSurface-format-bold">',
4246 'close': '</span>',
 47+ 'float': false
4348 },
4449 'italic': {
4550 'open': '<span class="editSurface-format-italic">',
4651 'close': '</span>',
 52+ 'float': false
4753 },
4854 'size': {
4955 'open': function( data ) {
5056 return '<span class="editSurface-format-' + data.type + '">';
5157 },
5258 'close': '</span>',
 59+ 'float': false
5360 },
5461 'script': {
5562 'open': function( data ) {
5663 return '<span class="editSurface-format-' + data.type + '">';
5764 },
5865 'close': '</span>',
 66+ 'float': false
5967 },
6068 'xlink': {
6169 'open': function( data ) {
6270 return '<span class="editSurface-format-link" data-href="' + data.href + '">';
6371 },
64 - 'close': '</span>'
 72+ 'close': '</span>',
 73+ 'float': false
6574 },
6675 'ilink': {
6776 'open': function( data ) {
6877 return '<span class="editSurface-format-link" data-title="' + data.title + '">';
6978 },
70 - 'close': '</span>'
 79+ 'close': '</span>',
 80+ 'float': false
7181 }
7282 };
7383
@@ -346,6 +356,34 @@
347357 };
348358
349359 /**
 360+ * Checks if a range of content contains any floating objects.
 361+ *
 362+ * @method
 363+ * @param range {es.Range} Range of content to check
 364+ * @returns {Boolean} If there's any floating objects in range
 365+ */
 366+es.Content.prototype.hasFloatingObjects = function( range ) {
 367+ if ( !range ) {
 368+ range = new es.Range( 0, this.data.length );
 369+ }
 370+ range.normalize();
 371+ for ( var i = 0; i < this.data.length; i++ ) {
 372+ if ( this.data[i].length > 1 ) {
 373+ for ( var j = 1; j < this.data[i].length; j++ ) {
 374+ var float = es.Content.annotationRenderers[this.data[i][j].type].float;
 375+ if ( float && typeof float === 'function' ) {
 376+ float = float( this.data[i][j].data );
 377+ }
 378+ if ( float ) {
 379+ return true;
 380+ }
 381+ }
 382+ }
 383+ }
 384+ return false;
 385+};
 386+
 387+/**
350388 * Inserts content data at a specific position.
351389 *
352390 * Inserted content will inherit annotations from neighboring content.

Status & tagging log