Exemple #1
0
func newReaderFromJSObject(in *js.Object) (readerAt, error) {
	if jsbuiltin.InstanceOf(in, js.Global.Get("ArrayBuffer")) {
		return &byteSliceReader{Buf: arrayBufferToByteSlice(in)}, nil
	}
	if jsbuiltin.InstanceOf(in, js.Global.Get("Blob")) {
		return newBlobReader(in), nil
	}
	return nil, errors.New("unsupported input type: " + jsbuiltin.TypeOf(in))
}
Exemple #2
0
// New loads the pouchdb-find plugin (if not already loaded) and returns
// a plugin instance.
func New(db *pouchdb.PouchDB) *PouchPluginFind {
	fnType := jsbuiltin.TypeOf(db.GetJS("createIndex"))
	if fnType == "undefined" {
		// Load the JS plugin
		plugin := js.Global.Call("require", "pouchdb-find")
		pouchdb.Plugin(plugin)
	} else if fnType != "function" {
		panic("Cannot load pouchdb-find plugin; .createIndex method already exists as a non-function")
	}
	return &PouchPluginFind{db}
}
Exemple #3
0
func BaseURI() string {
	doc := js.Global.Get("document")
	if jsbuiltin.TypeOf(doc) == "undefined" {
		// Likely running from node.js, as during testing
		return ""
	}
	rawUri := js.Global.Get("jQuery").Get("mobile").Get("path").Call("getDocumentBase").String()
	uri, _ := url.Parse(rawUri)
	uri.Fragment = ""
	uri.RawQuery = ""
	return uri.String()
}
Exemple #4
0
func sendResponse(req *Message, data *string) error {
	iframe := js.Global.Get("document").Call("getElementById", req.IframeId)
	if jsbuiltin.TypeOf(iframe) == "undefined" {
		return fmt.Errorf("Cannot find requested iframe")
	}
	iframe.Get("contentWindow").Call("postMessage", Response{
		Tag:  req.Tag,
		Path: req.Path,
		Data: *data,
	}, "*")
	return nil
}
Exemple #5
0
// FindLink returns a header link element matching the requested rel tag, if present.
func FindLink(rel string) string {
	doc := js.Global.Get("document")
	if jsbuiltin.TypeOf(doc) == "undefined" {
		// Likely running from node.js, as during testing
		return ""
	}
	links := doc.Call("getElementsByTagName", "head").Index(0).Call("getElementsByTagName", "link")
	for i := 0; i < links.Length(); i++ {
		link := links.Index(i)
		if link.Get("rel").String() == rel {
			return link.Get("href").String()
		}
	}
	return ""
}