define([
    "underscore",
    "jQuery",
    "hr/hr"
], function(_, $, hr) {
    var DialogView = hr.View.extend({
        className: "component-dialog modal fade",
        defaults: {
            args: {},
            template: null,
            dialog: null,
            open: true,
            autoFocus: false,
            keyboard: true,
            className: "",
            valueSelector: true
        },
        events: {
            "keydown": "keydown",
            "hidden.bs.modal": "hidden",
            "shown.bs.modal": "shown",
            "click .action-close": "close",
            "click .action-confirm": "actionConfirm"
        },
        template: function() {
            if (this.options.template != null) return this.options.template;
            return "dialogs/"+this.options.dialog+".html";
        },
        templateContext: function() {
            return {
                options: this.options
            };
        },

        initialize: function(options) {
            DialogView.__super__.initialize.apply(this, arguments);
            this.$el.addClass(this.options.className);

            this.value = null;

            if (this.options.keyboard) {
                $(document).keydown(_.bind(this.keydown, this));
            }

            return this;
        },

        finish: function() {
            this.open();
            return DialogView.__super__.finish.apply(this, arguments);
        },

        /*
         *  Add to window and open
         */
        open: function() {
            if (DialogView.current != null) DialogView.current.close();

            this.$el.appendTo($("body"));
            this.$el.modal('show');
            DialogView.current = this;
            return this;
        },

        /*
         *  (event) Close the dialog
         */
        close: function(e) {
            if (e != null) {
                e.preventDefault();
            }
            this.$el.modal('hide');
            DialogView.current = null;
        },

        /*
         *  (event) Modal is hidden
         */
        hidden: function() {
            this.trigger("close", this.value);
            this.$el.remove();
        },

        /*
         * (event) Modal is shown
         */
        shown: function() {
            if (this.options.autoFocus) {
                this.$("input").focus();
            }
        },

        /*
         *  (event) action: confirm: close dialog with value from selector
         */
        actionConfirm: function(e) {
            if (e != null) {
                e.preventDefault();
            }
            this.value = this._getValue();
            this.close();
        },

        /*
         *  Selector for prompt dialog
         */
        selectorPrompt: function() {
            return this.$(".input").val();
        },

        /*
         *  Return final value
         */
        _getValue: function() {
            var selector = this.options.valueSelector;
            if (_.isFunction(selector)) {
                this.value = selector(this);
            } else if (_.isString(selector)) {
                this.value = this[selector]();
            } else {
                this.value = selector;
            }
            return this.value;
        },

        /*
         *  (event) keydown
         */
        keydown: function(e) {
            if (!this.options.keyboard) return;

            var key = e.keyCode || e.which;

            // Enter: valid
            if (key == 13) {
                this.actionConfirm(e);
            } else 
            // Esc: close
            if (key == 27) {
                this.close(e);
            }
        }
    }, {
        current: null,
    });

    return DialogView;
});
@@ -1143,16 +1143,106 @@
 = null;%0A
+            this.keydownHandler = _.bind(this.keydown, this)%0A%0A            // Bind keyboard
 %0A       
@@ -1307,23 +1307,24 @@
 nt).
+bind(%22
 keydown
-(_.bind(
+%22, 
 this
@@ -1331,23 +1331,23 @@
 .keydown
-, this)
+Handler
 );%0A     
@@ -2001,32 +2001,163 @@
 );%0A            %7D
+%0A%0A            // Unbind dowument keydown%0A            $(document).unbind(%22keydown%22, this.keydownHandler);%0A%0A            // Hide modal
 %0A            thi

Fix #44 keyboard handler for modal