Sha256: a8e042d477eed5315f161b8ec7178c4c9d42a2cffcf7f539c2cb7ad08b04b1be

Contents?: true

Size: 881 Bytes

Versions: 8

Compression:

Stored size: 881 Bytes

Contents

#= require jquery.pjax

class AssessmentNotification
  constructor: ->
    @enable()

  enable: ->
    $(document).on "submit", "form[data-pjax]", (event) ->
      $.pjax.submit event, "[data-pjax-container]"

    $(window).on "beforeunload", =>
      @sendNotification()

    $(window).on "unload", =>
      @sendNotification()

    $(document).on "pjax:popstate", (event) ->
      event.preventDefault() if event.direction == "back"

  disable: ->
    $(document).off "submit", "form[data-pjax]"

    $(window).off("beforeunload").off("unload")

  sendNotification: ->
    unless @_sentNotification
      $.ajax window.location.href + "/notification", method: "POST", async: false
      @_sentNotification = true
    `void(0)`

  _sentNotification: false

$ ->
  if $("form[data-pjax]").length and $.support.pjax
    window.assessmentNotification = new AssessmentNotification()

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
study_engine-0.3.1 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.3.0 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.2.2 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.2.1 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.2.0 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.1.1 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.1.0 app/assets/javascripts/study_engine/assessment_notifications.js.coffee
study_engine-0.0.2 app/assets/javascripts/study_engine/assessment_notifications.js.coffee