-
Notifications
You must be signed in to change notification settings - Fork 0
/
jumbotron.go
53 lines (43 loc) · 1.03 KB
/
jumbotron.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package beleine
import "fmt"
type Jumbotron struct {
id string
components []Component
fluid bool
js string
}
//Create Jumbotron struct
func NewJumbotron() Jumbotron {
return Jumbotron{id: GetGlobalID()}
}
//Attach component to Jumbotron
func (j *Jumbotron) Attach(c interface{Component}) {
j.components = append(j.components, c)
}
func (j *Jumbotron) Render() string {
fluidTag := ""
if j.fluid {
fluidTag = " jumbotron-fluid"
}
result := fmt.Sprintf(`<div id="%s" class="jumbotron%s">`, j.id, fluidTag)
for _, c := range j.components {
result += c.Render()
}
result += `</div>`
return result
}
func (j *Jumbotron) RenderJS() string {
return j.js
}
//Enable/disable Jumbotron fluid
func (j *Jumbotron) SetFluid(fluid bool) {
j.fluid = fluid
}
//Returns component ID
func (j *Jumbotron) GetID() string {
return j.id
}
//Sets JS code function, to be executed after click
func (j *Jumbotron) SetOnClickListener(listener string) {
j.js += fmt.Sprintf("%s.onclick = function(){%s};", j.id, listener)
}