note 86436 deleted from book.dom by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 18:06:08 +0000 |
| Subject: | note 86436 deleted from book.dom by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212227@lists.php.net to get a copy of this message | ||
Note Submitter: cgorbit spamless_at ya dot ru
----
Show expandable DOM like in Firebug.
http://cgorbit.itkm.ru/temp/phpdotnet/common.js
needed for script, sorry, but it's my framework.
<?php
function gaie( $node, &$arr, $attr )
{
if ( $value = $node->getAttribute( $attr ) )
$arr[ $attr ] = u2w( $value );
}
function innerXML( $l, $collapse_all = true, $top_run = true )
{
$atts4elements = array(
'a' => 'href',
'table' => 'border,cellpadding,cellspacing',
'td' => 'colspan,rowspan'
);
$s = '';
if ( $top_run ) :
ob_start();
?><html>
<head>
<meta http-uquiv="Content-type" content="text/html; charset=windows-1251"
/>
<script type="text/javascript" src="/common.js"></script>
</head>
<body>
<style type="text/css">
body {
}
.root-inner-xml-list {
list-style-type: none;
font-size: 1em;
font-family: monospace;
}
.root-inner-xml-list ul {
list-style-type: none;
}
.root-inner-xml-list li.text-node span.value {
color: black;
font-weight: bold;
background-color: lightgrey;
margin-right: 1em;
padding: 0em 0.2em;
}
.root-inner-xml-list li.text-node span.hex {
color: gray;
font-style: italic;
}
.root-inner-xml-list li.element-node {
color: blue;
}
.root-inner-xml-list .attribute-name {
color: green;
}
.root-inner-xml-list .attribute-value {
color: red;
color: rgb( 205, 0, 0 );
}
.root-inner-xml-list .node-with-childs {
cursor: pointer;
//cursor: hand;
}
.root-inner-xml-list .collapsed-node {
background-color: yellow;
}
.root-inner-xml-list .collapsed-node + ul {
display: none;
}
</style>
<ul class="root-inner-xml-list">
<?
$s .= ob_get_clean();
endif;
//if ( $top_run ) $l = $l->childNodes;
foreach ( $l as $i => $node )
{
if ( $node->nodeType == XML_ELEMENT_NODE )
{
$atts = array();
$atts2get = array( 'id', 'class', 'style' );
if ( @$atts4elements[ $node->tagName ] )
$atts2get = array_merge( $atts2get, explode( ',', $atts4elements[ $node->tagName ]
) );
foreach ( $atts2get as $att2get )
gaie( $node, $atts, $att2get );
$attr_arr = array();
foreach ( $atts as $name => $value )
$attr_arr[] = sprintf( '<span
class="attribute-name">%s</span>="<span
class="attribute-value">%s</span>"', $name, $value );
$atts_s = '';
if ( $attr_arr )
$atts_s = join( ' ', $attr_arr );
$span_class_name = array( 'node-name' );
if ( $node->childNodes->length )
$span_class_name[] = 'node-with-childs';
if ( $collapse_all )
$span_class_name[] = 'collapsed-node';
$span_class_name = join( ' ', $span_class_name );
$inner = '<span class="' . $span_class_name . '"><'.
$node->tagName . ' ' . $atts_s . '></span>';
if ( $node->childNodes->length )
$inner .= '<ul>' . innerXML( $node->childNodes, $collapse_all, false ) .
'</ul>';
$className = 'element-node';
}
elseif ( $node->nodeType == XML_TEXT_NODE )
{
$value = htmlspecialchars( u2w( $node->nodeValue ) );
$inner = '<span class="value">' . $value . '</span><span
class="hex">' . string2hex( $value ) . '</span>';
$className = 'text-node';
}
else
continue;
$s .= '<li class="' . $className . '">' . $inner .
'</li>';
if ( $top_run ) echo '<hr />';
}
if ( $top_run ):
ob_start();
?></ul>
<script type="text/javascript">
onLoad( function(){
addEvent( $( '.root-inner-xml-list .node-with-childs', true ), 'click',
function( e ){
var el = e.target;
ul = getNextSibling( el );
if ( !ul || ul.tagName != 'UL' ) return;
invertClass( el, 'collapsed-node' );
});
});
globalInit();
</script>
</body>
</html>
<?
$s .= ob_get_clean();
endif;
return $s;
}
?>