r92488 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92487‎ | r92488 | r92489 >
Date:22:29, 18 July 2011
Author:inez
Status:deferred
Tags:
Comment:
Implementation of getLines method, that returns array of lines objects
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -559,4 +559,69 @@
560560 };
561561 };
562562
 563+Content.prototype.getLines = function() {
 564+ var lines = [],
 565+ line = null,
 566+ offset = 0,
 567+ left = '',
 568+ right = '',
 569+ leftPlain,
 570+ rightPlain;
 571+
 572+ for ( var i = 0; i < this.data.length; i++ ) {
 573+
 574+ if ( line == null ) {
 575+ line = {
 576+ text : '',
 577+ annotations : []
 578+ };
 579+ }
 580+
 581+ if ( this.data[i] == "\n" ) {
 582+ lines.push(line);
 583+ line = null;
 584+ offset = i + 1;
 585+ continue;
 586+ }
 587+
 588+ right = this.data[i];
 589+ leftPlain = typeof left === 'string';
 590+ rightPlain = typeof right === 'string';
 591+
 592+ for ( var j = 1; j < left.length; j++ ) {
 593+ if (rightPlain || this.indexOfAnnotation( i, left[j], true ) === -1) {
 594+ for ( var k = line.annotations.length - 1; k >= 0; k--) {
 595+ if ( line.annotations[k].type === left[j].type ) {
 596+ if ( Content.compareObjects( line.annotations[k].data, left[j].data ) ) {
 597+ line.annotations[k].range.end = i - offset;
 598+ break;
 599+ }
 600+ }
 601+ }
 602+ }
 603+ }
 604+
 605+ for ( var j = 1; j < right.length; j++ ) {
 606+ if (leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1) {
 607+ var annotation = Content.copyObject( right[j] );
 608+ annotation.range = {
 609+ start : i - offset,
 610+ end : i + 1 - offset
 611+ };
 612+ line.annotations.push( annotation );
 613+ }
 614+ }
 615+
 616+ left = right;
 617+
 618+ if ( rightPlain ) {
 619+ line.text += this.data[i];
 620+ } else {
 621+ line.text += this.data[i][0];
 622+ }
 623+ }
 624+
 625+ return lines;
 626+};
 627+
563628 extend( Content, EventEmitter );

Status & tagging log