2018-12-22 06:14:41 +02:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
2019-09-07 20:03:17 +02:00
|
|
|
// ELEMENT_EXISTS returns a boolean value indicating whether there is an element matched by selector.
|
2019-02-20 01:10:18 +02:00
|
|
|
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
|
2018-12-22 06:14:41 +02:00
|
|
|
// @param selector (String) - CSS selector.
|
|
|
|
// @returns (Boolean) - A boolean value indicating whether there is an element matched by selector.
|
2019-02-21 04:24:05 +02:00
|
|
|
func ElementExists(ctx context.Context, args ...core.Value) (core.Value, error) {
|
2018-12-22 06:14:41 +02:00
|
|
|
el, selector, err := queryArgs(args)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
2019-07-26 19:22:06 +02:00
|
|
|
return el.ExistsBySelector(ctx, selector)
|
2018-12-22 06:14:41 +02:00
|
|
|
}
|