예제 #1
0
func RunPreparation() {
	Time = NewClock()

	dom.GetWindow().AddEventListener("onbeforeunload", false, func(e dom.Event) {
		dom.GetWindow().Alert("You're closing")
	})
}
예제 #2
0
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},
			}))
		}()
	})
}
예제 #3
0
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)
	}
}
예제 #4
0
파일: main.go 프로젝트: captncraig/gc6
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()
		})
}
예제 #5
0
파일: html.go 프로젝트: gmlewis/go-frp
// 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
}
예제 #6
0
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)
	})
}
예제 #7
0
파일: frontend.go 프로젝트: beyang/frontend
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()
}
예제 #8
0
파일: frontend.go 프로젝트: beyang/frontend
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()
}
예제 #9
0
func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("pali").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, paliIME)
}
예제 #10
0
파일: input.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("foo").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, inputKeyUp)
}
예제 #11
0
파일: page.go 프로젝트: kego/ke
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)
				}()
			}
		}
	})
}
예제 #12
0
파일: client.go 프로젝트: kego/ke
func getRawInfo() string {
	return dom.
		GetWindow().
		Document().(dom.HTMLDocument).
		GetElementByID("body").(*dom.HTMLBodyElement).
		GetAttribute("info")
}
예제 #13
0
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),
			),
		)
	}
}
예제 #14
0
파일: hello.go 프로젝트: influx6/gu
func main() {

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

}
예제 #15
0
파일: hide.go 프로젝트: siongui/userpages
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", "")
	})
}
예제 #16
0
func translate(value string) {
	d := dom.GetWindow().Document()
	elements := d.QuerySelectorAll("[data-default-string]")
	for _, element := range elements {
		elm := element.(*dom.HTMLDivElement)
		elm.SetTextContent(gettext(value, elm.Dataset()["defaultString"]))
	}
}
예제 #17
0
func main() {
	example := dom.GetWindow().Document().GetElementByID("example")
	m.Mount(
		example,
		js.M{
			"view":       js.MakeFunc(View),
			"controller": js.MakeFunc(Controller)},
	)
}
예제 #18
0
func main() {
	w := dom.GetWindow()
	s := w.Document().GetElementByID("foo")

	w.AddEventListener("keydown", false, func(event dom.Event) {
		ke := event.(*dom.KeyboardEvent)
		s.SetInnerHTML(strconv.Itoa(ke.KeyCode))
	})
}
예제 #19
0
파일: app.go 프로젝트: influx6/gu
// New returns a new design.Resources activating the DOMRenderer if its gets called
// on the browser or else on the server.
func New() *design.Resources {
	if detect.IsBrowser() {
		return design.New(&redom.DOMRenderer{
			Document: dom.GetWindow().Document(),
		})
	}

	return design.New()
}
예제 #20
0
// Add adds the given CSS string to the DOM
func Add(css string) dom.Element {
	h := dom.GetWindow().Document().GetElementsByTagName("head")
	if len(h) == 0 {
		return nil
	}
	s := xdom.Style()
	h[0].AppendChild(xjs.SetInnerText(s, css))
	return s
}
예제 #21
0
파일: html.go 프로젝트: gmlewis/go-frp
// Render renders a view and writes it to the DOM.
func Render(view Viewer, rootUpdateFunc interface{}) {
	// log.Printf("GML: html.Render(view=%#v, rootUpdateFunc=%#v)", view, rootUpdateFunc)
	v := view.View(rootUpdateFunc, nil)
	str, initFuncs := v.Render()
	dom.GetWindow().Document().GetElementByID(domNode).SetInnerHTML(str)
	for _, initFunc := range initFuncs {
		initFunc()
	}
}
예제 #22
0
파일: main.go 프로젝트: influx6/gu
func main() {
	win := dom.GetWindow()
	doc := win.Document()

	tick := anix.Animate(Width(400))
	tick(doc.QuerySelector("div"))

	tick.Start()
}
예제 #23
0
파일: data.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()

	div1 := d.GetElementByID("foo").(*dom.HTMLDivElement)
	print(div1.Dataset()["myDemoValue"])

	div2 := d.GetElementByID("foo2").(*dom.HTMLDivElement)
	print(div2.Dataset()["hello"])
}
예제 #24
0
파일: bind.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()
	h := d.GetElementByID("foo")

	h.AddEventListener("click", false, func(event dom.Event) {
		event.PreventDefault()
		h.SetInnerHTML("I am Clicked")
		println("This message is printed in browser console")
	})
}
예제 #25
0
파일: append.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()

	foo := d.GetElementByID("foo").(*dom.HTMLDivElement)
	foo.AddEventListener("click", false, func(event dom.Event) {
		div := d.CreateElement("div").(*dom.HTMLDivElement)
		div.Style().SetProperty("color", "red", "")
		div.SetTextContent("I am new div")
		foo.AppendChild(div)
	})
}
예제 #26
0
파일: login.go 프로젝트: steveoc64/gold
func Hide() {

	window := dom.GetWindow().(*dom.Window)
	doc := window.Document().(*dom.Document)

	// hide login, and change to logout btn
	lf := doc.GetElementByID(lfid).(*dom.HTMLDivElement)
	lf.Style().SetProperty("display", "none", "")
	lb := doc.GetElementByID("nav-login-btn")
	lb.SetTextContent("Logout")
}
예제 #27
0
파일: index.go 프로젝트: snyderep/pongish
func getWSBaseURL() string {
	document := dom.GetWindow().Document().(dom.HTMLDocument)
	location := document.Location()

	wsProtocol := "ws"
	if location.Protocol == "https:" {
		wsProtocol = "wss"
	}

	return fmt.Sprintf("%s://%s:%s/ws/", wsProtocol, location.Hostname, location.Port)
}
예제 #28
0
파일: play.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()

	foo := d.GetElementByID("foo").(*dom.HTMLButtonElement)
	foo.AddEventListener("click", false, func(event dom.Event) {
		a := d.GetElementByID("audio").(*dom.HTMLAudioElement)
		// already specify source in audio tag, no need to set src
		//a.SetAttribute("src", "Wat_Metta_Buddha_Qualities.mp3")
		a.Play()
	})
}
예제 #29
0
파일: toggle.go 프로젝트: siongui/userpages
func main() {
	d := dom.GetWindow().Document()
	foo := d.GetElementByID("foo").(*dom.HTMLDivElement)
	foo1 := d.GetElementByID("foo1").(*dom.HTMLSpanElement)
	foo2 := d.GetElementByID("foo2").(*dom.HTMLSpanElement)
	foo3 := d.GetElementByID("foo3").(*dom.HTMLDivElement)
	foo.AddEventListener("click", false, func(event dom.Event) {
		foo1.Class().Toggle("invisible")
		foo2.Class().Toggle("invisible")
		foo3.Class().Toggle("invisible")
	})
}
예제 #30
0
파일: main.go 프로젝트: captncraig/gc6
func render(c *renderData) {
	dom.GetWindow().Document().GetElementByID("stepCount").(*dom.HTMLSpanElement).SetTextContent(fmt.Sprint(c.count))
	ctx := dom.GetWindow().Document().GetElementByID("dc").(*dom.HTMLCanvasElement).GetContext2d()
	ctx.ClearRect(0, 0, 10000, 10000)
	startX, startY := c.maze.Start()
	endX, endY := c.maze.End()
	curX, curY := c.maze.Icarus()
	for y := 0; y < c.maze.Height(); y++ {
		for x := 0; x < c.maze.Width(); x++ {
			fillCell(ctx, x, y, "white")
			if x == curX && y == curY {
				fillCell(ctx, x, y, "pink")
			} else if x == startX && y == startY {
				fillCell(ctx, x, y, "orange")
			} else if x == endX && y == endY {
				fillCell(ctx, x, y, "yellow")
			}
			drawBorders(c, ctx, x, y)
		}
	}
}