當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dom.GetWindow函數代碼示例

本文整理匯總了Golang中honnef/co/go/js/dom.GetWindow函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetWindow函數的具體用法?Golang GetWindow怎麽用?Golang GetWindow使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetWindow函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunPreparation

func RunPreparation() {
	Time = NewClock()

	dom.GetWindow().AddEventListener("onbeforeunload", false, func(e dom.Event) {
		dom.GetWindow().Alert("You're closing")
	})
}
開發者ID:matiwinnetou,項目名稱:engi,代碼行數:7,代碼來源:engo_js.go

示例2: main

func main() {
	dom.GetWindow().AddEventListener("load", false, func(dom.Event) {
		go func() {
			if err := rpcInit(); err != nil {
				xjs.Alert("Failed to connect to RPC server: %s", err)
				return
			}
			title, err := RPC.ServerName()
			if err != nil {
				xjs.Alert("Error retrieving server name: %s", err)
				return
			}
			body := dom.GetWindow().Document().(dom.HTMLDocument).Body()
			body.Underlying().Set("spellcheck", "false")
			xjs.RemoveChildren(body)
			body.AppendChild(xdom.H1())
			SetTitle(title)
			body.AppendChild(tabs.New([]tabs.Tab{
				{"Servers", ServersTab()},
				{"Maps", MapsTab()},
				{"Generators", GeneratorsTab},
				{"Settings", settingsTab},
			}))
		}()
	})
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:26,代碼來源:main.go

示例3: SetTitle

func SetTitle(title string) {
	title += " Server"
	xjs.SetInnerText(dom.GetWindow().Document().(dom.HTMLDocument).Body().ChildNodes()[0], title)
	tDoc, ok := dom.GetWindow().Document().(dom.HTMLDocument)
	if ok {
		tDoc.SetTitle(title)
	}
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:8,代碼來源:main.go

示例4: setupEvents

func setupEvents() {
	dom.GetWindow().Document().GetElementByID("init").
		AddEventListener("click", false, func(dom.Event) {
			go initialize()
		})
	dom.GetWindow().Document().GetElementByID("step").
		AddEventListener("click", false, func(dom.Event) {
			step()
		})
	dom.GetWindow().Document().GetElementByID("run").
		AddEventListener("click", false, func(dom.Event) {
			go run()
		})
}
開發者ID:captncraig,項目名稱:gc6,代碼行數:14,代碼來源:main.go

示例5: On

// On adds an event handler to an HTML element.
func (s HTML) On(event string, rootUpdateFunc, updateFunc, actionFunc interface{}) HTML {
	id := s.ID()
	s.initFuncs = append(s.initFuncs, func() {
		el := dom.GetWindow().Document().GetElementByID(id)
		if el == nil {
			log.Printf("unable to find DOM element id=%q", id)
			return
		}
		el.AddEventListener(event, false, func(de dom.Event) {
			go func() {
				u := reflect.ValueOf(updateFunc)
				// log.Printf("GML: updateFunc=%#v, u=%#v", updateFunc, u)
				a := reflect.ValueOf(actionFunc)
				// log.Printf("GML: actionFunc=%#v, a=%#v, a.Type=%q", actionFunc, a, a.Type())
				args := []reflect.Value{a}
				if reflect.TypeOf(updateFunc).NumIn() == 2 {
					var e interface{} = de
					args = append(args, reflect.ValueOf(e))
				}
				newModel := u.Call(args)
				// log.Printf("GML: in click handler! len(newModel)=%v", len(newModel))
				// log.Printf("GML: in click handler! newModel[0]=%v", newModel[0])
				// log.Printf("GML: in click handler! newModel[0].Type=%v", newModel[0].Type())
				if view, ok := newModel[0].Interface().(Viewer); ok {
					Render(view, rootUpdateFunc)
				}
			}()
		})
	})
	return s
}
開發者ID:gmlewis,項目名稱:go-frp,代碼行數:32,代碼來源:html.go

示例6: draggable

func draggable(elm *dom.HTMLDivElement) {
	var startX, startY, initialMouseX, initialMouseY int
	var fmove, fup func(*js.Object)
	elm.Style().SetProperty("position", "absolute", "")
	d := dom.GetWindow().Document()

	mousemove := func(event dom.Event) {
		event.PreventDefault()
		e := event.(*dom.MouseEvent)
		dx := e.ClientX - initialMouseX
		dy := e.ClientY - initialMouseY
		elm.Style().SetProperty("top", strconv.Itoa(startY+dy)+"px", "")
		elm.Style().SetProperty("left", strconv.Itoa(startX+dx)+"px", "")
	}

	mouseup := func(event dom.Event) {
		d.RemoveEventListener("mousemove", false, fmove)
		d.RemoveEventListener("mouseup", false, fup)
	}

	elm.AddEventListener("mousedown", false, func(event dom.Event) {
		event.PreventDefault()
		e := event.(*dom.MouseEvent)
		startX = int(elm.OffsetLeft())
		startY = int(elm.OffsetTop())
		initialMouseX = e.ClientX
		initialMouseY = e.ClientY
		fmove = d.AddEventListener("mousemove", false, mousemove)
		fup = d.AddEventListener("mouseup", false, mouseup)
	})
}
開發者ID:steveoc64,項目名稱:gopherjs-experiments,代碼行數:31,代碼來源:app.go

示例7: SelectMenuOnInput

func SelectMenuOnInput(event dom.Event, object dom.HTMLElement, defaultOption, queryParameter string) {
	rawQuery := strings.TrimPrefix(dom.GetWindow().Location().Search, "?")
	query, _ := url.ParseQuery(rawQuery)

	selectElement := object.(*dom.HTMLSelectElement)

	selected := selectElement.SelectedOptions()[0].Text

	if selected == defaultOption {
		query.Del(queryParameter)
	} else {
		query.Set(queryParameter, selected)
	}

	dom.GetWindow().Location().Search = "?" + query.Encode()
}
開發者ID:beyang,項目名稱:frontend,代碼行數:16,代碼來源:frontend.go

示例8: CheckboxOnChange

func CheckboxOnChange(event dom.Event, object dom.HTMLElement, defaultValue bool, queryParameter string) {
	rawQuery := strings.TrimPrefix(dom.GetWindow().Location().Search, "?")
	query, _ := url.ParseQuery(rawQuery)

	inputElement := object.(*dom.HTMLInputElement)

	selected := inputElement.Checked

	if selected == defaultValue {
		query.Del(queryParameter)
	} else {
		query.Set(queryParameter, "")
	}

	dom.GetWindow().Location().Search = "?" + query.Encode()
}
開發者ID:beyang,項目名稱:frontend,代碼行數:16,代碼來源:frontend.go

示例9: main

func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("pali").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, paliIME)
}
開發者ID:siongui,項目名稱:go-online-input-method-pali,代碼行數:7,代碼來源:pali.go

示例10: main

func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("foo").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, inputKeyUp)
}
開發者ID:siongui,項目名稱:userpages,代碼行數:7,代碼來源:input.go

示例11: addKeyboardEvents

func (v *PageView) addKeyboardEvents() {
	window := dom.GetWindow()
	document := window.Document().(dom.HTMLDocument)
	window.AddEventListener("keydown", true, func(e dom.Event) {
		k := e.(*dom.KeyboardEvent)
		switch document.ActiveElement().TagName() {
		case "INPUT", "TEXTAREA", "SELECT":
			if k.KeyCode == 27 {
				// escape
				document.ActiveElement().Blur()
			}
			return
		default:
			switch k.KeyCode {
			case 65:
				// "a"
				addCollectionItem(v.Ctx, v.App, v.App.Nodes.Selected())
			case 37, 38, 39, 40:
				// up, down, left, right
				k.PreventDefault()
				go func() {
					v.KeyPress(k.KeyCode)
				}()
			}
		}
	})
}
開發者ID:kego,項目名稱:ke,代碼行數:27,代碼來源:page.go

示例12: getRawInfo

func getRawInfo() string {
	return dom.
		GetWindow().
		Document().(dom.HTMLDocument).
		GetElementByID("body").(*dom.HTMLBodyElement).
		GetAttribute("info")
}
開發者ID:kego,項目名稱:ke,代碼行數:7,代碼來源:client.go

示例13: misc

func misc(mType string, id int, o *overlay.Overlay, deleteFunc func(int) error) func(dom.Element) {
	return func(c dom.Element) {
		download := xdom.A()
		download.Href = "http://" + js.Global.Get("location").Get("host").String() + "/download/" + mType + "/" + strconv.Itoa(id) + ".zip"
		download.Target = "_blank"
		del := xdom.Button()
		del.AddEventListener("click", false, func(dom.Event) {
			del.Disabled = true
			if dom.GetWindow().Confirm("Are you sure?") {
				go func() {
					err := deleteFunc(id)
					if err != nil {
						del.Disabled = false
						xjs.Alert("Error while deleting %s: %s", mType, err)
					} else {
						o.Close()
					}
				}()
			}
		})
		xjs.AppendChildren(c,
			xjs.AppendChildren(xdom.Fieldset(),
				xjs.SetInnerText(xdom.Legend(), "Download"),
				xjs.SetInnerText(xdom.Div(), "Click the following link to download the "+mType+" as a zip file."),
				xjs.SetInnerText(download, download.Href),
			),
			xjs.AppendChildren(xdom.Fieldset(),
				xjs.SetInnerText(xdom.Legend(), "Delete"),
				xjs.SetInnerText(xdom.Div(), "The following button will permanently delete the "+mType+" (this cannot be undone)."),
				xjs.SetInnerText(del, "Delete "+mType),
			),
		)
	}
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:34,代碼來源:utils.go

示例14: main

func main() {

	New(&DOMRenderer{
		Document: dom.GetWindow().Document(),
	}).Init(true)

}
開發者ID:influx6,項目名稱:gu,代碼行數:7,代碼來源:hello.go

示例15: main

func main() {
	d := dom.GetWindow().Document()

	foo := d.GetElementByID("foo").(*dom.HTMLDivElement)
	foo.AddEventListener("click", false, func(event dom.Event) {
		foo.Style().SetProperty("display", "none", "")
	})
}
開發者ID:siongui,項目名稱:userpages,代碼行數:8,代碼來源:hide.go


注:本文中的honnef/co/go/js/dom.GetWindow函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。