diff options
Diffstat (limited to 'javascript/jsapi.c')
-rw-r--r-- | javascript/jsapi.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/javascript/jsapi.c b/javascript/jsapi.c index 35e3da35d..2aa0f8918 100644 --- a/javascript/jsapi.c +++ b/javascript/jsapi.c @@ -149,3 +149,59 @@ bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) return false; } + +bool js_fire_event(jscontext *ctx, const char *type, void *target) +{ + JSContext *cx = (JSContext *)ctx; + dom_node *node = target; + JSObject *jsevent; + jsval rval; + jsval argv[1]; + JSBool ret = JS_TRUE; + dom_exception exc; + dom_event *event; + dom_string *type_dom; + + if (node == NULL) { + /* deliver to window */ + if (cx == NULL) { + return false; + } + + exc = dom_string_create((unsigned char*)type, strlen(type), &type_dom); + if (exc != DOM_NO_ERR) { + return false; + } + +/* exc = dom_event_create(document, &event);*/ + exc = -1; + if (exc != DOM_NO_ERR) { + return false; + } + + exc = dom_event_init(event, type_dom, false, false); + dom_string_unref(type_dom); + if (exc != DOM_NO_ERR) { + return false; + } + + jsevent = jsapi_new_Event(cx, NULL, NULL, event); + if (jsevent == NULL) { + return false; + } + + argv[0] = OBJECT_TO_JSVAL(jsevent); + + ret = JS_CallFunctionName(cx, + JS_GetGlobalObject(cx), + "dispatchEvent", + 1, + argv, + &rval); + } + + if (ret == JS_TRUE) { + return true; + } + return false; +} |