mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[mujs] element.href
This commit is contained in:
parent
b911a27746
commit
64be2be5ee
@ -574,6 +574,35 @@ mjs_element_get_property_firstElementChild(js_State *J)
|
|||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_element_get_property_href(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
|
||||||
|
dom_string *href = NULL;
|
||||||
|
dom_exception exc;
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exc = dom_element_get_attribute(el, corestring_dom_href, &href);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!href) {
|
||||||
|
js_pushstring(J, "");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
js_pushstring(J, dom_string_data(href));
|
||||||
|
dom_string_unref(href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mjs_element_get_property_id(js_State *J)
|
mjs_element_get_property_id(js_State *J)
|
||||||
{
|
{
|
||||||
@ -1680,6 +1709,37 @@ mjs_element_set_property_dir(js_State *J)
|
|||||||
js_pushundefined(J);
|
js_pushundefined(J);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_element_set_property_href(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
dom_string *hrefstr = NULL;
|
||||||
|
dom_exception exc;
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
|
assert(interpreter);
|
||||||
|
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
js_pushundefined(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char *str = js_tostring(J, 1);
|
||||||
|
if (!str) {
|
||||||
|
js_error(J, "out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exc = dom_string_create((const uint8_t *)str, strlen(str), &hrefstr);
|
||||||
|
|
||||||
|
if (exc == DOM_NO_ERR && hrefstr) {
|
||||||
|
exc = dom_element_set_attribute(el, corestring_dom_href, hrefstr);
|
||||||
|
interpreter->changed = 1;
|
||||||
|
dom_string_unref(hrefstr);
|
||||||
|
}
|
||||||
|
js_pushundefined(J);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mjs_element_set_property_id(js_State *J)
|
mjs_element_set_property_id(js_State *J)
|
||||||
{
|
{
|
||||||
@ -3316,6 +3376,7 @@ mjs_push_element(js_State *J, void *node)
|
|||||||
addproperty(J, "dir", mjs_element_get_property_dir, mjs_element_set_property_dir);
|
addproperty(J, "dir", mjs_element_get_property_dir, mjs_element_set_property_dir);
|
||||||
addproperty(J, "firstChild", mjs_element_get_property_firstChild, NULL);
|
addproperty(J, "firstChild", mjs_element_get_property_firstChild, NULL);
|
||||||
addproperty(J, "firstElementChild", mjs_element_get_property_firstElementChild, NULL);
|
addproperty(J, "firstElementChild", mjs_element_get_property_firstElementChild, NULL);
|
||||||
|
addproperty(J, "href", mjs_element_get_property_href, mjs_element_set_property_href);
|
||||||
addproperty(J, "id", mjs_element_get_property_id, mjs_element_set_property_id);
|
addproperty(J, "id", mjs_element_get_property_id, mjs_element_set_property_id);
|
||||||
addproperty(J, "innerHTML", mjs_element_get_property_innerHtml, mjs_element_set_property_innerHtml);
|
addproperty(J, "innerHTML", mjs_element_get_property_innerHtml, mjs_element_set_property_innerHtml);
|
||||||
addproperty(J, "innerText", mjs_element_get_property_innerHtml, mjs_element_set_property_innerText);
|
addproperty(J, "innerText", mjs_element_get_property_innerHtml, mjs_element_set_property_innerText);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user