Esempio n. 1
0
File: main.go Progetto: theclapp/js
func newVm() *VM {
	vm := new(VM)
	vm.BaseViewModel = ko.NewBaseViewModel()
	vm.List = ko.NewObservableArray([]int{1, 2, 3, 4, 5})
	vm.Doit = func() {
		col := dom.Document().GetElementsByTagName("li")
		println("col:", col.Length, col.Item(0))
		el := dom.Document().QuerySelector("ul")
		els := el.QuerySelectorAll("li")
		println("els:", els.Length, els.Index(0))
	}
	return vm
}
Esempio n. 2
0
File: test.go Progetto: theclapp/js
func test() {
	body := dom.Body()
	div := dom.Document().CreateElement("div")
	div.SetAttribute("id", "div")
	div.SetAttribute("class", "div")
	body.AppendChild(div)
	body.SetAttribute("aaa", 123)
	// println("getAttr", body.GetAttribute)
	println(body.GetAttribute("aaa"))
	// println("Object:", body.Object)
	// println("Body:", body)
	// println("GetElementsByTagName", body.GetElementsByTagName)
	c := body.GetElementsByTagName("div")
	println(c)
	el := c.Item(0)
	println(el.GetAttribute("id"))

	el = body.QuerySelector("div")
	println(el.GetAttribute("id"))
	c = body.QuerySelectorAll("div")
	println(c, c.Length, c.Item(0).GetAttribute("id"))
	println("el:", el)
	el.Style.SetProperty("width", "100")
	el.Style.SetProperty("height", "100")
	el.Style.SetProperty("border", "dotted")
	el.AddEventListener(dom.EvtClick, func(e *dom.Event) {
		println("click:", e, e.ClientX, e.ClientY, e.ScreenX, e.ClientY)
		println("CurrentTarget", e.CurrentTarget)
	})
}
Esempio n. 3
0
File: ko.go Progetto: theclapp/js
// RegisterComponent is used to create KnockoutJS component with more options
func RegisterComponent(c *Component) {
	if c.Style != "" {
		style := dom.Document().CreateElement("style")
		style.InnerHTML = c.Style
		dom.Body().AppendChild(style)
	}
	rawRegisterComponent(c.Name, js.M{
		"template":    c.template(),
		"viewModel":   c.viewModel(),
		"synchronous": c.Synchronous,
	})
}