Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ctrl+LeftClick | Collapse - Expand All #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions class.krumo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

//////////////////////////////////////////////////////////////////////////////

/**
/**
* Set the KRUMO_DIR constant up with the absolute path to Krumo files. If it
* is not defined, include_path will be used. Set KRUMO_DIR only if any other
* module or application has not already set it up.
* module or application has not already set it up.
*/
if (!defined('KRUMO_DIR'))
{
Expand Down Expand Up @@ -766,24 +766,32 @@ protected static function _js()

/**
* Toggle the nodes connected to an HTML element
* @param ClickEvent evt
* @param HtmlElement el
*/
"toggle": function(el)
"toggle": function(evt, el)
{
var ul = el.parentNode.getElementsByTagName('ul');
for (var i=0; i<ul.length; i++)
{
if (ul[i].parentNode.parentNode == el.parentNode)
{
ul[i].parentNode.style.display = (ul[i].parentNode.style.display == 'none')
? 'block'
: 'none';
let ctrl = evt.ctrlKey;
if (ctrl) {
let opened = el.className.indexOf('krumo-opened') > -1;
let parent = el.parentNode;
let nest = parent.querySelectorAll(".krumo-nest");
let exp = parent.querySelectorAll(".krumo-expand");
for (let i = 0; i < nest.length; i++) {
nest[i].style.display = (opened) ? 'none' : 'block';
}
for (let i = 0; i < exp.length; i++) {
(opened) ? krumo.unclass(exp[i], 'krumo-opened') : krumo.reclass(exp[i], 'krumo-opened');
}
} else {
let ul = el.parentNode.getElementsByTagName('ul');
for (let i = 0; i < ul.length; i++) {
if (ul[i].parentNode.parentNode == el.parentNode) {
ul[i].parentNode.style.display = (ul[i].parentNode.style.display === 'none') ? 'block' : 'none';
}
}
(ul[0].parentNode.style.display === 'block') ? krumo.reclass(el, 'krumo-opened') : krumo.unclass(el, 'krumo-opened');
}

(ul[0].parentNode.style.display == 'block')
? krumo.reclass(el, 'krumo-opened')
: krumo.unclass(el, 'krumo-opened');
}
}
</script><?php
Expand Down Expand Up @@ -1077,7 +1085,7 @@ private static function _array(&$data, $name)
?>
<li class="krumo-child">

<div <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
<div <?php if (count($data) > 0) {?> onClick="krumo.toggle(evt, this);"<?php } ?>
class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>">

<a class="krumo-name"><?php echo $name;?></a>
Expand Down Expand Up @@ -1126,7 +1134,7 @@ private static function _object(&$data, $name)
?>
<li class="krumo-child">

<div <?php if ($has_properties) {?> onClick="krumo.toggle(this);"<?php } ?>
<div <?php if ($has_properties) {?> onClick="krumo.toggle(evt, this);"<?php } ?>
class="krumo-element<?php echo $has_properties ? ' krumo-expand' : '';?>" >

<a class="krumo-name"><?php echo $name;?></a>
Expand Down Expand Up @@ -1252,7 +1260,7 @@ private static function _string($data, $name)

?>
<li class="krumo-child">
<div <?php if ($_extra) {?> onClick="krumo.toggle(this);"<?php } ?>
<div <?php if ($_extra) {?> onClick="krumo.toggle(evt, this);"<?php } ?>
class="krumo-element<?php echo $_extra ? ' krumo-expand' : '';?>" >

<a class="krumo-name"><?php echo $name;?></a>
Expand Down