Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js |
— | — | @@ -381,35 +381,37 @@ |
382 | 382 | // This is based on Linker::generateTOC(), so it should behave like the |
383 | 383 | // TOC on rendered articles does - which is considdered to be correct |
384 | 384 | // 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; |
391 | 401 | } |
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 } ); |
394 | 407 | } |
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(); |
397 | 413 | } |
398 | | - outline[i].nLevel = nLevel; |
399 | | - lastLevel = outline[i].level; |
| 414 | + context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true } ); |
400 | 415 | } |
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 } ); |
414 | 416 | } |
415 | 417 | } |
416 | 418 | |