nice modal view steals keyboard nicely

This commit is contained in:
Peter Cottle 2013-01-01 14:38:43 -08:00
parent e424bc27aa
commit 0d6f2516cb
2 changed files with 1137 additions and 1071 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@ var GitError = require('../util/errors').GitError;
var _ = require('underscore'); var _ = require('underscore');
// horrible hack to get localStorage Backbone plugin // horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone; var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
var Main = require('../app');
var BaseView = Backbone.View.extend({ var BaseView = Backbone.View.extend({
getDestination: function() { getDestination: function() {
@ -112,6 +113,7 @@ var ModalView = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
this.render(); this.render();
this.stealKeyboard();
}, },
render: function() { render: function() {
@ -120,6 +122,25 @@ var ModalView = Backbone.View.extend({
$('body').append(this.el); $('body').append(this.el);
}, },
stealKeyboard: function() {
console.warn('stealing keyboard');
Main.getEventBaton().stealBaton('keydown', this.onKeyDown, this);
Main.getEventBaton().stealBaton('keyup', this.onKeyUp, this);
},
releaseKeyboard: function() {
Main.getEventBaton().releaseBaton('keydown', this.onKeyDown, this);
Main.getEventBaton().releaseBaton('keyup', this.onKeyUp, this);
},
onKeyDown: function(e) {
e.preventDefault();
},
onKeyUp: function(e) {
e.preventDefault();
},
show: function() { show: function() {
this.toggleZ(true); this.toggleZ(true);
this.toggleShow(true); this.toggleShow(true);
@ -150,6 +171,7 @@ var ModalView = Backbone.View.extend({
tearDown: function() { tearDown: function() {
this.$el.html(''); this.$el.html('');
$('body')[0].removeChild(this.el); $('body')[0].removeChild(this.el);
this.releaseKeyboard();
} }
}); });