From 96a033064d8867010a550048d08fc612d7dcb8f9 Mon Sep 17 00:00:00 2001 From: Sean Roberts Date: Thu, 30 Mar 2017 15:46:50 -0400 Subject: [PATCH 1/2] Fixing sidebar not closing on outside content click issue --- src/annotator/sidebar.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/annotator/sidebar.coffee b/src/annotator/sidebar.coffee index 01cbd17abc8..4e86d679d36 100644 --- a/src/annotator/sidebar.coffee +++ b/src/annotator/sidebar.coffee @@ -47,6 +47,16 @@ module.exports = class Sidebar extends Host @element.on 'click', (event) => if !@selectedTargets?.length this.hide() + + # Mobile browsers do not register click events on + # elements without cursor: pointer. So instead of + # adding that to every element, we can add the initial + # touchstart event which is always registered to + # make up for the lack of click support for all elements. + @element.on 'touchstart', (event) => + if !@selectedTargets?.length + this.hide() + return this _setupSidebarEvents: -> From b6741e51c572eb2183418c888290e35b9ac9523b Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 31 Mar 2017 11:44:55 +0100 Subject: [PATCH 2/2] Add tests for sidebar closing when user clicks or taps in document --- src/annotator/sidebar.coffee | 3 +++ src/annotator/test/sidebar-test.coffee | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/annotator/sidebar.coffee b/src/annotator/sidebar.coffee index 4e86d679d36..6a842c818c3 100644 --- a/src/annotator/sidebar.coffee +++ b/src/annotator/sidebar.coffee @@ -176,6 +176,9 @@ module.exports = class Sidebar extends Host .removeClass('h-icon-chevron-right') .addClass('h-icon-chevron-left') + isOpen: -> + !@frame.hasClass('annotator-collapsed') + createAnnotation: (annotation = {}) -> super this.show() unless annotation.$highlight diff --git a/src/annotator/test/sidebar-test.coffee b/src/annotator/test/sidebar-test.coffee index 38d9f7da38f..30f9057ce51 100644 --- a/src/annotator/test/sidebar-test.coffee +++ b/src/annotator/test/sidebar-test.coffee @@ -173,3 +173,16 @@ describe 'Sidebar', -> hide = sandbox.stub(sidebar, 'hide') sidebar.onSwipe({type: 'swiperight'}) assert.calledOnce(hide) + + describe 'document events', -> + + sidebar = null + + beforeEach -> + sidebar = createSidebar({}) + + it 'closes the sidebar when the user taps or clicks in the page', -> + for event in ['click', 'touchstart'] + sidebar.show() + sidebar.element.trigger(event) + assert.isFalse(sidebar.isOpen())