Kaynağa Gözat

feat(control-sidebar): add ability to toggle between multiple control-sidebars

- instead of collapse and show (2 clicks)
REJack 3 yıl önce
ebeveyn
işleme
a936e220f6
1 değiştirilmiş dosya ile 16 ekleme ve 8 silme
  1. 16 8
      build/js/ControlSidebar.js

+ 16 - 8
build/js/ControlSidebar.js

@@ -66,7 +66,6 @@ class ControlSidebar {
   collapse() {
     const $body = $('body')
     const $html = $('html')
-    const { target } = this._config
 
     // Show the control sidebar
     if (this._config.controlsidebarSlide) {
@@ -87,10 +86,14 @@ class ControlSidebar {
     }, this._config.animationSpeed)
   }
 
-  show() {
+  show(toggle = false) {
     const $body = $('body')
     const $html = $('html')
 
+    if (toggle) {
+      $(SELECTOR_CONTROL_SIDEBAR).hide()
+    }
+
     // Collapse the control sidebar
     if (this._config.controlsidebarSlide) {
       $html.addClass(CLASS_NAME_CONTROL_SIDEBAR_ANIMATE)
@@ -113,15 +116,20 @@ class ControlSidebar {
 
   toggle() {
     const $body = $('body')
-    const shouldClose = $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
-        $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE)
+    const { target } = this._config
+
+    const notVisible = !$(target).is(':visible')
+    const shouldClose = ($body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
+      $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE))
+    const shouldToggle = notVisible && ($body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) ||
+      $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE))
 
-    if (shouldClose) {
+    if (notVisible || shouldToggle) {
+      // Open the control sidebar
+      this.show(notVisible)
+    } else if (shouldClose) {
       // Close the control sidebar
       this.collapse()
-    } else {
-      // Open the control sidebar
-      this.show()
     }
   }