1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-03 00:46:51 +02:00

Refactored methods (#376)

* Refactored methods

* Fixed errors provided by go vet
This commit is contained in:
Tim Voronov
2019-09-06 23:15:27 -04:00
committed by GitHub
parent c773509469
commit 24370d8178
11 changed files with 65 additions and 152 deletions

View File

@ -2,6 +2,7 @@ package html
import (
"context"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
@ -17,22 +18,15 @@ func Focus(ctx context.Context, args ...core.Value) (core.Value, error) {
return values.None, err
}
// Document with selector
if len(args) == 2 {
doc, err := drivers.ToDocument(args[0])
if err != nil {
return values.None, err
}
return values.None, doc.FocusBySelector(ctx, values.ToString(args[1]))
}
el, err := drivers.ToElement(args[0])
if err != nil {
return values.None, err
}
return values.None, el.Focus(ctx)
if len(args) == 1 {
return values.None, el.Focus(ctx)
}
return values.None, el.FocusBySelector(ctx, values.ToString(args[1]))
}