r99122 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99121‎ | r99122 | r99123 >
Date:17:18, 6 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved indexOfAnnotation code to es.DocumentModel.getIndexOfAnnotation, so other methods can use it
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -96,19 +96,6 @@
9797 this.data.splice( this.cursor, op.data.length );
9898 }
9999
100 - function indexOfAnnotation( character, annotation ) {
101 - if ( $.isArray( character ) ) {
102 - // Find the index of a comparable annotation (checking for same value, not reference)
103 - var index;
104 - for ( var i = 0; i < character.length; i++ ) {
105 - if ( character[i].hash === op.annotation.hash ) {
106 - return index;
107 - }
108 - }
109 - }
110 - return -1;
111 - }
112 -
113100 function attribute( op, invert ) {
114101 var element = this.data[this.cursor];
115102 if ( element.type === undefined ) {
@@ -158,7 +145,7 @@
159146 for ( var i = 0, length = this.clear.length; i < length; i++ ) {
160147 var annotation = this.clear[i];
161148 for ( var j = this.cursor; j < to; j++ ) {
162 - var index = indexOfAnnotation( this.data[j], annotation );
 149+ var index = es.DocumentModel.getIndexOfAnnotation( this.data[j], annotation );
163150 if ( index !== -1 ) {
164151 this.data[j].splice( index, 1 );
165152 }
@@ -181,7 +168,7 @@
182169 if ( op.bias === 'start' ) {
183170 target.push( op.annotation );
184171 } else if ( op.bias === 'end' ) {
185 - var index = indexOfAnnotation( target[i], op.annotation );
 172+ var index = es.DocumentModel.getIndexOfAnnotation( target[i], op.annotation );
186173 if ( index === -1 ) {
187174 throw 'Annotation stack error. Annotation is missing.';
188175 }
@@ -271,6 +258,19 @@
272259 return hash;
273260 };
274261
 262+es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) {
 263+ if ( $.isArray( character ) ) {
 264+ // Find the index of a comparable annotation (checking for same value, not reference)
 265+ var index;
 266+ for ( var i = 0; i < character.length; i++ ) {
 267+ if ( character[i].hash === op.annotation.hash ) {
 268+ return index;
 269+ }
 270+ }
 271+ }
 272+ return -1;
 273+};
 274+
275275 /**
276276 * Creates an es.ContentModel object from a plain content object.
277277 *

Status & tagging log