main.coffee 925 Bytes
Newer Older
1
AjaxPrefix.addAjaxPrefix(jQuery, -> CMS.prefix)
2

3 4 5 6
@CMS =
  Models: {}
  Views: {}

7 8
  prefix: $("meta[name='path_prefix']").attr('content')

9 10 11
_.extend CMS, Backbone.Events

$ ->
12 13
  Backbone.emulateHTTP = true

14
  $.ajaxSetup
15
    headers : { 'X-CSRFToken': $.cookie 'csrftoken' }
16
    dataType: 'json'
17

18
  $(document).ajaxError (event, jqXHR, ajaxSettings, thrownError) ->
19 20
    if ajaxSettings.notifyOnError is false
      return
21 22 23 24 25 26
    msg = new CMS.Models.ErrorMessage(
        "title": gettext("Studio's having trouble saving your work")
        "message": jqXHR.responseText || gettext("This may be happening because of an error with our server or your internet connection. Try refreshing the page or making sure you are online.")
    )
    new CMS.Views.Notification({model: msg})

27 28 29 30
  window.onTouchBasedDevice = ->
    navigator.userAgent.match /iPhone|iPod|iPad/i

  $('body').addClass 'touch-based-device' if onTouchBasedDevice()