r93226 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93225‎ | r93226 | r93227 >
Date:17:53, 26 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Made tree traversal functionality generic
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -43,22 +43,32 @@
4444 position.left += lineOffset.left - blockOffset.left;
4545 position.bottom += lineOffset.top - blockOffset.top;
4646
 47+ this.traverseItems( function( item ) {
 48+ if ( item === location.item ) {
 49+ return false;
 50+ }
 51+ position.line += item.flow.lines.length;
 52+ } );
 53+ return position;
 54+};
 55+
 56+es.ListBlock.prototype.traverseItems = function( callback ) {
4757 // Recursively walk the tree of list items and their lists, depth first, until we get to the
4858 // same item as location.item, incrementing position.line for each line that occurs before it
4959 var stack = [{ 'list': this.list, 'index': 0 }],
5060 list,
5161 item,
5262 pop,
53 - parent;
 63+ parent,
 64+ index = 0;
5465 while ( stack.length ) {
5566 iteration = stack[stack.length - 1];
5667 pop = true;
5768 while ( iteration.index < iteration.list.items.length ) {
5869 item = iteration.list.items[iteration.index++];
59 - if ( item === location.item ) {
60 - return position;
 70+ if ( callback( item, index++ ) === false ) {
 71+ return false;
6172 }
62 - position.line += item.flow.lines.length;
6373 if ( item.lists.length ) {
6474 parent = stack.length;
6575 for ( var i = 0; i < item.lists.length; i++ ) {
@@ -76,7 +86,7 @@
7787 }
7888 }
7989 }
80 - return position;
 90+ return true;
8191 };
8292
8393 es.ListBlock.prototype.getOffset = function( position ) {

Status & tagging log