Sha256: 65ed5528f62d01ef44a029ebe950402dc876887e410b89fb8aac907a0e131dd5

Contents?: true

Size: 1.33 KB

Versions: 38

Compression:

Stored size: 1.33 KB

Contents

wait = ->
  $.ajax
    url: window.location.pathname + '/wait'
    dataType: 'json'
    timeout: 29 * 1000
    success: ->
      $.get window.location.pathname + '.js', (html)->
        $('#book').html html
        initMathJax()
        initNavOffset()
        wait()
    error: (jqXHR, textStatus)->
      if textStatus == 'timeout'
        # polling end, reconnect immediately
        wait()
      else
        # server down, try reconnecting again after timeout
        setTimeout wait, 5000

initMathJax = ->
  $('#mathJaxJS').remove()
  delete MathJax

  chapter_number = $('.chapter').attr('data-number')

  script = document.createElement( 'script' )
  script.id = 'mathJaxJS'
  script.type = 'text/javascript'
  script.src = '<%= @mathjax_src %>'
  script.innerHTML = """
    <%= @mathjax_config %>
    """

  $('head').append script

delay = 1000
initNavOffset = ->
  loading = true
  finish = _.debounce ->
    loading = false
  , delay

  offset = 20
  navHeight = $('#bookMenu').height() + offset
  $(window).scroll ->
    if loading
      offset = $(window.location.hash).offset().top - navHeight
      $(window).scrollTop offset
      finish()

  $(window).bind 'hashchange', (e)->
    e.preventDefault()
    offset = $(window.location.hash).offset().top - navHeight
    $(window).scrollTop offset

$ ->
  initMathJax()
  initNavOffset()
  wait()

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
softcover-1.2.10 lib/softcover/server/views/main.js.erb
softcover-1.2.9 lib/softcover/server/views/main.js.erb
softcover-1.2.8 lib/softcover/server/views/main.js.erb
softcover-1.2.7 lib/softcover/server/views/main.js.erb
softcover-1.2.6 lib/softcover/server/views/main.js.erb
softcover-1.2.5 lib/softcover/server/views/main.js.erb
softcover-1.2.4 lib/softcover/server/views/main.js.erb
softcover-1.2.3 lib/softcover/server/views/main.js.erb
softcover-1.2.2 lib/softcover/server/views/main.js.erb
softcover-1.2.1 lib/softcover/server/views/main.js.erb
softcover-1.2.0 lib/softcover/server/views/main.js.erb
softcover-1.1.28 lib/softcover/server/views/main.js.erb
softcover-1.1.27 lib/softcover/server/views/main.js.erb
softcover-1.1.23 lib/softcover/server/views/main.js.erb
softcover-1.1.22 lib/softcover/server/views/main.js.erb
softcover-1.1.21 lib/softcover/server/views/main.js.erb
softcover-1.1.20 lib/softcover/server/views/main.js.erb
softcover-1.1.19 lib/softcover/server/views/main.js.erb
softcover-1.1.18 lib/softcover/server/views/main.js.erb
softcover-1.1.17 lib/softcover/server/views/main.js.erb