2014-01-03 13:32:13 -05:00
|
|
|
FacebookHandler = require 'lib/FacebookHandler'
|
|
|
|
GPlusHandler = require 'lib/GPlusHandler'
|
|
|
|
locale = require 'locale/locale'
|
|
|
|
{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
|
|
|
|
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-01-21 12:03:04 -05:00
|
|
|
else if (key.ctrl or key.command) and not key.alt and event.keyCode in [219, 221] # prevent Ctrl/Cmd + [ / ]
|
|
|
|
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
|
|
|
|
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-02-06 17:00:27 -05:00
|
|
|
COMMON_FILES = ['/images/pages/base/modal_background.png', '/images/level/code_palette_background.png']
|
2014-01-03 13:32:13 -05:00
|
|
|
preload = (arrayOfImages) ->
|
|
|
|
$(arrayOfImages).each ->
|
|
|
|
$('<img/>')[0].src = @
|
|
|
|
|
|
|
|
Application = initialize: ->
|
|
|
|
Router = require('lib/Router')
|
|
|
|
@tracker = new Tracker()
|
|
|
|
new FacebookHandler()
|
|
|
|
new GPlusHandler()
|
2014-01-07 00:25:18 -05:00
|
|
|
$(document).bind 'keydown', preventBackspace
|
2014-01-07 02:45:33 -05:00
|
|
|
|
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
|
|
|
|
#sendMissingTo: "current"
|
|
|
|
#resPostPath: '/languages/add/__lng__/__ns__'
|
|
|
|
}, (t) =>
|
|
|
|
@router = new Router()
|
|
|
|
@router.subscribe()
|
|
|
|
Object.freeze this if typeof Object.freeze is 'function'
|
|
|
|
@router = Router
|
|
|
|
|
|
|
|
module.exports = Application
|
|
|
|
window.application = Application
|