Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -109,14 +109,23 @@ |
110 | 110 | toAdopt = [], |
111 | 111 | newParents = [], |
112 | 112 | toDeleteCollecting = false, |
113 | | - toAdoptCollecting = false; |
| 113 | + toAdoptCollecting = false, |
| 114 | + itemLevel, |
| 115 | + toAdoptLevel, |
| 116 | + newParent, |
| 117 | + startItemLevel = locationStart.item.getLevel(); |
114 | 118 | |
115 | 119 | this.traverseItems( function( item, index ) { |
| 120 | + itemLevel = item.getLevel(); |
116 | 121 | |
117 | 122 | if ( toDeleteCollecting === false && toDelete.length === 0 ) { |
118 | | - newParents[ item.getLevel() ] = item; |
| 123 | + newParents[ itemLevel ] = { |
| 124 | + item: item, |
| 125 | + firstChild: item.lists[0] ? item.lists[0].first() : null |
| 126 | + }; |
| 127 | + newParents = newParents.slice( 0, itemLevel + 1 ); |
119 | 128 | } |
120 | | - |
| 129 | + |
121 | 130 | if ( toDeleteCollecting ) { |
122 | 131 | toDelete.push( item ); |
123 | 132 | } |
— | — | @@ -139,17 +148,23 @@ |
140 | 149 | |
141 | 150 | } ); |
142 | 151 | |
143 | | - var toAdoptLevel, |
144 | | - newParent; |
145 | | - |
146 | | - for ( var i = toAdopt.length - 1; i >= 0; i-- ) { |
| 152 | + for ( var i = 0; i < toAdopt.length; i++ ) { |
147 | 153 | toAdoptLevel = toAdopt[i].getLevel(); |
148 | | - newParent = newParents[ toAdoptLevel ] ? newParents[ toAdoptLevel ] : newParents[ newParents.length - 1 ]; |
149 | | - newParent.lists[0].prepend( toAdopt[i] ); |
| 154 | + newParent = newParents[ toAdoptLevel - 1 ] ? newParents[ toAdoptLevel -1 ] : newParents[ newParents.length - 1 ]; |
| 155 | + |
| 156 | + if( newParent.firstChild && toAdoptLevel > startItemLevel ) { |
| 157 | + newParent.item.lists[0].insertBefore( toAdopt[i], newParent.firstChild ); |
| 158 | + } else { |
| 159 | + if ( newParent.item.lists[0] ) { |
| 160 | + newParent.item.lists[0].append( toAdopt[i] ); |
| 161 | + } else { |
| 162 | + newParent.item.append( new es.ListBlockList( toAdopt[i].list.style, [ toAdopt[i] ] ) ); |
| 163 | + } |
| 164 | + } |
150 | 165 | } |
151 | | - |
| 166 | + |
152 | 167 | for ( var i = toDelete.length - 1; i >= 0; i-- ) { |
153 | | - toDelete[i].list.remove(toDelete[i]); |
| 168 | + toDelete[i].list.remove( toDelete[i] ); |
154 | 169 | } |
155 | 170 | } |
156 | 171 | }; |