mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
DOM ecmascript: Defined getElementById.
This commit is contained in:
parent
fc8c5fa024
commit
f0c720c19b
@ -6,6 +6,9 @@
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Document.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLElement.h"
|
||||
#include "dom/node.h"
|
||||
#include "util/hash.h"
|
||||
|
||||
JSBool
|
||||
Document_getProperty(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||
@ -181,7 +184,20 @@ static JSBool
|
||||
Document_getElementById(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
/* Write me! */
|
||||
struct html_objects *o = JS_GetContextPrivate(ctx);
|
||||
unsigned char *key;
|
||||
struct hash_item *item;
|
||||
|
||||
if (argc != 1)
|
||||
return JS_FALSE;
|
||||
key = jsval_to_string(ctx, &argv[0]);
|
||||
item = get_hash_item(o->ids, key, strlen(key));
|
||||
if (item) {
|
||||
struct dom_node *node = item->value;
|
||||
|
||||
assert(node);
|
||||
object_to_jsval(ctx, rval, node->ecmascript_obj);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLElement.h"
|
||||
#include "dom/node.h"
|
||||
#include "util/hash.h"
|
||||
|
||||
JSBool
|
||||
HTMLElement_getProperty(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||
@ -55,6 +56,7 @@ HTMLElement_setProperty(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
struct dom_node *node;
|
||||
struct HTMLElement_struct *html;
|
||||
struct html_objects *o;
|
||||
|
||||
if (!JSVAL_IS_INT(id))
|
||||
return JS_TRUE;
|
||||
@ -71,7 +73,16 @@ HTMLElement_setProperty(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
switch (JSVAL_TO_INT(id)) {
|
||||
case JSP_HTML_ELEMENT_ID:
|
||||
o = JS_GetContextPrivate(ctx);
|
||||
if (html->id) {
|
||||
struct hash_item *item = get_hash_item(o->ids, html->id, strlen(html->id));
|
||||
|
||||
if (item)
|
||||
del_hash_item(o->ids, item);
|
||||
}
|
||||
mem_free_set(&html->id, stracpy(jsval_to_string(ctx, vp)));
|
||||
if (html->id)
|
||||
add_hash_item(o->ids, html->id, strlen(html->id), node);
|
||||
break;
|
||||
case JSP_HTML_ELEMENT_TITLE:
|
||||
mem_free_set(&html->title, stracpy(jsval_to_string(ctx, vp)));
|
||||
@ -128,8 +139,16 @@ void
|
||||
done_HTMLElement(struct dom_node *node)
|
||||
{
|
||||
struct HTMLElement_struct *d = node->data.element.html_data;
|
||||
JSContext *ctx = node->ecmascript_ctx;
|
||||
struct html_objects *o = JS_GetContextPrivate(ctx);
|
||||
|
||||
mem_free_if(d->id);
|
||||
if (d->id) {
|
||||
struct hash_item *item = get_hash_item(o->ids, d->id, strlen(d->id));
|
||||
|
||||
if (item)
|
||||
del_hash_item(o->ids, item);
|
||||
mem_free(d->id);
|
||||
}
|
||||
mem_free_if(d->title);
|
||||
mem_free_if(d->lang);
|
||||
mem_free_if(d->dir);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
struct dom_node;
|
||||
struct hash;
|
||||
|
||||
extern const JSClass HTMLElement_class;
|
||||
extern const JSFunctionSpec HTMLElement_funcs[];
|
||||
@ -24,6 +25,7 @@ struct html_objects { /* FIXME: Better name for this type. */
|
||||
JSObject *Node_object;
|
||||
JSObject *Element_object;
|
||||
JSObject *HTMLElement_object;
|
||||
struct hash *ids;
|
||||
};
|
||||
|
||||
void make_HTMLElement(JSContext *ctx, struct dom_node *node);
|
||||
|
Loading…
Reference in New Issue
Block a user