Skip to content

Commit

Permalink
Added configuration node collapse behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Dec 25, 2009
1 parent 37e1b1c commit bd1f3ef
Showing 1 changed file with 96 additions and 35 deletions.
131 changes: 96 additions & 35 deletions class.krumo.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@
/**
* Configuration array.
*/
static $_config = array();
Private Static $_config = array();

/**
* Returns values from Krumo's configuration
Expand Down Expand Up @@ -644,6 +644,47 @@
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

/**
* Cascade configuration array
*
* By default, all nodes are collapsed.
*/
Private Static $_cascade = array(0);

/**
* Set a cascade configuration array.
*
* Each value in the array is the maximum number of entries that node can
* have before it is being collapsed. The last value is repeated for all
* further levels.
*
* Example:
* array(10,5,0) - Nodes from the first level are expanded if they have less
* than 10 child nodes. Nodes from the second level are ex-
* panded if they have less then 5 nodes and all lower levels
* are collapsed.
*
* @param array $cascade Cascading information
* @access public
* @static
*/
Public Static Function cascade($cascade) {
self::$_cascade = $cascade;
}

/**
* Determines if a given node will be collapsed or not.
*/
Private Static Function _isCollapsed($level, $childCount) {
if (isset(self::$_cascade[$level])) {
return $childCount > self::$_cascade[$level];
} else {
return $childCount > end(self::$_cascade);
}
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

/**
* Print the skin (CSS)
Expand Down Expand Up @@ -922,6 +963,11 @@
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

/**
* Level of recursion.
*/
Private Static $_level = 0;

/**
* Render a dump for the properties of an array or objeect
Expand Down Expand Up @@ -954,41 +1000,48 @@
krumo::_hive($data);

// render it
//
//
$collapsed = krumo::_isCollapsed(self::$_level, count($data)-1);
?>
<div class="krumo-nest" style="display:none;">
<div class="krumo-nest"<?php if ($collapsed): ?> style="display:none;"<?php endif;?>>
<ul class="krumo-node">
<?php
<?php

// keys ?
//
$keys = ($_is_object)
? array_keys(get_object_vars($data))
: array_keys($data);
// keys ?
//
$keys = ($_is_object)
? array_keys(get_object_vars($data))
: array_keys($data);

// we're decending one level deeper
self::$_level++;

// itterate
//
foreach($keys as $k) {

// skip marker
// itterate
//
if ($k === $_recursion_marker) {
continue;
}
foreach($keys as $k) {

// skip marker
//
if ($k === $_recursion_marker) {
continue;
}

// get real value
//
if ($_is_object) {
$v =& $data->$k;
} else {
$v =& $data[$k];
}
// get real value
//
if ($_is_object) {
$v =& $data->$k;
} else {
$v =& $data[$k];
}

krumo::_dump($v,$k);
} ?>
krumo::_dump($v,$k);
} ?>
</ul>
</div>
<?php
<?php

// back up one level
self::$_level--;
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Expand Down Expand Up @@ -1027,12 +1080,16 @@
* @access private
* @static
*/
Private Static Function _array(&$data, $name) {
Private Static Function _array(&$data, $name) {
$childCount = count($data);
$collapsed = krumo::_isCollapsed(self::$_level, count($data));
$elementClasses = ($childCount > 0) ? (
($collapsed) ? ' krumo-expand' : ' krumo-expand krumo-opened'
) : '';
?>
<li class="krumo-child">

<div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
<?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
<div class="krumo-element<?php echo $elementClasses; ?>"
<?php if ($childCount > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">

Expand Down Expand Up @@ -1078,12 +1135,16 @@
* @access private
* @static
*/
Private Static Function _object(&$data, $name) {
Private Static Function _object(&$data, $name) {
$childCount = count($data);
$collapsed = krumo::_isCollapsed(self::$_level, count($data));
$elementClasses = ($childCount > 0) ? (
($collapsed) ? ' krumo-expand' : ' krumo-expand krumo-opened'
) : '';
?>
<li class="krumo-child">

<div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
<?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
<div class="krumo-element<?php echo $elementClasses; ?>"
<?php if ($childCount > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">

Expand Down

0 comments on commit bd1f3ef

Please sign in to comment.