mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
Fixed #56
This commit is contained in:
parent
a4fa41020f
commit
250b7322a9
5 changed files with 23 additions and 17 deletions
|
@ -3,6 +3,7 @@ GPlusHandler = require 'lib/GPlusHandler'
|
||||||
locale = require 'locale/locale'
|
locale = require 'locale/locale'
|
||||||
{me} = require 'lib/auth'
|
{me} = require 'lib/auth'
|
||||||
Tracker = require 'lib/Tracker'
|
Tracker = require 'lib/Tracker'
|
||||||
|
CocoView = require 'views/kinds/CocoView'
|
||||||
|
|
||||||
COMMON_FILES = ['/images/modal_background.png', '/images/level/code_palette_background.png']
|
COMMON_FILES = ['/images/modal_background.png', '/images/level/code_palette_background.png']
|
||||||
preload = (arrayOfImages) ->
|
preload = (arrayOfImages) ->
|
||||||
|
@ -15,6 +16,9 @@ Application = initialize: ->
|
||||||
@tracker = new Tracker()
|
@tracker = new Tracker()
|
||||||
new FacebookHandler()
|
new FacebookHandler()
|
||||||
new GPlusHandler()
|
new GPlusHandler()
|
||||||
|
$(document).bind 'keydown', preventBackspace
|
||||||
|
console.log 'done applied it'
|
||||||
|
|
||||||
preload(COMMON_FILES)
|
preload(COMMON_FILES)
|
||||||
$.i18n.init {
|
$.i18n.init {
|
||||||
lng: me?.lang() ? 'en'
|
lng: me?.lang() ? 'en'
|
||||||
|
@ -32,3 +36,19 @@ Application = initialize: ->
|
||||||
|
|
||||||
module.exports = Application
|
module.exports = Application
|
||||||
window.application = Application
|
window.application = Application
|
||||||
|
|
||||||
|
|
||||||
|
preventBackspace = (event) ->
|
||||||
|
console.log 'PREVENT', event
|
||||||
|
if event.keyCode is 8 and not elementAcceptsKeystrokes(event.srcElement or event.target)
|
||||||
|
event.preventDefault()
|
||||||
|
# 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
|
||||||
|
return (tag is 'textarea' or (tag is 'input' and type in textInputTypes) or el.contentEditable in ["", "true"]) and not (el.readOnly or el.disabled)
|
||||||
|
|
|
@ -181,18 +181,6 @@ module.exports = class CocoView extends Backbone.View
|
||||||
for viewID, view of @subviews
|
for viewID, view of @subviews
|
||||||
view.stopListeningToShortcuts()
|
view.stopListeningToShortcuts()
|
||||||
|
|
||||||
preventBackspace: (event) ->
|
|
||||||
event.preventDefault() if event.keyCode is 8 and not @elementAcceptsKeystrokes(event.srcElement or event.target)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Subviews
|
# Subviews
|
||||||
|
|
||||||
insertSubView: (view) ->
|
insertSubView: (view) ->
|
||||||
|
|
|
@ -9,7 +9,6 @@ module.exports = class ModalView extends CocoView
|
||||||
|
|
||||||
shortcuts:
|
shortcuts:
|
||||||
'esc': 'hide'
|
'esc': 'hide'
|
||||||
'backspace, delete': 'preventBackspace'
|
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
options ?= {}
|
options ?= {}
|
||||||
|
|
|
@ -17,10 +17,6 @@ module.exports = class RootView extends CocoView
|
||||||
"click #logout-button": "logoutAccount"
|
"click #logout-button": "logoutAccount"
|
||||||
'change .language-dropdown': 'showDiplomatSuggestionModal'
|
'change .language-dropdown': 'showDiplomatSuggestionModal'
|
||||||
|
|
||||||
shortcuts:
|
|
||||||
'backspace, delete': 'preventBackspace'
|
|
||||||
# 'backspace': 'preventBackspace'
|
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
@buildLanguages()
|
@buildLanguages()
|
||||||
|
|
|
@ -24,6 +24,9 @@ module.exports = class SpellView extends View
|
||||||
'modal-closed': 'focus'
|
'modal-closed': 'focus'
|
||||||
'focus-editor': 'focus'
|
'focus-editor': 'focus'
|
||||||
|
|
||||||
|
events:
|
||||||
|
'click .ace': -> console.log 'clicked ace', @
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super options
|
super options
|
||||||
@session = options.session
|
@session = options.session
|
||||||
|
|
Loading…
Reference in a new issue