r94921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94920‎ | r94921 | r94922 >
Date:18:56, 18 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Implement annotateContent for ListBlock (for single item and for multiple items)
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -252,6 +252,78 @@
253253 }
254254 };
255255
 256+/**
 257+ * Applies an annotation to a given range.
 258+ *
 259+ * If a range arguments are not provided, all content will be annotated.
 260+ *
 261+ * @method
 262+ * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
 263+ * @param annotation {Object} Annotation to apply
 264+ * @param range {es.Range} Range of content to annotate
 265+ */
 266+es.ListBlock.prototype.annotateContent = function( method, annotation, range ) {
 267+ range.normalize();
 268+
 269+ var locationStart = this.getLocationFromOffset( range.start ),
 270+ locationEnd = this.getLocationFromOffset( range.end );
 271+
 272+ if ( locationStart.item == locationEnd.item ) {
 273+ // annotate content within one item
 274+ locationStart.item.content.annotate(
 275+ method,
 276+ annotation,
 277+ new es.Range(
 278+ locationStart.offset,
 279+ locationStart.offset + range.end - range.start
 280+ )
 281+ );
 282+ } else {
 283+ // annotate content across multiple items
 284+
 285+ // annotate content in the first item - from offset to end
 286+ locationStart.item.content.annotate(
 287+ method,
 288+ annotation,
 289+ new es.Range(
 290+ locationStart.offset,
 291+ locationStart.item.content.getLength()
 292+ )
 293+ );
 294+
 295+ // annotate content in the last item - from beginning to offset
 296+ locationEnd.item.content.annotate(
 297+ method,
 298+ annotation,
 299+ new es.Range(
 300+ 0,
 301+ locationEnd.offset
 302+ )
 303+ );
 304+
 305+ // annotate all content in selected items except first and last one
 306+ var annotating = false;
 307+ for ( var i = 0; i < this.list.items.length; i++ ) {
 308+ if ( this.list.items[i] === locationStart.item ) {
 309+ annotating = true;
 310+ continue;
 311+ } else if ( this.list.items[i] === locationEnd.item ) {
 312+ break;
 313+ }
 314+ if ( annotating ) {
 315+ this.list.items[i].content.annotate(
 316+ method,
 317+ annotation,
 318+ new es.Range(
 319+ 0,
 320+ this.list.items[i].content.getLength()
 321+ )
 322+ );
 323+ }
 324+ }
 325+ }
 326+};
 327+
256328 es.ListBlock.prototype.getText = function( range, render ) {
257329 return "";
258330 };

Status & tagging log