Example #1
0
func ok(kp *js.Object) {
	print("ok")
	print(kp)
	fmt.Printf("%d\n", kp.Get("byteLength").Int())
	x := tmp.Call("view", kp)
	log.Println(x)
}
Example #2
0
func copyStruct(dst, src js.Object, typ Type) {
	fields := jsType(typ).Get("fields")
	for i := 0; i < fields.Length(); i++ {
		name := fields.Index(i).Index(0).Str()
		dst.Set(name, src.Get(name))
	}
}
Example #3
0
func (d *Domain) Register(endpoint string, handler *js.Object) *js.Object {
	cb := core.NewID()
	var p promise.Promise

	go func() {
		// From the want wrapper pull out the types they defined,
		// and pass them down into the core.
		h := handler.Get("types")
		tmp := h.Interface()
		types, hasTypes := tmp.([]interface{})

		// handler can either be:
		// 1. an object that contains "types" and "fp" attributes.
		// 2. a naked function, in which case we tell the core that it doesn't
		// care about types.
		handlerFunction := handler
		handlerTypes := []interface{}{nil}
		if hasTypes {
			handlerFunction = handler.Get("fp")
			handlerTypes = types
		}

		if err := d.coreDomain.Register(endpoint, cb, handlerTypes); err == nil {
			d.app.registrations[cb] = handlerFunction
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
Example #4
0
func stringable(t *js.Object) bool {
	switch t.Get("kind").Int() {
	case boolKind, int8Kind, int16Kind, int32Kind, intKind, uint8Kind, uint16Kind, uint32Kind, uintKind, int64Kind, uint64Kind, float32Kind, float64Kind, stringKind:
		return true
	}
	return false
}
Example #5
0
func (v Value) Slice3(i, j, k int) Value {
	var (
		cap int
		typ Type
		s   *js.Object
	)
	switch kind := v.kind(); kind {
	case Array:
		if v.flag&flagAddr == 0 {
			panic("reflect.Value.Slice: slice of unaddressable array")
		}
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		cap = int(tt.len)
		typ = SliceOf(tt.elem)
		s = jsType(typ).New(v.object())

	case Slice:
		typ = v.typ
		s = v.object()
		cap = s.Get("$capacity").Int()

	default:
		panic(&ValueError{"reflect.Value.Slice3", kind})
	}

	if i < 0 || j < i || k < j || k > cap {
		panic("reflect.Value.Slice3: slice index out of bounds")
	}

	return makeValue(typ, js.Global.Call("$subslice", s, i, j, k), v.flag&flagRO)
}
Example #6
0
File: gujs.go Project: influx6/gu
// QuerySelectorAll returns the result of querySelectorAll on an object
func QuerySelectorAll(o *js.Object, sel string) []*js.Object {
	if sad := o.Get("querySelectorAll"); sad == nil || sad == js.Undefined {
		return nil
	}

	return DOMObjectToList(o.Call("querySelectorAll", sel))
}
Example #7
0
func ConsoleEvent(name string, event *jquery.Event, data *js.Object) {
	page := data.Get("toPage").String()
	if page == "[object Object]" {
		page = data.Get("toPage").Call("jqmData", "url").String()
	}
	console.Log("Event: %s, Current page: %s", name, page)
}
Example #8
0
func printValueAt(e js.Object, name string, value string) {
	targets := []js.Object{}
	if e.Get("name").Str() == name {
		targets = append(targets, e)
	}
	query := fmt.Sprintf("*[name=\"%s\"]", html.EscapeString(name))
	es := e.Call("querySelectorAll", query)
	for i := 0; i < es.Length(); i++ {
		targets = append(targets, es.Index(i))
	}

	if e.Get("dataset").Get(toDatasetProp(datasetAttrKey)).Str() == name {
		targets = append(targets, e)
	}
	query = fmt.Sprintf(
		"*[data-%s=\"%s\"]",
		html.EscapeString(datasetAttrKey),
		html.EscapeString(name))
	es = e.Call("querySelectorAll", query)
	for i := 0; i < es.Length(); i++ {
		targets = append(targets, es.Index(i))
	}

	for _, e := range targets {
		if e.Call("hasAttribute", "value").Bool() {
			e.Set("value", value)
		} else {
			e.Set("textContent", value)
		}
	}
}
Example #9
0
func copyStruct(dst, src *js.Object, typ Type) {
	fields := jsType(typ).Get("fields")
	for i := 0; i < fields.Length(); i++ {
		prop := fields.Index(i).Get("prop").String()
		dst.Set(prop, src.Get(prop))
	}
}
Example #10
0
File: dom.go Project: influx6/gu
// TriggerBindEvent connects the giving event with the provided dom target.
func (dm *DOMRenderer) TriggerBindEvent(event *gjs.Object, root *gjs.Object, source *trees.Event) {
	target := event.Get("target")

	children := root.Call("querySelectorAll", source.Target())
	if children == nil || children == gjs.Undefined {
		return
	}

	kids := js.DOMObjectToList(children)
	var match bool

	for _, item := range kids {
		if item != target {
			continue
		}

		match = true
		break
	}

	// if we match then run the listeners registered.
	if match {
		dispatch.Dispatch(trees.EventBroadcast{
			EventID: source.EventID,
			Event:   trees.NewWrapperEvent(event),
		})
	}
}
Example #11
0
func NewProxy(proxyObj *js.Object) *Proxy {
	p := new(Proxy)
	p.o = proxyObj
	if proxyObj.String() != "undefined" {
		p.Settings = proxyObj.Get("settings")
	}
	return p
}
Example #12
0
func setMouseCursorFromEvent(e *js.Object) {
	scale := currentUI.scale
	rect := canvas.Call("getBoundingClientRect")
	x, y := e.Get("clientX").Int(), e.Get("clientY").Int()
	x -= rect.Get("left").Int()
	y -= rect.Get("top").Int()
	currentInput.setMouseCursor(int(float64(x)/scale), int(float64(y)/scale))
}
Example #13
0
func NewContextMenus(contextMenusObj *js.Object) *ContextMenus {
	c := new(ContextMenus)
	c.o = contextMenusObj
	if c.o.String() != "undefined" {
		c.ACTION_MENU_TOP_LEVEL_LIMIT = contextMenusObj.Get("ACTION_MENU_TOP_LEVEL_LIMIT").Int()
	}
	return c
}
Example #14
0
File: pali.go Project: siongui/pali
func handleInputKeyUp(event *js.Object) {
	if keycode := event.Get("keyCode").Int(); keycode == 13 {
		// user press enter key
		w := word.Get("value").String()
		word.Call("blur")
		go httpGetWordJson(w)
	}
}
Example #15
0
func New(el *js.Object) *Canvas {
	return &Canvas{
		Element: el,
		ctx:     el.Call("getContext", "2d"),
		Width:   el.Get("width").Int(),
		Height:  el.Get("height").Int(),
	}
}
Example #16
0
// DOMObjectToList takes a jsobjects and returns a list of internal objects by calling the item method
func DOMObjectToList(o *js.Object) []*js.Object {
	var out []*js.Object
	length := o.Get("length").Int()
	for i := 0; i < length; i++ {
		out = append(out, o.Call("item", i))
	}
	return out
}
Example #17
0
func setMouseCursorFromEvent(e *js.Object) {
	scale := canvas.Get("dataset").Get("ebitenScale").Int()
	rect := canvas.Call("getBoundingClientRect")
	x, y := e.Get("clientX").Int(), e.Get("clientY").Int()
	x -= rect.Get("left").Int()
	y -= rect.Get("top").Int()
	currentInput.SetMouseCursor(x/scale, y/scale)
}
Example #18
0
func getProterty(obj *js.Object, ps []string) *js.Object {
	for _, p := range ps {
		obj = obj.Get(p)
		if obj == js.Undefined {
			break
		}
	}
	return obj
}
Example #19
0
func uint8ArrayToArrayBuffer(p *js.Object) *js.Object {
	buffer := p.Get("buffer")
	byteOffset := p.Get("byteOffset").Int()
	byteLength := p.Get("byteLength").Int()
	if byteOffset != 0 || byteLength != buffer.Get("byteLength").Int() {
		return buffer.Call("slice", byteOffset, byteOffset+byteLength)
	}
	return buffer
}
Example #20
0
func getFrameData(obj *js.Object) []byte {
	// Check if it's an array buffer. If so, convert it to a Go byte slice.
	if constructor := obj.Get("constructor"); constructor == js.Global.Get("ArrayBuffer") {
		int8Array := js.Global.Get("Uint8Array").New(obj)
		return int8Array.Interface().([]byte)
	}

	return []byte(obj.String())
}
Example #21
0
func (self *pane) pix2Vec(evnt *js.Object) mgl32.Vec2 {
	v := mgl32.Vec3{ // generate vector from current pixel coords
		float32(evnt.Get("clientX").Float()),
		float32(evnt.Get("clientY").Float()),
		1.0, // apply translations from transform matrix
	}
	v = self.untransform.Mul3x1(v) // apply pan & zoom untransform matrix

	return v.Vec2() // return vec2
}
Example #22
0
// EmptyTextNode returns two bool values, the first indicating if its a text node and the second indicating if the text node is empty
func EmptyTextNode(o *js.Object) (bool, bool) {
	if o.Get("nodeType").Int() == 3 {
		textContent := strings.TrimSpace(o.Get("textContent").String())
		if textContent != "" {
			return true, false
		}
		return true, true
	}
	return false, false
}
func findIds(element *js.Object, set map[string]bool) []string {
	ids := []string{}
	for element != nil {
		id := element.Get("id").String()
		if set[id] {
			ids = append(ids, id)
		}
		element = element.Get("parentNode")
	}
	return ids
}
Example #24
0
// JqmTargetUri determines the target URI based on a jQuery Mobile event 'ui' object
func JqmTargetUri(ui *js.Object) string {
	rawUrl := ui.Get("toPage").String()
	if rawUrl == "[object Object]" {
		rawUrl = ui.Get("toPage").Call("jqmData", "url").String()
	}
	pageUrl, _ := url.Parse(rawUrl)
	pageUrl.Path = strings.TrimPrefix(pageUrl.Path, "/android_asset/www")
	pageUrl.Host = ""
	pageUrl.User = nil
	pageUrl.Scheme = ""
	return pageUrl.String()
}
Example #25
0
//convert object with string fields into one with parsed fields
func filterIntData(obj js.Object) js.Object {
	result := js.Global.Get("Object").New()
	result.Set("name", obj.Get("name").Str())
	s := obj.Get("value").Str()
	i, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		console.Error("unable to parse ", s, " in the dataset: IGNORED")
		return nil
	}
	result.Set("value", i)
	return result
}
Example #26
0
// JqmTargetUri determines the target URI based on a jQuery Mobile event 'ui' object
func JqmTargetUri(ui *js.Object) string {
	rawUrl := ui.Get("toPage").String()
	if rawUrl == "[object Object]" {
		rawUrl = ui.Get("toPage").Call("jqmData", "url").String()
	}
	pageUrl, _ := url.Parse(rawUrl)
	path := strings.TrimPrefix(pageUrl.Path, "/android_asset/www")
	if len(pageUrl.Fragment) > 0 {
		return path + "#" + pageUrl.Fragment
	}
	return "/" + strings.TrimPrefix(path, "/")
}
Example #27
0
func getIDElement(e js.Object) js.Object {
	for {
		attr := e.Get("dataset").Get(toDatasetProp(datasetAttrID))
		if !attr.IsUndefined() {
			return e
		}
		e = e.Get("parentNode")
		if e.IsNull() || e.IsUndefined() {
			break
		}
	}
	return nil
}
Example #28
0
func filterFloatData(obj js.Object) js.Object {
	result := js.Global.Get("Object").New()
	result.Set("letter", obj.Get("letter").Str())
	s := obj.Get("frequency").Str()
	f, err := strconv.ParseFloat(s, 64)
	if err != nil {
		console.Error("unable to parse ", s, " in the dataset: IGNORED")
		return nil
	}
	result.Set("frequency", f)
	return result

}
Example #29
0
File: dom.go Project: influx6/govfx
// PageBox returns the offset of the current page bounding box.
func PageBox() (float64, float64) {
	var cursor *js.Object

	if useDocForOffset {
		cursor = Document().Underlying()
	} else {
		cursor = Root()
	}

	top := cursor.Get(topScrollAttr)
	left := cursor.Get(leftScrollAttr)
	return ParseFloat(top.String()), ParseFloat(left.String())
}
Example #30
0
func (a *audioProcessor) Process(e *js.Object) {
	// Can't use 'go' here. Probably it may cause race conditions.
	b := e.Get("outputBuffer")
	l := b.Call("getChannelData", 0)
	r := b.Call("getChannelData", 1)
	inputL, inputR := toLR(loadChannelBuffer(a.channel, bufferSize*4))
	const max = 1 << 15
	for i := 0; i < len(inputL); i++ {
		// TODO: Use copyToChannel?
		l.SetIndex(i, float64(inputL[i])/max)
		r.SetIndex(i, float64(inputR[i])/max)
	}
}