codecombat/app/initialize.coffee

82 lines
2.4 KiB
CoffeeScript
Raw Normal View History

Backbone.Mediator.setValidationEnabled false
2014-01-03 13:32:13 -05:00
app = require 'application'
channelSchemas =
'app': require './schemas/subscriptions/app'
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'
'user': require './schemas/subscriptions/user'
'world': require './schemas/subscriptions/world'
definitionSchemas =
'bus': require './schemas/definitions/bus'
'misc': require './schemas/definitions/misc'
init = ->
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
setUpDefinitions()
setUpChannels()
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-01-03 13:32:13 -05:00
treemaExt = require 'treema-ext'
treemaExt.setup()
$ -> init()
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
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
setUpChannels = ->
for channel of channelSchemas
Backbone.Mediator.addChannelSchemas channelSchemas[channel]
setUpDefinitions = ->
for definition of definitionSchemas
Backbone.Mediator.addDefSchemas definitionSchemas[definition]
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()