Skip to content

Commit

Permalink
Added SCROLL_TOP and SCROLL_BOTTOM (MontFerret#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex authored and Владимир Фетисов committed Apr 10, 2019
1 parent cdb9a46 commit c89014b
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/stdlib/html/scroll.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package html

import (
"context"
"github.com/MontFerret/ferret/pkg/html/dynamic"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)

// ScrollTop Scrolls the document's window to its top.
// @param doc (Document) - Target document.
func ScrollTop(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

if err != nil {
return values.None, err
}

err = core.ValidateType(args[0], core.HTMLDocumentType)

if err != nil {
return values.None, err
}

doc, ok := args[0].(*dynamic.HTMLDocument)

if !ok {
return values.None, core.Errors(core.ErrInvalidType, ErrNotDynamic)
}

return values.None, doc.ScrollTop()
}

// ScrollTop Scrolls the document's window to its bottom.
// @param doc (Document) - Target document.
func ScrollBottom(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

if err != nil {
return values.None, err
}

err = core.ValidateType(args[0], core.HTMLDocumentType)

if err != nil {
return values.None, err
}

doc, ok := args[0].(*dynamic.HTMLDocument)

if !ok {
return values.None, core.Errors(core.ErrInvalidType, ErrNotDynamic)
}

return values.None, doc.ScrollBottom()
}

0 comments on commit c89014b

Please sign in to comment.