-
Notifications
You must be signed in to change notification settings - Fork 0
/
iframe_expand_host.go
44 lines (37 loc) · 1.18 KB
/
iframe_expand_host.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
package compton
import (
_ "embed"
"github.com/boggydigital/compton/consts/compton_atoms"
"io"
)
var (
//go:embed "script/iframe_expand_receive.js"
scriptIframeExpandReceive []byte
)
type IframeExpandElement struct {
BaseElement
r Registrar
iframe Element
}
func (ife *IframeExpandElement) Write(w io.Writer) error {
return ife.iframe.Write(w)
}
// IframeExpandHost creates iframe-expand that will expand height to content height.
// In order to achieve that, two scripts need to be present
// script/receive.js on the host page (the page that contains iframe element)
// script/post.js within the iframe page. See NewContent that creates the page
// with that script. Initially host iframe has opacity: 0 through `loading`
// class to avoid flash of white content as iframe loads
func IframeExpandHost(r Registrar, id, src string) Element {
iframe := IframeLazy(src)
iframe.SetId(id)
iframe.AddClass("loading")
r.RegisterStyles(DefaultStyle,
compton_atoms.StyleName(compton_atoms.IframeExpandHost))
r.RegisterRequirements(compton_atoms.ScriptName(compton_atoms.IframeExpandHost),
Script(scriptIframeExpandReceive))
return &IframeExpandElement{
r: r,
iframe: iframe,
}
}