Exemple #1
0
func RunPreparation() {
	Time = NewClock()

	dom.GetWindow().AddEventListener("onbeforeunload", false, func(e dom.Event) {
		dom.GetWindow().Alert("You're closing")
	})
}
Exemple #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},
			}))
		}()
	})
}
Exemple #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)
	}
}
Exemple #4
0
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()
		})
}
Exemple #5
0
// 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
}
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)
	})
}
Exemple #7
0
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()
}
Exemple #8
0
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()
}
func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("pali").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, paliIME)
}
Exemple #10
0
func main() {
	d := dom.GetWindow().Document()
	p := d.GetElementByID("foo").(*dom.HTMLInputElement)

	p.Focus()
	p.AddEventListener("keyup", false, inputKeyUp)
}
Exemple #11
0
Fichier : page.go Projet : 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)
				}()
			}
		}
	})
}
Exemple #12
0
func getRawInfo() string {
	return dom.
		GetWindow().
		Document().(dom.HTMLDocument).
		GetElementByID("body").(*dom.HTMLBodyElement).
		GetAttribute("info")
}
Exemple #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),
			),
		)
	}
}
Exemple #14
0
func main() {

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

}
Exemple #15
0
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", "")
	})
}
Exemple #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"]))
	}
}
Exemple #17
0
func main() {
	example := dom.GetWindow().Document().GetElementByID("example")
	m.Mount(
		example,
		js.M{
			"view":       js.MakeFunc(View),
			"controller": js.MakeFunc(Controller)},
	)
}
Exemple #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))
	})
}
Exemple #19
0
// 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()
}
Exemple #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
}
Exemple #21
0
// 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()
	}
}
Exemple #22
0
func main() {
	win := dom.GetWindow()
	doc := win.Document()

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

	tick.Start()
}
Exemple #23
0
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"])
}
Exemple #24
0
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")
	})
}
Exemple #25
0
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)
	})
}
Exemple #26
0
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")
}
Exemple #27
0
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)
}
Exemple #28
0
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()
	})
}
Exemple #29
0
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")
	})
}
Exemple #30
0
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)
		}
	}
}