66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package elements
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gopherjs/gopherjs/js"
|
|
|
|
"go.dev.pztrn.name/bulpherjs/common"
|
|
"go.dev.pztrn.name/bulpherjs/metas"
|
|
)
|
|
|
|
const (
|
|
sectionDefaultClass = "section"
|
|
)
|
|
|
|
// SectionOptions is a "section" HTML element configuration structure.
|
|
type SectionOptions struct {
|
|
Class string
|
|
}
|
|
|
|
// Section is a controlling structure for "section" HTML element.
|
|
type Section struct {
|
|
metas.Generic
|
|
|
|
options *SectionOptions
|
|
}
|
|
|
|
// NewSection creates new "section" HTML element controlling structure.
|
|
func NewSection(sectionOptions *SectionOptions) *Section {
|
|
s := &Section{}
|
|
s.initialize(sectionOptions)
|
|
|
|
return s
|
|
}
|
|
|
|
// Build builds element and calls Build() for all child elements.
|
|
func (s *Section) Build() *js.Object {
|
|
s.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementSection)
|
|
|
|
if s.options == nil {
|
|
s.AddClassesFromString(sectionDefaultClass)
|
|
s.BuildChilds(s.Object)
|
|
|
|
return s.Object
|
|
}
|
|
|
|
if !strings.Contains(s.options.Class, "section") {
|
|
s.options.Class += " section"
|
|
}
|
|
|
|
if s.options.Class != "" {
|
|
s.AddClassesFromString(s.options.Class)
|
|
}
|
|
|
|
s.BuildChilds(s.Object)
|
|
|
|
return s.Object
|
|
}
|
|
|
|
// Initializes controlling structure with necessary parameters.
|
|
func (s *Section) initialize(sectionOptions *SectionOptions) {
|
|
s.options = sectionOptions
|
|
|
|
s.InitializeGeneric()
|
|
}
|