Sha256: 41e4d0122f97e75ffccb9dbb4f6c6b6275586c1d94b3cbacff3088b7fdfefc60

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

$ ->

  #
  # Create file TOC from the headings
  #
  $('#filecontents').each ->
    nav = $('nav.toc')
    target = nav
    level = 0
    ancestors = []

    for heading, index in $('h2,h3,h4,h5,h6', @)
      heading = $(heading)
      heading.before $("<a name='toc_#{ index }'></a>")

      depth = parseInt heading.get(0).tagName.substring(1)

      # Create a nested list
      if depth > level
        list = $('<ol></ol>')
        target.append list
        ancestors.push target

        target = list
        level = depth

      # Go up one list level
      else if depth < level
        target = ancestors.pop() for i in [0...level - depth]
        target = $('nav.toc ol:first') unless target
        level = depth

      target.append $("<li><a href='#toc_#{ index }'>#{ heading.text() }</a></li>")

    nav.hide() if $('ol', nav).length is 0

  #
  # Toggle the TOC visibility
  #
  $('a.hide_toc').click -> $('nav.toc').toggleClass 'hidden'

  #
  # Toggle the float position status between floating and inline
  #
  $('a.float_toc').click ->
    $('nav.toc').toggleClass 'inline'
    $(@).text if $('nav.toc').hasClass 'inline' then 'float' else 'left'

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.5 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.4 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.3 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.2 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.1 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.1.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-4.0.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.4.3 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.4.2 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.4.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.3.1 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.3.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.2.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.1.1 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.1.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-3.0.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-2.0.0 node_modules/codo/themes/default/assets/javascript/toc.coffee
ela-1.1.0 node_modules/codo/themes/default/assets/javascript/toc.coffee