1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-17 13:28:35 +01:00

Make hidden tabs configurable

This commit is contained in:
Barry vd. Heuvel 2024-09-10 19:21:44 +02:00
parent 152f2ea347
commit 5e76d50854
2 changed files with 45 additions and 4 deletions

View File

@ -62,6 +62,8 @@ class JavascriptRenderer
protected $useRequireJs = false; protected $useRequireJs = false;
protected $hideEmptyTabs = false;
protected $initialization; protected $initialization;
protected $controls = array(); protected $controls = array();
@ -157,6 +159,9 @@ class JavascriptRenderer
if (array_key_exists('use_requirejs', $options)) { if (array_key_exists('use_requirejs', $options)) {
$this->setUseRequireJs($options['use_requirejs']); $this->setUseRequireJs($options['use_requirejs']);
} }
if (array_key_exists('hide_empty_tabs', $options)) {
$this->setHideEmptyTabs($options['hide_empty_tabs']);
}
if (array_key_exists('controls', $options)) { if (array_key_exists('controls', $options)) {
foreach ($options['controls'] as $name => $control) { foreach ($options['controls'] as $name => $control) {
$this->addControl($name, $control); $this->addControl($name, $control);
@ -397,6 +402,29 @@ class JavascriptRenderer
return $this->useRequireJs; return $this->useRequireJs;
} }
/**
* Sets whether to hide empty tabs or not
*
* @param boolean $hide
* @return $this
*/
public function setHideEmptyTabs($hide = true)
{
$this->hideEmptyTabs = $hide;
return $this;
}
/**
* Checks if empty tabs are hidden or not
*
* @return boolean
*/
public function areEmptyTabsHidden()
{
return $this->hideEmptyTabs;
}
/** /**
* Adds a control to initialize * Adds a control to initialize
* *
@ -1036,7 +1064,7 @@ class JavascriptRenderer
public function replaceTagInBuffer($here = true, $initialize = true, $renderStackedData = true, $head = false) public function replaceTagInBuffer($here = true, $initialize = true, $renderStackedData = true, $head = false)
{ {
$render = ($head ? $this->renderHead() : "") $render = ($head ? $this->renderHead() : "")
. $this->render($initialize, $renderStackedData); . $this->render($initialize, $renderStackedData);
$current = ($here && ob_get_level() > 0) ? ob_get_clean() : self::REPLACEABLE_TAG; $current = ($here && ob_get_level() > 0) ? ob_get_clean() : self::REPLACEABLE_TAG;
@ -1075,7 +1103,7 @@ class JavascriptRenderer
$nonce = $this->getNonceAttribute(); $nonce = $this->getNonceAttribute();
if ($nonce != '') { if ($nonce != '') {
$js = preg_replace("/<script>/", "<script nonce='{$this->cspNonce}'>", $js); $js = preg_replace("/<script>/", "<script nonce='{$this->cspNonce}'>", $js);
} }
@ -1100,6 +1128,11 @@ class JavascriptRenderer
$js .= sprintf("var %s = new %s();\n", $this->variableName, $this->javascriptClass); $js .= sprintf("var %s = new %s();\n", $this->variableName, $this->javascriptClass);
} }
if ($this->hideEmptyTabs !== null) {
$js .= sprintf("%s.setHideEmptyTabs(%s);\n", $this->variableName,
json_encode($this->hideEmptyTabs));
}
if (($this->initialization & self::INITIALIZE_CONTROLS) === self::INITIALIZE_CONTROLS) { if (($this->initialization & self::INITIALIZE_CONTROLS) === self::INITIALIZE_CONTROLS) {
$js .= $this->getJsControlsDefinitionCode($this->variableName); $js .= $this->getJsControlsDefinitionCode($this->variableName);
} }

View File

@ -255,7 +255,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
className: csscls('panel'), className: csscls('panel'),
render: function() { render: function() {
this.$tab = $('<a />').addClass(csscls('tab')).hide(); this.$tab = $('<a />').addClass(csscls('tab'));
this.$icon = $('<i />').appendTo(this.$tab); this.$icon = $('<i />').appendTo(this.$tab);
this.bindAttr('icon', function(icon) { this.bindAttr('icon', function(icon) {
if (icon) { if (icon) {
@ -425,6 +425,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
this.firstTabName = null; this.firstTabName = null;
this.activePanelName = null; this.activePanelName = null;
this.activeDatasetId = null; this.activeDatasetId = null;
this.hideEmptyTabs = false;
this.datesetTitleFormater = new DatasetTitleFormater(this); this.datesetTitleFormater = new DatasetTitleFormater(this);
this.options.bodyMarginBottomHeight = parseInt($('body').css('margin-bottom')); this.options.bodyMarginBottomHeight = parseInt($('body').css('margin-bottom'));
try { try {
@ -643,7 +644,10 @@ if (typeof(PhpDebugBar) == 'undefined') {
} else { } else {
self.showTab(name); self.showTab(name);
} }
}); })
if (this.hideEmptyTabs) {
tab.$tab.hide();
}
tab.$tab.attr('data-collector', name); tab.$tab.attr('data-collector', name);
tab.$el.attr('data-collector', name); tab.$el.attr('data-collector', name);
tab.$el.appendTo(this.$body); tab.$el.appendTo(this.$body);
@ -1058,6 +1062,10 @@ if (typeof(PhpDebugBar) == 'undefined') {
} }
}, },
setHideEmptyTabs: function(hideEmpty) {
this.hideEmptyTabs = hideEmpty;
},
/** /**
* Returns the handler to open past dataset * Returns the handler to open past dataset
* *