1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-23 01:24:30 +02:00
ferret/pkg/stdlib/html/wait_style_all.go
Tim Voronov d7b923e4c3
Feature/#220 iframe support (#315)
* Refactored Virtual DOM structure
* Added new E2E tests
* Updated E2E Test Runner
2019-06-19 17:58:56 -04:00

67 lines
1.4 KiB
Go

package html
import (
"context"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleAllWhen(ctx, args, drivers.WaitEventPresence)
}
func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleAllWhen(ctx, args, drivers.WaitEventAbsence)
}
func waitStyleAllWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
err := core.ValidateArgs(args, 4, 5)
if err != nil {
return values.None, err
}
doc, err := drivers.ToDocument(args[0])
if err != nil {
return values.None, err
}
// selector
err = core.ValidateType(args[1], types.String)
if err != nil {
return values.None, err
}
// attr name
err = core.ValidateType(args[2], types.String)
if err != nil {
return values.None, err
}
selector := args[1].(values.String)
name := args[2].(values.String)
value := args[3]
timeout := values.NewInt(defaultTimeout)
if len(args) == 5 {
err = core.ValidateType(args[4], types.Int)
if err != nil {
return values.None, err
}
timeout = args[4].(values.Int)
}
ctx, fn := waitTimeout(ctx, timeout)
defer fn()
return values.None, doc.WaitForStyleBySelectorAll(ctx, selector, name, value, when)
}