Replaces a specified HTML tag based from the given callback.

@param  \Pilipinews\Common\Crawler $crawler
@param  string                     $element
@param  callable                   $callback
@return \Pilipinews\Common\Crawler
769607
protected function replace(Crawler $crawler, $element, $callback)
    {
        $function = function (Crawler $crawler) use ($callback)
        {
            $node = $crawler->getNode(0);

            $html = $node->ownerDocument->saveHtml($node);

            $text = $callback($crawler, (string) $html);

            return array((string) $html, (string) $text);
        };

        $items = $crawler->filter($element)->each($function);

        $html = (string) $crawler->html();

        foreach ((array) $items as $item)
        {
            $html = str_replace($item[0], $item[1], $html);
        }

        return new Crawler((string) $html);
    }
219117
protected function wrapInNode($nodeType, $callback)
    {
        // Sanity check
        assert(is_string($nodeType));
        assert(is_callable($callback));

        $this->startElement($nodeType);
        $result = $callback();
        $this->endElement();

        return $result;
    }
663816
protected function eachPageUncache($selector, callable $callback)
	{
		$num = 0;
		$id = 0;
		while (true) {
			$p = $this->pages->get("{$selector}, id>$id");
			if(!$id = $p->id) break;
			$callback($p);
			$this->pages->uncacheAll($p);
			$num++;
		}
		return $num;
	}
494872
public function detach(string $event, $callback){
        if(isset($this->listeners[$event])){
            return $this->listeners[$event]->remove($callback);
        }
        return false;
    }
61786
public function callback($callable, $description = null): ValidatorChain
    {
        $rule = Validator::rule('callback', [$callable]);
        if (null !== $description) {
            $rule->setDescription($description);
        }
        $this->addRule($rule);
        return $this;
    }
887146
protected function appendWrapper(\DOMElement $element, \DOMDocument $dom)
    {
        $wrapper = $dom->createElement('div');
        $wrapper->setAttribute('class', 'cms-slide-wrapper');

        $element->appendChild($wrapper);

        return $wrapper;
    }
30249
function crawlScript($,result, script, callback) {

    var link = $(script).attr('src');
    var parentUrl = result.url;

    if (link) {
          var linkUri = URI.linkToURI(parentUrl, link);
          pm.crawlLink(parentUrl, linkUri, null, null, function(){
            addLinkToQueue(result, parentUrl, linkUri, null, null, callback);
          });
    }
    else {
      callback();
    }


}
458609
protected function fetchContainer(Crawler $crawler, $container)
    {
        $content = $crawler->filter($container);

        if (!$content->count()) {
            throw new HttpException(422, 'No content');
        }

        return $content->html();
    }
714494
public function replaceWith(Element $element) 
	{
		// if the element has a parent
		if ( ! empty($this->parent)) {
			$this->parent->replaceChild($this, $element);
		} else {
			throw new \BadMethodCallException(
				__METHOD__."() expects this element to have a parent element"
			);
		}
		
		return $this;
	}
453191
public function open(callable $callback)
    {
        $sessionHandleList = $this->getSessionWindowHandles();
        $callback($this->driver);
        for ($i = 0; $i < 10; $i++) {
            $handle = $this->getNewWindow($sessionHandleList);
            if ($handle === null) {
                sleep(1);
            } else {
                $this->setWindowHandle($handle);
                return $this;
            }
        }
        throw new WebDriver_Exception("The expected window didn't open.");
    }
471282
protected function reparentElement(DOMElement $element)
	{
		$parentNode = $element->parentNode;
		do
		{
			$lastChild = $parentNode->lastChild;
			$parentNode->parentNode->insertBefore($lastChild, $parentNode->nextSibling);
		}
		while (!$lastChild->isSameNode($element));
	}
657409
function crawlLinks(result, $, endCallback) {

    if (! result.links){
        return endCallback();
    }

    log.debug({"url" : result.url, "step" : "analyzeHTML", "message" : "CrawlLinks"});

    async.each($('link'), function(linkTag, callback) {
        crawLink($, result, linkTag, callback);
    }, endCallback);
}
298504
public static function convertElement($element, RemoteWebDriver $driver)
    {
        if ($element instanceof RemoteWebElement) {
            return new self($element, $driver);
        }

        return $element;
    }
197830
public <T extends EventObject> void setDefaultEventCallback(
            final CrawlEvent event,
            final Consumer<T> callback) {
        defaultCallbacks.put(event, callback);
    }
888898
protected function hasAttributes(Crawler $element)
    {
        foreach ($this->attributes as $name => $value) {
            if (is_numeric($name)) {
                if (is_null($element->attr($value))) {
                    return false;
                }
            } else {
                if ($element->attr($name) != $value) {
                    return false;
                }
            }
        }

        return true;
    }
104889
protected function replaceElement(DOMElement $element)
	{
		$elName = $this->lowercase($element->localName);
		if ($elName === $element->localName)
		{
			return;
		}

		// Create a new element with the correct name
		$newElement = (is_null($element->namespaceURI))
		            ? $this->ownerDocument->createElement($elName)
		            : $this->ownerDocument->createElementNS($element->namespaceURI, $elName);

		// Move every child to the new element
		while ($element->firstChild)
		{
			$newElement->appendChild($element->removeChild($element->firstChild));
		}

		// Copy attributes to the new node
		foreach ($element->attributes as $attribute)
		{
			$newElement->setAttributeNS(
				$attribute->namespaceURI,
				$attribute->nodeName,
				$attribute->value
			);
		}

		// Replace the old element with the new one
		$element->parentNode->replaceChild($newElement, $element);
	}
893795
function delegate(callback, el) {
        var currentElement = el;

        do {
            if (!isClickTarget(currentElement)) continue;
            callback(currentElement);
            return;
        } while(currentElement.nodeName.toUpperCase() !== 'BODY' && (currentElement = currentElement.parentNode));
    }