2014-11-28 20:49:41 -05:00
|
|
|
FacebookHandler = require 'core/social-handlers/FacebookHandler'
|
|
|
|
GPlusHandler = require 'core/social-handlers/GPlusHandler'
|
|
|
|
GitHubHandler = require 'core/social-handlers/GitHubHandler'
|
|
|
|
ModuleLoader = require 'core/ModuleLoader'
|
2014-11-28 19:38:50 -05:00
|
|
|
locale = require 'locale/locale'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
|
|
|
Tracker = require 'core/Tracker'
|
2015-01-09 15:38:00 -05:00
|
|
|
CocoModel = require 'models/CocoModel'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-04-24 15:24:22 -04:00
|
|
|
marked.setOptions {gfm: true, sanitize: true, smartLists: true, breaks: false}
|
|
|
|
|
2014-05-15 20:07:53 -04:00
|
|
|
# TODO, add C-style macro constants like this?
|
2014-09-18 16:18:44 -04:00
|
|
|
window.SPRITE_RESOLUTION_FACTOR = 3
|
2014-09-24 13:55:33 -04:00
|
|
|
window.SPRITE_PLACEHOLDER_WIDTH = 60
|
2014-05-15 20:07:53 -04:00
|
|
|
|
2014-04-02 17:42:34 -04:00
|
|
|
# Prevent Ctrl/Cmd + [ / ], P, S
|
|
|
|
ctrlDefaultPrevented = [219, 221, 80, 83]
|
2014-01-07 02:45:33 -05:00
|
|
|
preventBackspace = (event) ->
|
|
|
|
if event.keyCode is 8 and not elementAcceptsKeystrokes(event.srcElement or event.target)
|
|
|
|
event.preventDefault()
|
2014-04-02 17:42:34 -04:00
|
|
|
else if (key.ctrl or key.command) and not key.alt and event.keyCode in ctrlDefaultPrevented
|
2015-12-02 15:03:27 -05:00
|
|
|
console.debug "Prevented keystroke", key
|
2014-01-21 12:03:04 -05:00
|
|
|
event.preventDefault()
|
2014-01-07 02:45:33 -05:00
|
|
|
|
|
|
|
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-01-07 02:45:33 -05:00
|
|
|
|
2015-01-02 18:44:43 -05:00
|
|
|
COMMON_FILES = ['/images/pages/base/modal_background.png', '/images/level/popover_background.png', '/images/level/code_palette_wood_background.png', '/images/level/code_editor_background_border.png']
|
2014-01-03 13:32:13 -05:00
|
|
|
preload = (arrayOfImages) ->
|
|
|
|
$(arrayOfImages).each ->
|
|
|
|
$('<img/>')[0].src = @
|
|
|
|
|
2015-01-06 00:57:23 -05:00
|
|
|
# IE9 doesn't expose console object unless debugger tools are loaded
|
|
|
|
window.console ?=
|
|
|
|
info: ->
|
|
|
|
log: ->
|
|
|
|
error: ->
|
|
|
|
debug: ->
|
|
|
|
console.debug ?= console.log # Needed for IE10 and earlier
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
Application = initialize: ->
|
2014-11-28 20:49:41 -05:00
|
|
|
Router = require('core/Router')
|
2015-03-02 01:19:01 -05:00
|
|
|
@isProduction = -> document.location.href.search('https?://localhost:3000') is -1
|
2015-10-16 17:42:25 -04:00
|
|
|
@isIPadApp = webkit?.messageHandlers? and navigator.userAgent?.indexOf('CodeCombat-iPad') isnt -1
|
2014-09-06 22:50:31 -04:00
|
|
|
$('body').addClass 'ipad' if @isIPadApp
|
2015-10-28 14:33:27 -04:00
|
|
|
if $.browser.msie and parseInt($.browser.version) is 10
|
|
|
|
$("html").addClass("ie10")
|
2014-01-03 13:32:13 -05:00
|
|
|
@tracker = new Tracker()
|
2014-03-23 12:30:01 -04:00
|
|
|
@facebookHandler = new FacebookHandler()
|
|
|
|
@gplusHandler = new GPlusHandler()
|
2014-08-15 10:20:45 -04:00
|
|
|
@githubHandler = new GitHubHandler()
|
2014-11-28 19:38:50 -05:00
|
|
|
@moduleLoader = new ModuleLoader()
|
|
|
|
@moduleLoader.loadLanguage(me.get('preferredLanguage', true))
|
2014-01-07 00:25:18 -05:00
|
|
|
$(document).bind 'keydown', preventBackspace
|
2014-01-03 13:32:13 -05:00
|
|
|
preload(COMMON_FILES)
|
2015-01-09 15:38:00 -05:00
|
|
|
CocoModel.pollAchievements()
|
2014-01-03 13:32:13 -05:00
|
|
|
$.i18n.init {
|
2014-08-23 18:51:59 -04:00
|
|
|
lng: me.get('preferredLanguage', true)
|
2014-01-03 13:32:13 -05:00
|
|
|
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()
|
2014-03-12 14:39:09 -04:00
|
|
|
onIdleChanged = (to) => => Backbone.Mediator.publish 'application:idle-changed', idle: @userIsIdle = to
|
2014-03-11 16:59:12 -04:00
|
|
|
@idleTracker = new Idle
|
2014-03-12 14:39:09 -04:00
|
|
|
onAway: onIdleChanged true
|
|
|
|
onAwayBack: onIdleChanged false
|
|
|
|
onHidden: onIdleChanged true
|
|
|
|
onVisible: onIdleChanged false
|
2014-03-11 16:59:12 -04:00
|
|
|
awayTimeout: 5 * 60 * 1000
|
|
|
|
@idleTracker.start()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = Application
|
|
|
|
window.application = Application
|