diff --git a/app/application.coffee b/app/application.coffee index 9bc15ad4cfe..1d25ab07b84 100644 --- a/app/application.coffee +++ b/app/application.coffee @@ -3,6 +3,7 @@ GPlusHandler = require 'lib/GPlusHandler' locale = require 'locale/locale' {me} = require 'lib/auth' Tracker = require 'lib/Tracker' +CocoView = require 'views/kinds/CocoView' COMMON_FILES = ['/images/modal_background.png', '/images/level/code_palette_background.png'] preload = (arrayOfImages) -> @@ -15,6 +16,9 @@ Application = initialize: -> @tracker = new Tracker() new FacebookHandler() new GPlusHandler() + $(document).bind 'keydown', preventBackspace + console.log 'done applied it' + preload(COMMON_FILES) $.i18n.init { lng: me?.lang() ? 'en' @@ -32,3 +36,19 @@ Application = initialize: -> module.exports = 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) diff --git a/app/views/kinds/CocoView.coffee b/app/views/kinds/CocoView.coffee index 6bf2fdfba1a..4384961b82b 100644 --- a/app/views/kinds/CocoView.coffee +++ b/app/views/kinds/CocoView.coffee @@ -181,18 +181,6 @@ module.exports = class CocoView extends Backbone.View for viewID, view of @subviews 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 insertSubView: (view) -> diff --git a/app/views/kinds/ModalView.coffee b/app/views/kinds/ModalView.coffee index 09e5efdf42e..72ed25764a9 100644 --- a/app/views/kinds/ModalView.coffee +++ b/app/views/kinds/ModalView.coffee @@ -9,7 +9,6 @@ module.exports = class ModalView extends CocoView shortcuts: 'esc': 'hide' - 'backspace, delete': 'preventBackspace' constructor: (options) -> options ?= {} diff --git a/app/views/kinds/RootView.coffee b/app/views/kinds/RootView.coffee index bd16a94fefd..77c0c0160a2 100644 --- a/app/views/kinds/RootView.coffee +++ b/app/views/kinds/RootView.coffee @@ -17,10 +17,6 @@ module.exports = class RootView extends CocoView "click #logout-button": "logoutAccount" 'change .language-dropdown': 'showDiplomatSuggestionModal' - shortcuts: - 'backspace, delete': 'preventBackspace' -# 'backspace': 'preventBackspace' - afterRender: -> super() @buildLanguages() diff --git a/app/views/play/level/tome/spell_view.coffee b/app/views/play/level/tome/spell_view.coffee index 93926771a2b..313e1b76161 100644 --- a/app/views/play/level/tome/spell_view.coffee +++ b/app/views/play/level/tome/spell_view.coffee @@ -23,6 +23,9 @@ module.exports = class SpellView extends View 'tome:reload-code': 'onCodeReload' 'modal-closed': 'focus' 'focus-editor': 'focus' + + events: + 'click .ace': -> console.log 'clicked ace', @ constructor: (options) -> super options