Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js |
— | — | @@ -14,6 +14,14 @@ |
15 | 15 | } |
16 | 16 | }; |
17 | 17 | |
| 18 | +es.ListBlockList.prototype.traverseItems = function( callback ) { |
| 19 | + for( var i = 0; i < this.items.length; i++ ) { |
| 20 | + if ( callback( this.items[i], i ) === false ) { |
| 21 | + return false; |
| 22 | + } |
| 23 | + } |
| 24 | +}; |
| 25 | + |
18 | 26 | es.ListBlockList.flattenList = function( wikidomList, items, level ) { |
19 | 27 | for ( var i = 0; i < wikidomList.items.length; i++ ) { |
20 | 28 | items.push( |
Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -57,28 +57,30 @@ |
58 | 58 | } else if ( position.top >= this.$.height() ) { |
59 | 59 | return this.getLength(); |
60 | 60 | } |
61 | | - |
62 | | - var globalOffset = 0, |
63 | | - i, |
| 61 | + |
| 62 | + var offset = 0, |
64 | 63 | itemOffset, |
65 | 64 | itemHeight, |
66 | 65 | blockOffset = this.$.offset(); |
67 | 66 | |
68 | 67 | position.top += blockOffset.top; |
69 | 68 | position.left += blockOffset.left; |
70 | | - |
71 | | - for( i = 0; i < this.list.items.length; i++ ) { |
72 | | - itemOffset = this.list.items[i].$content.offset(); |
73 | | - itemHeight = this.list.items[i].$content.height(); |
74 | | - |
| 69 | + |
| 70 | + this.list.traverseItems( function( item, index ) { |
| 71 | + itemOffset = item.$content.offset(); |
| 72 | + itemHeight = item.$content.height(); |
| 73 | + |
75 | 74 | if ( position.top >= itemOffset.top && position.top < itemOffset.top + itemHeight ) { |
76 | 75 | position.top -= itemOffset.top; |
77 | 76 | position.left -= itemOffset.left; |
78 | | - return globalOffset + this.list.items[i].flow.getOffset( position ); |
| 77 | + offset += item.flow.getOffset( position ); |
| 78 | + return false; |
79 | 79 | } |
80 | 80 | |
81 | | - globalOffset += this.list.items[i].content.getLength() + 1; |
82 | | - } |
| 81 | + offset += item.content.getLength() + 1; |
| 82 | + } ); |
| 83 | + |
| 84 | + return offset; |
83 | 85 | }; |
84 | 86 | |
85 | 87 | /** |
— | — | @@ -90,28 +92,25 @@ |
91 | 93 | */ |
92 | 94 | es.ListBlock.prototype.getPosition = function( offset ) { |
93 | 95 | var globalOffset = 0, |
94 | | - i, |
95 | 96 | itemLength, |
96 | 97 | position, |
97 | | - contentOffset, |
98 | 98 | blockOffset = this.$.offset(); |
99 | 99 | |
100 | | - for( i = 0; i < this.list.items.length; i++ ) { |
101 | | - itemLength = this.list.items[i].content.getLength(); |
| 100 | + this.list.traverseItems( function( item, index ) { |
| 101 | + itemLength = item.content.getLength(); |
102 | 102 | if ( offset >= globalOffset && offset < globalOffset + itemLength ) { |
103 | | - position = this.list.items[i].flow.getPosition( offset - globalOffset ); |
104 | | - contentOffset = this.list.items[i].$content.offset(); |
105 | | - |
| 103 | + position = item.flow.getPosition( offset - globalOffset ); |
| 104 | + contentOffset = item.$content.offset(); |
106 | 105 | position.top += contentOffset.top - blockOffset.top; |
107 | 106 | position.left += contentOffset.left - blockOffset.left; |
108 | 107 | position.bottom += contentOffset.top - blockOffset.top; |
109 | | - |
110 | | - position.line = i; |
111 | | - |
112 | | - return position; |
| 108 | + position.line = index; |
| 109 | + return false; |
113 | 110 | } |
114 | 111 | globalOffset += itemLength + 1; |
115 | | - } |
| 112 | + } ); |
| 113 | + |
| 114 | + return position; |
116 | 115 | }; |
117 | 116 | |
118 | 117 | /* Registration */ |