r103496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103495‎ | r103496 | r103497 >
Date:19:19, 17 November 2011
Author:tparscal
Status:ok
Tags:
Comment:
Added documentation to getScope and made it a little less confusing to read
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js
@@ -113,19 +113,30 @@
114114 }
115115 };
116116
 117+/**
 118+ * Get the parent node that would be affected by inserting given data into it's child.
 119+ *
 120+ * This is used when inserting data that closes and reopens one or more parent nodes into a child
 121+ * node, which requires rebuilding at a higher level.
 122+ *
 123+ * @method
 124+ * @param {es.DocumentNode} node Child node to start from
 125+ * @param {Array} data Data to inspect for closings
 126+ * @returns {es.DocumentNode} Lowest level parent node being affected
 127+ */
117128 es.TransactionProcessor.prototype.getScope = function( node, data ) {
118129 var i,
119130 length,
120131 level = 0,
121 - maxDepth = 0;
 132+ max = 0;
122133 for ( i = 0, length = data.length; i < length; i++ ) {
123134 if ( typeof data[i].type === 'string' ) {
124 - level += data[i].type.charAt( 0 ) === '/' ? -1 : 1;
125 - maxDepth = Math.max( maxDepth, -level );
 135+ level += data[i].type.charAt( 0 ) === '/' ? 1 : -1;
 136+ max = Math.max( max, level );
126137 }
127138 }
128 - if ( maxDepth > 0 ) {
129 - for ( i = 0; i < maxDepth - 1; i++ ) {
 139+ if ( max > 0 ) {
 140+ for ( i = 0; i < max - 1; i++ ) {
130141 node = node.getParent();
131142 }
132143 }

Status & tagging log