r60957 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60956‎ | r60957 | r60958 >
Date:01:03, 12 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Added check for validity of context.data.outline before using it.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -381,35 +381,37 @@
382382 // This is based on Linker::generateTOC(), so it should behave like the
383383 // TOC on rendered articles does - which is considdered to be correct
384384 // at this point in time.
385 - var outline = context.data.outline;
386 - var lastLevel = 0;
387 - var nLevel = 0;
388 - for ( var i = 0; i < outline.length; i++ ) {
389 - if ( outline[i].level > lastLevel ) {
390 - nLevel++;
 385+ if ( context.data.outline ) {
 386+ var outline = context.data.outline;
 387+ var lastLevel = 0;
 388+ var nLevel = 0;
 389+ for ( var i = 0; i < outline.length; i++ ) {
 390+ if ( outline[i].level > lastLevel ) {
 391+ nLevel++;
 392+ }
 393+ else if ( outline[i].level < lastLevel ) {
 394+ nLevel -= Math.max( 1, lastLevel - outline[i].level );
 395+ }
 396+ if ( nLevel <= 0 ) {
 397+ nLevel = 1;
 398+ }
 399+ outline[i].nLevel = nLevel;
 400+ lastLevel = outline[i].level;
391401 }
392 - else if ( outline[i].level < lastLevel ) {
393 - nLevel -= Math.max( 1, lastLevel - outline[i].level );
 402+ // Recursively build the structure and add special item for
 403+ // section 0, if needed
 404+ var structure = buildStructure( outline );
 405+ if ( $( 'input[name=wpSection]' ).val() == '' ) {
 406+ structure.unshift( { 'text': wgPageName.replace(/_/g, ' '), 'level': 1, 'index': 0 } );
394407 }
395 - if ( nLevel <= 0 ) {
396 - nLevel = 1;
 408+ context.modules.toc.$toc.html( buildList( structure ) );
 409+
 410+ if ( wgNavigableTOCResizable && !context.$ui.data( 'resizableDone' ) ) {
 411+ buildResizeControls();
 412+ buildCollapseControls();
397413 }
398 - outline[i].nLevel = nLevel;
399 - lastLevel = outline[i].level;
 414+ context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true } );
400415 }
401 - // Recursively build the structure and add special item for
402 - // section 0, if needed
403 - var structure = buildStructure( outline );
404 - if ( $( 'input[name=wpSection]' ).val() == '' ) {
405 - structure.unshift( { 'text': wgPageName.replace(/_/g, ' '), 'level': 1, 'index': 0 } );
406 - }
407 - context.modules.toc.$toc.html( buildList( structure ) );
408 -
409 - if ( wgNavigableTOCResizable && !context.$ui.data( 'resizableDone' ) ) {
410 - buildResizeControls();
411 - buildCollapseControls();
412 - }
413 - context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true } );
414416 }
415417 }
416418

Status & tagging log