r99174 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99173‎ | r99174 | r99175 >
Date:00:39, 7 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added initial code for generating annotation and attribute transactions
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/es.Transaction.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -600,17 +600,56 @@
601601 * @returns {es.Transaction}
602602 */
603603 es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, annotation ) {
604 - //
 604+ var tx = new es.Transaction();
 605+ range.normalize();
 606+
 607+ var i = range.start,
 608+ span = i,
 609+ annotating = this.data[i].type !== undefined;
 610+ while ( i < range.end ) {
 611+ if ( this.data[i].type !== undefined ) {
 612+ // Structural
 613+ if ( annotating ) {
 614+ tx.pushStopAnnotating( method, annotation );
 615+ span = 0;
 616+ annotating = false;
 617+ }
 618+ } else {
 619+ // Content
 620+ if ( !annotating ) {
 621+ if ( span ) {
 622+ tx.pushRetain( span );
 623+ }
 624+ tx.pushStartAnnotating( method, annotation );
 625+ span = 0;
 626+ annotating = true;
 627+ }
 628+ }
 629+ span++;
 630+ }
 631+ if ( range.end < this.data.length ) {
 632+ tx.pushRetain( this.data.length - range.end );
 633+ }
 634+ return tx;
605635 };
606636
607637 /**
608 - * Generates a transaction which changes attributes on an element at a given index.
 638+ * Generates a transaction which changes attributes on an element at a given offset.
609639 *
610640 * @method
611641 * @returns {es.Transaction}
612642 */
613 -es.DocumentModel.prototype.prepareElementAttributeChange = function( index, method, annotation ) {
614 - //
 643+es.DocumentModel.prototype.prepareElementAttributeChange = function( offset, method, key, value ) {
 644+ var tx = new es.Transaction();
 645+ if ( offset ) {
 646+ tx.pushRetain( offset );
 647+ }
 648+ if ( this.data[offset].type !== undefined ) {
 649+ tx.pushChangeElementAttribute( method, key, value );
 650+ }
 651+ if ( offset < this.data.length ) {
 652+ tx.pushRetain( this.data.length - offset );
 653+ }
615654 };
616655
617656 /**
Index: trunk/parsers/wikidom/lib/hype/es.Transaction.js
@@ -32,56 +32,29 @@
3333 } );
3434 };
3535
36 -es.Transaction.prototype.pushSetElementAttribute( key, value ) {
 36+es.Transaction.prototype.pushChangeElementAttribute( method, key, value ) {
3737 this.push( {
3838 'type': 'attribute',
39 - 'method': 'set',
 39+ 'method': method,
4040 'key': key,
4141 'value': value
4242 } );
4343 };
4444
45 -es.Transaction.prototype.pushClearElementAttribute( key, value ) {
 45+es.Transaction.prototype.pushStartAnnotating( method, annotation ) {
4646 this.push( {
47 - 'type': 'attribute',
48 - 'method': 'clear',
49 - 'key': key,
50 - 'value': value
51 - } );
52 -};
53 -
54 -es.Transaction.prototype.pushStartSettingAnnotation( annotation ) {
55 - this.push( {
5647 'type': 'annotate',
57 - 'method': 'set',
 48+ 'method': method,
5849 'bias': 'start',
5950 'annotation': annotation
6051 } );
6152 };
6253
63 -es.Transaction.prototype.pushStopSettingAnnotation( annotation ) {
 54+es.Transaction.prototype.pushStopAnnotating( method, annotation ) {
6455 this.push( {
6556 'type': 'annotate',
66 - 'method': 'set',
 57+ 'method': method,
6758 'bias': 'stop',
6859 'annotation': annotation
6960 } );
7061 };
71 -
72 -es.Transaction.prototype.pushStartClearingAnnotation( annotation ) {
73 - this.push( {
74 - 'type': 'annotate',
75 - 'method': 'clear',
76 - 'bias': 'start',
77 - 'annotation': annotation
78 - } );
79 -};
80 -
81 -es.Transaction.prototype.pushStopClearingAnnotation( annotation ) {
82 - this.push( {
83 - 'type': 'annotate',
84 - 'method': 'clear',
85 - 'bias': 'stop',
86 - 'annotation': annotation
87 - } );
88 -};

Status & tagging log