github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/scroll_bottom.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  )
    10  
    11  // SCROLL_BOTTOM scrolls the document's window to its bottom.
    12  // @param {HTMLDocument} document - HTML document.
    13  // @param {Int | Float} x - X coordinate.
    14  // @param {Int | Float} y - Y coordinate.
    15  // @param {Object} [params] - Scroll params.
    16  // @param {String} [params.behavior="instant"] - Scroll behavior
    17  // @param {String} [params.block="center"] - Scroll vertical alignment.
    18  // @param {String} [params.inline="center"] - Scroll horizontal alignment.
    19  func ScrollBottom(ctx context.Context, args ...core.Value) (core.Value, error) {
    20  	err := core.ValidateArgs(args, 1, 2)
    21  
    22  	if err != nil {
    23  		return values.None, err
    24  	}
    25  
    26  	doc, err := drivers.ToDocument(args[0])
    27  
    28  	if err != nil {
    29  		return values.None, err
    30  	}
    31  
    32  	var opts drivers.ScrollOptions
    33  
    34  	if len(args) > 1 {
    35  		opts, err = toScrollOptions(args[1])
    36  
    37  		if err != nil {
    38  			return values.None, err
    39  		}
    40  	}
    41  
    42  	return values.True, doc.ScrollBottom(ctx, opts)
    43  }