1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[mujs] Image.width and height in constructor

This commit is contained in:
Witold Filipczyk 2024-11-16 19:11:34 +01:00
parent a29a9112b9
commit 338d12d20b
2 changed files with 76 additions and 0 deletions

View File

@ -614,6 +614,32 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
js_pushnull(J);
}
static void
mjs_element_get_property_height(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 *h = NULL;
dom_exception exc;
if (!el) {
js_pushnull(J);
return;
}
exc = dom_element_get_attribute(el, corestring_dom_height, &h);
if (exc != DOM_NO_ERR || !h) {
js_pushnumber(J, 0);
return;
}
int height = atoi(dom_string_data(h));
dom_string_unref(h);
js_pushnumber(J, height);
}
static void
mjs_element_get_property_href(js_State *J)
{
@ -1460,6 +1486,32 @@ mjs_element_get_property_outerHtml(js_State *J)
done_string(&buf);
}
static void
mjs_element_get_property_width(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 *w = NULL;
dom_exception exc;
if (!el) {
js_pushnull(J);
return;
}
exc = dom_element_get_attribute(el, corestring_dom_width, &w);
if (exc != DOM_NO_ERR || !w) {
js_pushnumber(J, 0);
return;
}
int width = atoi(dom_string_data(w));
dom_string_unref(w);
js_pushnumber(J, width);
}
static void
mjs_element_get_property_textContent(js_State *J)
{
@ -3430,6 +3482,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
addproperty(J, "dir", mjs_element_get_property_dir, mjs_element_set_property_dir);
addproperty(J, "firstChild", mjs_element_get_property_firstChild, NULL);
addproperty(J, "firstElementChild", mjs_element_get_property_firstElementChild, NULL);
addproperty(J, "height", mjs_element_get_property_height, 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, "innerHTML", mjs_element_get_property_innerHtml, mjs_element_set_property_innerHtml);
@ -3458,6 +3511,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
addproperty(J, "textContent", mjs_element_get_property_textContent, mjs_element_set_property_textContent);
addproperty(J, "title", mjs_element_get_property_title, mjs_element_set_property_title);
addproperty(J, "value", mjs_element_get_property_value, mjs_element_set_property_value);
addproperty(J, "width", mjs_element_get_property_width, NULL);
}
}

View File

@ -48,6 +48,28 @@ mjs_image_constructor(js_State *J)
js_pushnull(J);
return;
}
const char *width = js_tostring(J, 1);
if (width) {
dom_string *value_str = NULL;
exc = dom_string_create((const uint8_t *)width, strlen(width), &value_str);
if (exc == DOM_NO_ERR) {
(void)dom_element_set_attribute(element, corestring_dom_width, value_str);
dom_string_unref(value_str);
}
}
const char *height = js_tostring(J, 2);
if (height) {
dom_string *value_str = NULL;
exc = dom_string_create((const uint8_t *)height, strlen(height), &value_str);
if (exc == DOM_NO_ERR) {
(void)dom_element_set_attribute(element, corestring_dom_height, value_str);
dom_string_unref(value_str);
}
}
mjs_push_node(J, element);
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);