Skip to content

Commit 52bbdea

Browse files
committed
Merge branch 'master' of github.com:jae-jae/QueryList into develop
2 parents 02c2b12 + 25b2dbd commit 52bbdea

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/Dom/Elements.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,34 @@ public function __call($name, $arguments)
166166
return $obj;
167167
}
168168

169+
/**
170+
* Iterating elements
171+
*
172+
* @param callable $callback
173+
*
174+
* @return $this
175+
*/
176+
public function each(callable $callback)
177+
{
178+
$break = false;
179+
$this->elements->each(function ($dom) use ($callback, &$break) {
180+
if ( ! $dom || $break) {
181+
return;
182+
}
183+
$orig = $dom;
184+
$dom = new Elements(pq($dom));
185+
if (false === call_user_func($callback, $dom)) {
186+
$dom = $orig;
187+
$break = true;
188+
} else {
189+
$dom = $dom->getDOMDocument();
190+
}
191+
unset($orig);
192+
});
193+
194+
return $this;
195+
}
196+
169197
/**
170198
* Iterating elements
171199
*
@@ -184,7 +212,7 @@ public function map($callback)
184212
/**
185213
* Gets the attributes of all the elements
186214
*
187-
* @param $attr HTML attribute name
215+
* @param string $attr HTML attribute name
188216
* @return \Illuminate\Support\Collection|\Tightenco\Collect\Support\Collection
189217
*/
190218
public function attrs($attr)

0 commit comments

Comments
 (0)