From 231d17fc7f23e98bbf0c26ded69e5d62358bf766 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sun, 29 Dec 2013 17:45:41 +0100 Subject: [PATCH] Change minimize to close button Close the debugbar, to save space. Minimize happens when clicking on the open tab. --- src/DebugBar/Resources/debugbar.css | 16 +++++--- src/DebugBar/Resources/debugbar.js | 59 +++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/DebugBar/Resources/debugbar.css b/src/DebugBar/Resources/debugbar.css index 46a40e1..eb9a540 100644 --- a/src/DebugBar/Resources/debugbar.css +++ b/src/DebugBar/Resources/debugbar.css @@ -12,6 +12,10 @@ div.phpdebugbar { text-align: left; } +div.phpdebugbar-closed { + width: auto; +} + div.phpdebugbar * { box-sizing: content-box; } @@ -39,7 +43,8 @@ a.phpdebugbar-tab, span.phpdebugbar-indicator, a.phpdebugbar-indicator, a.phpdebugbar-open-btn, -a.phpdebugbar-minimize-btn { +a.phpdebugbar-restore-btn, +a.phpdebugbar-close-btn { float: left; padding: 5px 8px; font-size: 14px; @@ -48,8 +53,8 @@ a.phpdebugbar-minimize-btn { } span.phpdebugbar-indicator, a.phpdebugbar-indicator, -a.phpdebugbar-open-btn, -a.phpdebugbar-minimize-btn { +a.phpdebugbar-restore-btn, +a.phpdebugbar-close-btn { float: right; border-right: 1px solid #ddd; } @@ -85,14 +90,13 @@ a.phpdebugbar-tab.phpdebugbar-active { color: white; } -a.phpdebugbar-minimize-btn { - display: none; +a.phpdebugbar-close-btn { background: url(icons.png) no-repeat 10px 7px; width: 16px; height: 16px; } -a.phpdebugbar-open-btn { +a.phpdebugbar-open-btn, a.phpdebugbar-restore-btn { background: url(icons.png) no-repeat -14px 8px; width: 16px; height: 16px; diff --git a/src/DebugBar/Resources/debugbar.js b/src/DebugBar/Resources/debugbar.js index 8f4aad1..1a6153c 100644 --- a/src/DebugBar/Resources/debugbar.js +++ b/src/DebugBar/Resources/debugbar.js @@ -471,9 +471,15 @@ if (typeof(PhpDebugBar) == 'undefined') { }); // minimize button - this.$minimizebtn = $('').addClass(csscls('minimize-btn')).appendTo(this.$header); - this.$minimizebtn.click(function() { - self.minimize(); + this.$closebtn = $('').addClass(csscls('close-btn')).appendTo(this.$header); + this.$closebtn.click(function() { + self.close(); + }); + + // minimize button + this.$restorebtn = $('').addClass(csscls('restore-btn')).hide().appendTo(this.$el); + this.$restorebtn.click(function() { + self.restore(); }); // open button @@ -509,12 +515,17 @@ if (typeof(PhpDebugBar) == 'undefined') { localStorage.setItem('phpdebugbar-height', this.$body.height()); } - // bar visibility - var visible = localStorage.getItem('phpdebugbar-visible'); - if (visible && visible == '1') { - var tab = localStorage.getItem('phpdebugbar-tab'); - if (this.isTab(tab)) { - this.showTab(tab); + // bar visibility + var open = localStorage.getItem('phpdebugbar-open'); + if(open && open == '0'){ + this.close(); + }else{ + var visible = localStorage.getItem('phpdebugbar-visible'); + if (visible && visible == '1') { + var tab = localStorage.getItem('phpdebugbar-tab'); + if (this.isTab(tab)) { + this.showTab(tab); + } } } }, @@ -691,7 +702,6 @@ if (typeof(PhpDebugBar) == 'undefined') { this.$resizehdle.show(); this.$body.show(); - this.$minimizebtn.show(); this.recomputeBottomOffset(); $(this.$header).find('> .' + csscls('active')).removeClass(csscls('active')); @@ -707,14 +717,13 @@ if (typeof(PhpDebugBar) == 'undefined') { }, /** - * Hide panels and "close" the debug bar + * Hide panels and minimize the debug bar * * @this {DebugBar} */ minimize: function() { this.$header.find('> .' + csscls('active')).removeClass(csscls('active')); this.$body.hide(); - this.$minimizebtn.hide(); this.$resizehdle.hide(); this.recomputeBottomOffset(); localStorage.setItem('phpdebugbar-visible', '0'); @@ -729,6 +738,32 @@ if (typeof(PhpDebugBar) == 'undefined') { isMinimized: function() { return this.$el.hasClass(csscls('minimized')); }, + + /** + * Close the debug bar + * + * @this {DebugBar} + */ + close: function() { + this.$header.hide(); + this.$body.hide(); + this.$restorebtn.show(); + localStorage.setItem('phpdebugbar-open', '0'); + this.$el.addClass(csscls('closed')); + }, + + /** + * Restore the debug bar + * + * @this {DebugBar} + */ + restore: function() { + this.$header.show(); + this.$restorebtn.hide(); + localStorage.setItem('phpdebugbar-open', '1'); + this.restoreState(); + this.$el.removeClass(csscls('closed')); + }, /** * Recomputes the padding-bottom css property of the body so