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:
@ -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]))
|
||||
}
|
||||
|
Reference in New Issue
Block a user