github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/blur.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/values"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/core"
    10  )
    11  
    12  // BLUR Calls blur on the element.
    13  // @param {HTMLPage | HTMLDocument | HTMLElement} node - Target node.
    14  // @param {String} [selector] - CSS selector.
    15  func Blur(ctx context.Context, args ...core.Value) (core.Value, error) {
    16  	err := core.ValidateArgs(args, 1, 2)
    17  
    18  	if err != nil {
    19  		return values.None, err
    20  	}
    21  
    22  	el, err := drivers.ToElement(args[0])
    23  
    24  	if err != nil {
    25  		return values.None, err
    26  	}
    27  
    28  	if len(args) == 1 {
    29  		return values.None, el.Blur(ctx)
    30  	}
    31  
    32  	selector, err := drivers.ToQuerySelector(args[1])
    33  
    34  	if err != nil {
    35  		return values.None, err
    36  	}
    37  
    38  	return values.None, el.BlurBySelector(ctx, selector)
    39  }