Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 19A6917B61 for ; Wed, 15 Apr 2015 20:04:15 +0000 (UTC) Received: (qmail 53050 invoked by uid 500); 15 Apr 2015 20:04:14 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 53000 invoked by uid 500); 15 Apr 2015 20:04:14 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 52966 invoked by uid 99); 15 Apr 2015 20:04:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2015 20:04:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3C025E050B; Wed, 15 Apr 2015 20:04:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: benkeen@apache.org To: commits@couchdb.apache.org Message-Id: <9ea824b534ee4058a6e289b8e9c1f171@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: fauxton commit: updated refs/heads/master to 5920016 Date: Wed, 15 Apr 2015 20:04:14 +0000 (UTC) Repository: couchdb-fauxton Updated Branches: refs/heads/master 7e101d889 -> 592001668 ESC key closes any open notification This PR just lets users use their keyboard to close notifications. We discussed doing the same with mouse clicks and mouse overs, but they were a bit more contentious so I figure we can add them later if we want. Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/59200166 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/59200166 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/59200166 Branch: refs/heads/master Commit: 592001668ec3d766a49debb9fd21cc1909c1c111 Parents: 7e101d8 Author: Ben Keen Authored: Wed Apr 15 11:53:01 2015 -0700 Committer: Ben Keen Committed: Wed Apr 15 13:03:44 2015 -0700 ---------------------------------------------------------------------- app/addons/fauxton/base.js | 19 ++++++++++++++++++- app/addons/fauxton/tests/baseSpec.js | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/59200166/app/addons/fauxton/base.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/base.js b/app/addons/fauxton/base.js index f2944f8..a5e0755 100644 --- a/app/addons/fauxton/base.js +++ b/app/addons/fauxton/base.js @@ -154,12 +154,28 @@ function (app, FauxtonAPI, Components, NavbarReactComponents, NavigationActions, this.removeWithAnimation(); }, - removeWithAnimation: function (event) { + removeWithAnimation: function () { this.$el.velocity('reverse', FauxtonAPI.constants.MISC.TRAY_TOGGLE_SPEED, function () { this.$el.remove(); + this.removeCloseListener(); }.bind(this)); }, + addCloseListener: function () { + $(document).on('keydown.notificationClose', this.onKeyDown.bind(this)); + }, + + onKeyDown: function (e) { + var code = e.keyCode || e.which; + if (code === 27) { // ESC key + this.removeWithAnimation(); + } + }, + + removeCloseListener: function () { + $(document).off('keydown.notificationClose', this.removeWithAnimation); + }, + delayedRemoval: function () { this.timeout = setTimeout(function () { this.removeWithAnimation(); @@ -174,6 +190,7 @@ function (app, FauxtonAPI, Components, NavbarReactComponents, NavigationActions, this.render().$el.appendTo(selector); this.$el.velocity('transition.slideDownIn', FauxtonAPI.constants.MISC.TRAY_TOGGLE_SPEED); this.delayedRemoval(); + this.addCloseListener(); return this; } }); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/59200166/app/addons/fauxton/tests/baseSpec.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/tests/baseSpec.js b/app/addons/fauxton/tests/baseSpec.js index 63b6669..da49273 100644 --- a/app/addons/fauxton/tests/baseSpec.js +++ b/app/addons/fauxton/tests/baseSpec.js @@ -121,5 +121,21 @@ define([ delete window.fauxton_xss_test2_escaped; }); + it('should close notification when ESCAPE key used', function () { + var notification = FauxtonAPI.addNotification({ + msg: 'Close me!', + selector: 'body' + }); + var removeWithAnimationSpy = sinon.spy(notification, 'removeWithAnimation'); + + notification.render(); + + // manually trigger an ESCAPE key click + $(document).trigger($.Event("keydown", { keyCode: 27 })); + + // confirm the remove method has now been called + assert.ok(removeWithAnimationSpy.calledOnce); + }); + }); });