Documentation
¶
Overview ¶
Package script provides scripting and template elements.
Elements:
- Script: JavaScript code or reference
- Noscript: Fallback for no JavaScript
- Template: HTML template (not rendered)
- Canvas: Graphics canvas
Script attributes:
- Src: External script URL
- Type: Script type (module, text/javascript)
- Async: Load asynchronously
- Defer: Defer execution until DOM ready
- Crossorigin: CORS settings
- Integrity: Subresource integrity hash
- Nomodule: Skip for module-supporting browsers
Canvas attributes:
- [Width], [Height]: Canvas dimensions
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element#scripting
Package script provides HTML scripting elements.
Index ¶
- func Async() attr.Node
- func Blocking(v string) attr.Node
- func Canvas(attrs ...attr.Node) elem.Scope
- func Crossorigin(v string) attr.Node
- func Defer() attr.Node
- func Integrity(v string) attr.Node
- func Nomodule() attr.Node
- func Noscript(attrs ...attr.Node) elem.Scope
- func Referrerpolicy(v string) attr.Node
- func Script(attrs ...attr.Node) elem.Scope
- func Src(v string) attr.Node
- func Template(attrs ...attr.Node) elem.Scope
- func Type(v string) attr.Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canvas ¶
Canvas creates a canvas element.
Example ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/core/attr"
"github.com/protolambda/chord/html/script"
)
func main() {
core.Dump(script.Canvas(attr.ID("game"), attr.KV("width", "800"), attr.KV("height", "600")))
}
Output: <canvas id="game" width="800" height="600"></canvas>
func Noscript ¶
Noscript creates a noscript element.
Example ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/html/script"
"github.com/protolambda/chord/html/text"
)
func main() {
core.Dump(script.Noscript()(text.Text("JavaScript required")))
}
Output: <noscript>JavaScript required</noscript>
func Referrerpolicy ¶
Referrerpolicy sets the referrerpolicy attribute.
func Script ¶
Script creates a script element.
Example ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/html/script"
)
func main() {
core.Dump(script.Script(script.Src("/app.js")))
}
Output: <script src="/app.js"></script>
Example (Inline) ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/core/elem"
"github.com/protolambda/chord/html/script"
)
func main() {
core.Dump(script.Script()(elem.Raw("console.log('hello');")))
}
Output: <script>console.log('hello');</script>
Example (Module) ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/html/script"
)
func main() {
core.Dump(script.Script(script.Type("module"), script.Src("/mod.js")))
}
Output: <script type="module" src="/mod.js"></script>
func Template ¶
Template creates a template element.
Example ¶
package main
import (
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/core/attr"
"github.com/protolambda/chord/html/script"
"github.com/protolambda/chord/html/text"
)
func main() {
core.Dump(script.Template(attr.ID("item-tpl"))(text.Span()(text.Text("Item"))))
}
Output: <template id="item-tpl"><span>Item</span></template>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.