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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ElementExists 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-02-21 04:24:05 +02:00
|
|
|
return el.ExistsBySelector(ctx, selector), nil
|
2018-12-22 06:14:41 +02:00
|
|
|
}
|