codecombat/app/application.coffee

65 lines
2.6 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
FacebookHandler = require 'lib/FacebookHandler'
GPlusHandler = require 'lib/GPlusHandler'
2014-04-23 14:25:36 -04:00
LinkedInHandler = require 'lib/LinkedInHandler'
locale = require 'locale/locale' # TODO: don't require all of these? Might be slow. (Haven't checked.)
2014-01-03 13:32:13 -05:00
{me} = require 'lib/auth'
Tracker = require 'lib/Tracker'
2014-01-07 00:25:18 -05:00
CocoView = require 'views/kinds/CocoView'
2014-01-03 13:32:13 -05:00
marked.setOptions {gfm: true, sanitize: true, smartLists: true, breaks: false}
# TODO, add C-style macro constants like this?
window.SPRITE_RESOLUTION_FACTOR = 4
# Prevent Ctrl/Cmd + [ / ], P, S
ctrlDefaultPrevented = [219, 221, 80, 83]
preventBackspace = (event) ->
if event.keyCode is 8 and not elementAcceptsKeystrokes(event.srcElement or event.target)
event.preventDefault()
else if (key.ctrl or key.command) and not key.alt and event.keyCode in ctrlDefaultPrevented
event.preventDefault()
elementAcceptsKeystrokes = (el) ->
# http://stackoverflow.com/questions/1495219/how-can-i-prevent-the-backspace-key-from-navigating-back
el ?= document.activeElement
tag = el.tagName.toLowerCase()
type = el.type?.toLowerCase()
textInputTypes = ['text', 'password', 'file', 'number', 'search', 'url', 'tel', 'email', 'date', 'month', 'week', 'time', 'datetimelocal']
# not radio, checkbox, range, or color
2014-06-30 22:16:26 -04:00
return (tag is 'textarea' or (tag is 'input' and type in textInputTypes) or el.contentEditable in ['', 'true']) and not (el.readOnly or el.disabled)
2014-05-12 19:45:12 -04:00
COMMON_FILES = ['/images/pages/base/modal_background.png', '/images/level/code_palette_background.png', '/images/level/popover_background.png', '/images/level/code_editor_background.png']
2014-01-03 13:32:13 -05:00
preload = (arrayOfImages) ->
$(arrayOfImages).each ->
$('<img/>')[0].src = @
Application = initialize: ->
Router = require('Router')
2014-01-03 13:32:13 -05:00
@tracker = new Tracker()
@facebookHandler = new FacebookHandler()
@gplusHandler = new GPlusHandler()
2014-01-07 00:25:18 -05:00
$(document).bind 'keydown', preventBackspace
2014-04-23 14:25:36 -04:00
@linkedinHandler = new LinkedInHandler()
2014-01-03 13:32:13 -05:00
preload(COMMON_FILES)
$.i18n.init {
lng: me?.lang() ? 'en'
fallbackLng: 'en'
resStore: locale
#debug: true
#sendMissing: true
2014-06-30 22:16:26 -04:00
#sendMissingTo: 'current'
2014-01-03 13:32:13 -05:00
#resPostPath: '/languages/add/__lng__/__ns__'
}, (t) =>
@router = new Router()
onIdleChanged = (to) => => Backbone.Mediator.publish 'application:idle-changed', idle: @userIsIdle = to
@idleTracker = new Idle
onAway: onIdleChanged true
onAwayBack: onIdleChanged false
onHidden: onIdleChanged true
onVisible: onIdleChanged false
awayTimeout: 5 * 60 * 1000
@idleTracker.start()
2014-01-03 13:32:13 -05:00
module.exports = Application
window.application = Application