From f6700616695f432a12dff47037d071ceb90cab3d Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 30 Jun 2016 00:55:44 -0700 Subject: [PATCH] Pressing escape closes the lightbox // FREEBIE --- js/views/attachment_view.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index 88089d3ba1..522cf17b9e 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -131,6 +131,12 @@ Whisper.LightboxView = Whisper.View.extend({ templateName: 'lightbox', className: 'modal lightbox', + initialize: function() { + this.window = extension.windows.getWindow(); + this.$document = $(this.window.document); + this.listener = this.onkeyup.bind(this); + this.$document.on('keyup', this.listener); + }, events: { 'click .save': 'save', 'click .close': 'remove', @@ -147,6 +153,12 @@ return false; } }, + onkeyup: function(e) { + if (e.keyCode === 27) { + this.remove(); + this.$document.off('keyup', this.listener); + } + }, render_attributes: function() { return { url: this.model.objectUrl }; }