r94203 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94202‎ | r94203 | r94204 >
Date:21:54, 10 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Deleting content across multiple items in lists with adopting orphaned items
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -109,14 +109,23 @@
110110 toAdopt = [],
111111 newParents = [],
112112 toDeleteCollecting = false,
113 - toAdoptCollecting = false;
 113+ toAdoptCollecting = false,
 114+ itemLevel,
 115+ toAdoptLevel,
 116+ newParent,
 117+ startItemLevel = locationStart.item.getLevel();
114118
115119 this.traverseItems( function( item, index ) {
 120+ itemLevel = item.getLevel();
116121
117122 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 );
119128 }
120 -
 129+
121130 if ( toDeleteCollecting ) {
122131 toDelete.push( item );
123132 }
@@ -139,17 +148,23 @@
140149
141150 } );
142151
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++ ) {
147153 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+ }
150165 }
151 -
 166+
152167 for ( var i = toDelete.length - 1; i >= 0; i-- ) {
153 - toDelete[i].list.remove(toDelete[i]);
 168+ toDelete[i].list.remove( toDelete[i] );
154169 }
155170 }
156171 };

Status & tagging log