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