From 9b7e5f5814119a22742867084c33e8f7ac894d5f Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sun, 9 Apr 2017 12:44:23 +0800 Subject: [PATCH] feat(event): Collapse the sidebar when click outside element in the small screen --- src/core/event/sidebar.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/event/sidebar.js b/src/core/event/sidebar.js index 3c6a63907..16401ea9d 100644 --- a/src/core/event/sidebar.js +++ b/src/core/event/sidebar.js @@ -7,17 +7,22 @@ const title = dom.$.title * Toggle button */ export function btn (el) { - const toggle = () => dom.body.classList.toggle('close') + const toggle = _ => dom.body.classList.toggle('close') el = dom.getNode(el) - dom.on(el, 'click', toggle) + dom.on(el, 'click', e => { + e.stopPropagation() + toggle() + }) const sidebar = dom.getNode('.sidebar') - dom.on(sidebar, 'click', () => { - isMobile && toggle() - setTimeout(() => getAndActive(sidebar, true, true), 0) - }) + isMobile && dom.on(dom.body, 'click', _ => + dom.body.classList.contains('close') && toggle() + ) + dom.on(sidebar, 'click', _ => + setTimeout((_ => getAndActive(sidebar, true, true), 0)) + ) } export function sticky () {