Sha256: eb622f54fd2949f14c7bc65c2a0276ea85f8ea84c3fe1f2345f982f04e06f1e1

Contents?: true

Size: 1.33 KB

Versions: 80

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

80 entries across 80 versions & 2 rubygems

Version Path
softcover-1.0.5 lib/softcover/server/views/main.js.erb
softcover-1.0.4 lib/softcover/server/views/main.js.erb
softcover-1.0.3 lib/softcover/server/views/main.js.erb
softcover-1.0.2 lib/softcover/server/views/main.js.erb
softcover-1.0.1 lib/softcover/server/views/main.js.erb
softcover-1.0.0 lib/softcover/server/views/main.js.erb
softcover-1.0.beta17 lib/softcover/server/views/main.js.erb
softcover-1.0.beta16 lib/softcover/server/views/main.js.erb
softcover-1.0.beta15 lib/softcover/server/views/main.js.erb
softcover-1.0.beta14 lib/softcover/server/views/main.js.erb
softcover-1.0.beta13 lib/softcover/server/views/main.js.erb
softcover-1.0.beta12 lib/softcover/server/views/main.js.erb
softcover-1.0.beta11 lib/softcover/server/views/main.js.erb
softcover-1.0.beta10 lib/softcover/server/views/main.js.erb
softcover-1.0.beta9 lib/softcover/server/views/main.js.erb
softcover-1.0.beta8 lib/softcover/server/views/main.js.erb
softcover-1.0.beta7 lib/softcover/server/views/main.js.erb
softcover-1.0.beta6 lib/softcover/server/views/main.js.erb
softcover-1.0.beta5 lib/softcover/server/views/main.js.erb
softcover-1.0.beta4 lib/softcover/server/views/main.js.erb