mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] element.offsetTop
This commit is contained in:
parent
317737fa34
commit
7c72d49f0c
@ -836,6 +836,69 @@ mjs_element_get_property_offsetParent(js_State *J)
|
||||
mjs_push_element(J, node);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_element_get_property_offsetTop(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
|
||||
|
||||
if (!el) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
struct document *document = doc_view->document;
|
||||
struct session *ses;
|
||||
|
||||
if (!document) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
int offset = find_offset(document->element_map_rev, el);
|
||||
|
||||
if (offset <= 0) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
struct node_rect *rect = get_element_rect(document, offset);
|
||||
|
||||
if (!rect) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
ses = doc_view->session;
|
||||
|
||||
if (!ses) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
dom_node *node = NULL;
|
||||
dom_exception exc = dom_node_get_parent_node(el, &node);
|
||||
if (exc != DOM_NO_ERR || !node) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
int offset_parent = find_offset(document->element_map_rev, node);
|
||||
|
||||
if (offset_parent <= 0) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
struct node_rect *rect_parent = get_element_rect(document, offset_parent);
|
||||
|
||||
if (!rect_parent) {
|
||||
js_pushnumber(J, 0);
|
||||
return;
|
||||
}
|
||||
int dy = int_max(0, (rect->y0 - rect_parent->y0) * ses->tab->term->cell_height);
|
||||
dom_node_unref(node);
|
||||
js_pushnumber(J, dy);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_element_get_property_ownerDocument(js_State *J)
|
||||
{
|
||||
@ -2893,6 +2956,7 @@ mjs_push_element(js_State *J, void *node)
|
||||
addproperty(J, "nodeValue", mjs_element_get_property_nodeValue, NULL);
|
||||
addproperty(J, "offsetLeft", mjs_element_get_property_offsetLeft, NULL);
|
||||
addproperty(J, "offsetParent", mjs_element_get_property_offsetParent, NULL);
|
||||
addproperty(J, "offsetTop", mjs_element_get_property_offsetTop, NULL);
|
||||
addproperty(J, "outerHTML", mjs_element_get_property_outerHtml, NULL);
|
||||
addproperty(J, "ownerDocument", mjs_element_get_property_ownerDocument, NULL);
|
||||
addproperty(J, "parentElement", mjs_element_get_property_parentElement, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user