Skip to content

Commit

Permalink
examples/playground.php: Fetch elements props
Browse files Browse the repository at this point in the history
  • Loading branch information
duzun committed Sep 29, 2024
1 parent 48ad784 commit 23ef94e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/duzun.me_playground_hquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
if ( $elements ) foreach($elements as $pos => $el) {
$els[] = array(
'nodeName' => $el->nodeName,
'attr' => $el->attr(),
'outerHtml' => $el->outerHtml(),
'attr' => $el->attr(null, true),
'outerHtml' => $el->outerHtml(null, true),
'pos' => $pos,
);
}
Expand Down
30 changes: 22 additions & 8 deletions examples/playground.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@

<p>
<button type="submit" name="go" value="elements" <?=$go=='elements'?'aria-pressed="true"':''?> class="btn btn-success">Fetch elements</button>
<button type="submit" name="go" value="elements_props" <?= $go == 'elements_props' ? 'aria-pressed="true"' : '' ?> class="btn btn-success">Fetch elements props</button>
<button type="submit" name="go" value="meta" <?=$go=='meta'?'aria-pressed="true"':''?> class="btn btn-success">Fetch meta</button>
<button type="submit" name="go" value="source" <?=$go=='source'?'aria-pressed="true"':''?> class="btn btn-success">Fetch source</button>
</p>
Expand All @@ -297,21 +298,34 @@

<section class="result">
<?php switch ($go) {
case 'elements_props':
case 'elements': if( !empty($elements) ):?>
<table style="width: 100%">
<thead><tr>
<th>Pos.</th>
<th>HTML</th>
<th>View</th>
<?php if ($go == 'elements_props'): ?>
<th width="60%">Props</th>
<?php else: ?>
<th>View</th>
<?php endif; ?>
</tr></thead>
<tbody>
<?php foreach($elements as $pos => $el): ?>
<tr>
<td><i class="col-xs-1"><?=$pos;?></i></td>
<td><pre style="word-break:break-word;"><?=htmlspecialchars($el->outerHtml(), ENT_QUOTES);?></pre></td>
<td><?=$el->outerHtml();?></td>
</tr>
<?php endforeach;?>
<?php foreach ($elements as $pos => $el): ?>
<tr>
<td><i class="col-xs-1"><?= $pos; ?></i></td>
<td>
<pre style="word-break:break-word;"><?= htmlspecialchars($el->outerHtml(), ENT_QUOTES); ?></pre>
</td>
<td>
<?php if ($go == 'elements_props'): ?>
<pre><?= htmlspecialchars(json_encode($el->attr(null, true), JSON_PRETTY_PRINT)) ?></pre>
<?php else: ?>
<?= $el->outerHtml(null, true); ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
Expand Down
4 changes: 2 additions & 2 deletions src/hQuery/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function html($id = null)
/**
* @return string .outerHtml
*/
public function outerHtml($id = null)
public function outerHtml($id = null, $eval_attr=false)
{
$dm = $this->isDoc() && !isset($id);
if ($dm) {
Expand All @@ -296,7 +296,7 @@ public function outerHtml($id = null)
$ret = self::$_nl_;
$map = isset($this->tag_map) ? $this->tag_map : (isset($doc->tag_map) ? $doc->tag_map : null);
foreach ($id as $p => $q) {
$a = $doc->get_attr_byId($p, null, true, true);
$a = $doc->get_attr_byId($p, null, true, !$eval_attr);
$n = $doc->tags[$p];
if ($map && isset($map[$_n = strtolower($n)])) {
$n = $map[$_n];
Expand Down

0 comments on commit 23ef94e

Please sign in to comment.