2014-05-20 18:31:49 -04:00
|
|
|
Backbone.Mediator.setValidationEnabled false
|
2014-01-03 13:32:13 -05:00
|
|
|
app = require 'application'
|
|
|
|
|
2014-04-11 08:37:08 -04:00
|
|
|
channelSchemas =
|
2014-08-27 15:24:03 -04:00
|
|
|
'auth': require './schemas/subscriptions/auth'
|
2014-04-11 14:09:50 -04:00
|
|
|
'bus': require './schemas/subscriptions/bus'
|
|
|
|
'editor': require './schemas/subscriptions/editor'
|
|
|
|
'errors': require './schemas/subscriptions/errors'
|
|
|
|
'misc': require './schemas/subscriptions/misc'
|
|
|
|
'play': require './schemas/subscriptions/play'
|
|
|
|
'surface': require './schemas/subscriptions/surface'
|
|
|
|
'tome': require './schemas/subscriptions/tome'
|
2014-08-27 15:24:03 -04:00
|
|
|
'god': require './schemas/subscriptions/god'
|
|
|
|
'scripts': require './schemas/subscriptions/scripts'
|
2014-08-28 12:27:42 -04:00
|
|
|
'world': require './schemas/subscriptions/world'
|
2014-04-11 08:37:08 -04:00
|
|
|
|
|
|
|
definitionSchemas =
|
|
|
|
'bus': require './schemas/definitions/bus'
|
|
|
|
'misc': require './schemas/definitions/misc'
|
|
|
|
|
2014-02-24 14:12:52 -05:00
|
|
|
init = ->
|
2014-07-13 11:37:39 -04:00
|
|
|
watchForErrors()
|
2014-06-16 13:42:13 -04:00
|
|
|
path = document.location.pathname
|
|
|
|
testing = path.startsWith '/test'
|
|
|
|
demoing = path.startsWith '/demo'
|
|
|
|
initializeServices() unless testing or demoing
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-06-16 06:55:58 -04:00
|
|
|
# Set up Backbone.Mediator schemas
|
2014-05-20 18:31:49 -04:00
|
|
|
setUpDefinitions()
|
|
|
|
setUpChannels()
|
2014-05-20 18:58:41 -04:00
|
|
|
Backbone.Mediator.setValidationEnabled document.location.href.search(/codecombat.com/) is -1
|
2014-01-03 13:32:13 -05:00
|
|
|
app.initialize()
|
|
|
|
Backbone.history.start({ pushState: true })
|
|
|
|
handleNormalUrls()
|
2014-07-30 17:19:21 -04:00
|
|
|
setUpMoment() # Set up i18n for moment
|
2014-02-24 14:12:52 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
treemaExt = require 'treema-ext'
|
|
|
|
treemaExt.setup()
|
|
|
|
|
|
|
|
handleNormalUrls = ->
|
|
|
|
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
|
2014-06-30 22:16:26 -04:00
|
|
|
$(document).on 'click', "a[href^='/']", (event) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
href = $(event.currentTarget).attr('href')
|
|
|
|
|
|
|
|
# chain 'or's for other black list routes
|
|
|
|
passThrough = href.indexOf('sign_out') >= 0
|
|
|
|
|
|
|
|
# Allow shift+click for new tabs, etc.
|
|
|
|
if !passThrough && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
# Remove leading slashes and hash bangs (backward compatablility)
|
|
|
|
url = href.replace(/^\//,'').replace('\#\!\/','')
|
|
|
|
|
|
|
|
# Instruct Backbone to trigger routing events
|
|
|
|
app.router.navigate url, { trigger: true }
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
2014-04-11 09:00:16 -04:00
|
|
|
setUpChannels = ->
|
2014-04-11 08:37:08 -04:00
|
|
|
for channel of channelSchemas
|
|
|
|
Backbone.Mediator.addChannelSchemas channelSchemas[channel]
|
|
|
|
|
2014-04-11 09:00:16 -04:00
|
|
|
setUpDefinitions = ->
|
2014-04-11 08:37:08 -04:00
|
|
|
for definition of definitionSchemas
|
2014-05-29 05:37:35 -04:00
|
|
|
Backbone.Mediator.addDefSchemas definitionSchemas[definition]
|
2014-06-15 17:19:37 -04:00
|
|
|
|
2014-07-30 17:19:21 -04:00
|
|
|
setUpMoment = ->
|
|
|
|
{me} = require 'lib/auth'
|
|
|
|
moment.lang me.lang(), {}
|
|
|
|
me.on 'change', (me) ->
|
|
|
|
moment.lang me.lang(), {} if me._previousAttributes.preferredLanguage isnt me.get 'preferredLanguage'
|
|
|
|
|
2014-06-16 13:42:13 -04:00
|
|
|
initializeServices = ->
|
|
|
|
services = [
|
|
|
|
'./lib/services/filepicker'
|
|
|
|
'./lib/services/segmentio'
|
|
|
|
'./lib/services/olark'
|
|
|
|
'./lib/services/facebook'
|
|
|
|
'./lib/services/google'
|
|
|
|
'./lib/services/twitter'
|
|
|
|
'./lib/services/linkedin'
|
|
|
|
]
|
|
|
|
|
|
|
|
for service in services
|
|
|
|
service = require service
|
|
|
|
service()
|
2014-07-13 11:37:39 -04:00
|
|
|
|
|
|
|
watchForErrors = ->
|
|
|
|
currentErrors = 0
|
|
|
|
window.onerror = (msg, url, line, col, error) ->
|
|
|
|
return if currentErrors >= 3
|
|
|
|
return unless me.isAdmin() or document.location.href.search(/codecombat.com/) is -1 or document.location.href.search(/\/editor\//) isnt -1
|
|
|
|
++currentErrors
|
|
|
|
msg = "Error: #{msg}<br>Check the JS console for more."
|
|
|
|
#msg += "\nLine: #{line}" if line?
|
|
|
|
#msg += "\nColumn: #{col}" if col?
|
|
|
|
#msg += "\nError: #{error}" if error?
|
|
|
|
#msg += "\nStack: #{stack}" if stack = error?.stack
|
|
|
|
noty text: msg, layout: 'topCenter', type: 'error', killer: false, timeout: 5000, dismissQueue: true, maxVisible: 3, callback: {onClose: -> --currentErrors}
|
2014-07-23 10:02:45 -04:00
|
|
|
|
2014-07-30 17:19:21 -04:00
|
|
|
$ -> init()
|