github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/wait_style_all.go (about) 1 package html 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/drivers" 7 "github.com/MontFerret/ferret/pkg/runtime/core" 8 "github.com/MontFerret/ferret/pkg/runtime/values" 9 "github.com/MontFerret/ferret/pkg/runtime/values/types" 10 ) 11 12 // WAIT_STYLE_ALL waits until a target style value appears on all matched elements with a given value. 13 // @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node. 14 // @param {String} styleNameOrSelector - Style name or CSS selector. 15 // @param {String | Any} valueOrStyleName - Style value or name. 16 // @param {Any | Int} [valueOrTimeout] - Style value or wait timeout. 17 // @param {Int} [timeout=5000] - Timeout. 18 func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) { 19 return waitStyleAllWhen(ctx, args, drivers.WaitEventPresence) 20 } 21 22 // WAIT_NO_STYLE_ALL waits until a target style value disappears on all matched elements with a given value. 23 // @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node. 24 // @param {String} styleNameOrSelector - Style name or CSS selector. 25 // @param {String | Any} valueOrStyleName - Style value or name. 26 // @param {Any | Int} [valueOrTimeout] - Style value or wait timeout. 27 // @param {Int} [timeout=5000] - Timeout. 28 func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) { 29 return waitStyleAllWhen(ctx, args, drivers.WaitEventAbsence) 30 } 31 32 func waitStyleAllWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) { 33 err := core.ValidateArgs(args, 4, 5) 34 35 if err != nil { 36 return values.None, err 37 } 38 39 el, err := drivers.ToElement(args[0]) 40 41 if err != nil { 42 return values.None, err 43 } 44 45 // selector 46 selector, err := drivers.ToQuerySelector(args[1]) 47 48 if err != nil { 49 return values.None, err 50 } 51 52 // attr name 53 err = core.ValidateType(args[2], types.String) 54 55 if err != nil { 56 return values.None, err 57 } 58 59 name := args[2].(values.String) 60 value := args[3] 61 timeout := values.NewInt(drivers.DefaultWaitTimeout) 62 63 if len(args) == 5 { 64 err = core.ValidateType(args[4], types.Int) 65 66 if err != nil { 67 return values.None, err 68 } 69 70 timeout = args[4].(values.Int) 71 } 72 73 ctx, fn := waitTimeout(ctx, timeout) 74 defer fn() 75 76 return values.True, el.WaitForStyleBySelectorAll(ctx, selector, name, value, when) 77 }