Skip to content

Commit 23ef94e

Browse files
committed
examples/playground.php: Fetch elements props
1 parent 48ad784 commit 23ef94e

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

examples/duzun.me_playground_hquery.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
if ( $elements ) foreach($elements as $pos => $el) {
8787
$els[] = array(
8888
'nodeName' => $el->nodeName,
89-
'attr' => $el->attr(),
90-
'outerHtml' => $el->outerHtml(),
89+
'attr' => $el->attr(null, true),
90+
'outerHtml' => $el->outerHtml(null, true),
9191
'pos' => $pos,
9292
);
9393
}

examples/playground.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282

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

298299
<section class="result">
299300
<?php switch ($go) {
301+
case 'elements_props':
300302
case 'elements': if( !empty($elements) ):?>
301303
<table style="width: 100%">
302304
<thead><tr>
303305
<th>Pos.</th>
304306
<th>HTML</th>
305-
<th>View</th>
307+
<?php if ($go == 'elements_props'): ?>
308+
<th width="60%">Props</th>
309+
<?php else: ?>
310+
<th>View</th>
311+
<?php endif; ?>
306312
</tr></thead>
307313
<tbody>
308-
<?php foreach($elements as $pos => $el): ?>
309-
<tr>
310-
<td><i class="col-xs-1"><?=$pos;?></i></td>
311-
<td><pre style="word-break:break-word;"><?=htmlspecialchars($el->outerHtml(), ENT_QUOTES);?></pre></td>
312-
<td><?=$el->outerHtml();?></td>
313-
</tr>
314-
<?php endforeach;?>
314+
<?php foreach ($elements as $pos => $el): ?>
315+
<tr>
316+
<td><i class="col-xs-1"><?= $pos; ?></i></td>
317+
<td>
318+
<pre style="word-break:break-word;"><?= htmlspecialchars($el->outerHtml(), ENT_QUOTES); ?></pre>
319+
</td>
320+
<td>
321+
<?php if ($go == 'elements_props'): ?>
322+
<pre><?= htmlspecialchars(json_encode($el->attr(null, true), JSON_PRETTY_PRINT)) ?></pre>
323+
<?php else: ?>
324+
<?= $el->outerHtml(null, true); ?>
325+
<?php endif; ?>
326+
</td>
327+
</tr>
328+
<?php endforeach; ?>
315329
</tbody>
316330
</table>
317331
<?php

src/hQuery/Node.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function html($id = null)
280280
/**
281281
* @return string .outerHtml
282282
*/
283-
public function outerHtml($id = null)
283+
public function outerHtml($id = null, $eval_attr=false)
284284
{
285285
$dm = $this->isDoc() && !isset($id);
286286
if ($dm) {
@@ -296,7 +296,7 @@ public function outerHtml($id = null)
296296
$ret = self::$_nl_;
297297
$map = isset($this->tag_map) ? $this->tag_map : (isset($doc->tag_map) ? $doc->tag_map : null);
298298
foreach ($id as $p => $q) {
299-
$a = $doc->get_attr_byId($p, null, true, true);
299+
$a = $doc->get_attr_byId($p, null, true, !$eval_attr);
300300
$n = $doc->tags[$p];
301301
if ($map && isset($map[$_n = strtolower($n)])) {
302302
$n = $map[$_n];

0 commit comments

Comments
 (0)