mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[quickjs] textContent
This commit is contained in:
parent
189115b661
commit
2bf349a013
@ -377,9 +377,16 @@ getDomRect(JSContext *ctx)
|
||||
|
||||
JSValue proto, obj;
|
||||
|
||||
/* Event class */
|
||||
JS_NewClassID(&js_domRect_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_domRect_class_id, &js_domRect_class);
|
||||
{
|
||||
static int initialised;
|
||||
|
||||
if (!initialised) {
|
||||
/* Event class */
|
||||
JS_NewClassID(&js_domRect_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_domRect_class_id, &js_domRect_class);
|
||||
initialised = 1;
|
||||
}
|
||||
}
|
||||
proto = JS_NewObject(ctx);
|
||||
REF_JS(proto);
|
||||
|
||||
@ -392,5 +399,7 @@ getDomRect(JSContext *ctx)
|
||||
JS_SetOpaque(proto, d);
|
||||
JSValue r = proto;
|
||||
|
||||
JS_DupValue(ctx, r);
|
||||
|
||||
RETURN_JS(r);
|
||||
}
|
||||
|
@ -1547,13 +1547,14 @@ js_element_get_property_textContent(JSContext *ctx, JSValueConst this_val)
|
||||
if (!el) {
|
||||
return JS_NULL;
|
||||
}
|
||||
struct string buf;
|
||||
if (!init_string(&buf)) {
|
||||
return JS_EXCEPTION;
|
||||
dom_string *content = NULL;
|
||||
dom_exception exc = dom_node_get_text_content(el, &content);
|
||||
|
||||
if (exc != DOM_NO_ERR || !content) {
|
||||
return JS_NULL;
|
||||
}
|
||||
walk_tree_content(&buf, el);
|
||||
JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length);
|
||||
done_string(&buf);
|
||||
JSValue ret = JS_NewStringLen(ctx, dom_string_data(content), dom_string_length(content));
|
||||
dom_string_unref(&content);
|
||||
|
||||
RETURN_JS(ret);
|
||||
}
|
||||
@ -2017,6 +2018,40 @@ out:
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_set_property_textContent(JSContext *ctx, JSValueConst this_val, JSValue val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
REF_JS(val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
|
||||
|
||||
if (!el) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
size_t len;
|
||||
const char *str = JS_ToCStringLen(ctx, &len, val);
|
||||
|
||||
if (!str) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
dom_string *content = NULL;
|
||||
dom_exception exc = dom_string_create((const uint8_t *)str, len, &content);
|
||||
JS_FreeCString(ctx, str);
|
||||
|
||||
if (exc != DOM_NO_ERR || !content) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
exc = dom_node_set_text_content(el, content);
|
||||
dom_string_unref(&content);
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_set_property_title(JSContext *ctx, JSValueConst this_val, JSValue val)
|
||||
{
|
||||
@ -3357,7 +3392,7 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("previousSibling", js_element_get_property_previousSibling, NULL),
|
||||
JS_CGETSET_DEF("style", js_element_get_property_style, NULL),
|
||||
JS_CGETSET_DEF("tagName", js_element_get_property_tagName, NULL),
|
||||
JS_CGETSET_DEF("textContent", js_element_get_property_textContent, NULL),
|
||||
JS_CGETSET_DEF("textContent", js_element_get_property_textContent, js_element_set_property_textContent),
|
||||
JS_CGETSET_DEF("title", js_element_get_property_title, js_element_set_property_title),
|
||||
JS_CGETSET_DEF("value", js_element_get_property_value, js_element_set_property_value),
|
||||
JS_CFUNC_DEF("addEventListener", 3, js_element_addEventListener),
|
||||
|
31
test/ecmascript/assert/element.textContent.html
Normal file
31
test/ecmascript/assert/element.textContent.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<h3>Differences between innerText and textContent.</h3>
|
||||
|
||||
<p id="demo">This p element contains a <span style="display:block">hidden span element</span> and a <span> visible span element</span>.</p>kkkk
|
||||
|
||||
<button onclick="getTextContent()">Get textContent</button>
|
||||
<button onclick="getInnerText()">Get innerText</button>
|
||||
|
||||
<p><strong>Note:</strong> The textContent property is not supported in Internet Explorer 8 and earlier, and the innerText property is not supported in IE9 and earlier.</p>
|
||||
|
||||
<p id="demo"></p>
|
||||
|
||||
<script>
|
||||
function getTextContent() {
|
||||
console.assert(document.getElementById("demo").textContent === 'This p element contains a hidden span element and a visible span element.', 'without tags');
|
||||
}
|
||||
|
||||
function getInnerText() {
|
||||
window.alert(document.getElementById("demo").innerText)
|
||||
}
|
||||
|
||||
console.error('element.textContent.html');
|
||||
getTextContent();
|
||||
console.exit();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -64,6 +64,7 @@ took = [
|
||||
'element.querySelectorAll.html',
|
||||
'element.querySelector.html',
|
||||
'element.setAttribute.html',
|
||||
'element.textContent.html',
|
||||
#'event.html',
|
||||
'eventListener.html',
|
||||
'keyboardEvent.html',
|
||||
|
Loading…
x
Reference in New Issue
Block a user