mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[js] element.remove
This commit is contained in:
parent
fb90f2a832
commit
f625d74673
@ -1591,6 +1591,7 @@ static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *
|
||||
static bool element_hasChildNodes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_isEqualNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_isSameNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_remove(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
|
||||
const spidermonkeyFunctionSpec element_funcs[] = {
|
||||
{ "contains", element_contains, 1 },
|
||||
@ -1600,9 +1601,11 @@ const spidermonkeyFunctionSpec element_funcs[] = {
|
||||
{ "hasChildNodes", element_hasChildNodes, 0 },
|
||||
{ "isEqualNode", element_isEqualNode, 1 },
|
||||
{ "isSameNode", element_isSameNode, 1 },
|
||||
{ "remove", element_remove, 0 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
check_contains(xmlpp::Node *node, xmlpp::Node *searched, bool *result_set, bool *result)
|
||||
{
|
||||
@ -1862,6 +1865,34 @@ element_isSameNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_remove(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||
|
||||
if (!comp || argc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||
|
||||
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL))
|
||||
return false;
|
||||
|
||||
xmlpp::Element *el = JS_GetPrivate(hobj);
|
||||
|
||||
if (!el) {
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::Node::remove_node(el);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
getElement(JSContext *ctx, void *node)
|
||||
{
|
||||
|
29
test/ecmascript/remove.html
Normal file
29
test/ecmascript/remove.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<p>Click the button to get the value of outer HTML before remove demo.</p>
|
||||
|
||||
<button onclick="myFunction()">Try it</button>
|
||||
|
||||
<p>Click the button to get the value of outer HTML after remove demo.</p>
|
||||
|
||||
<button onclick="myFunction2()">Remove demo</button>
|
||||
|
||||
<p id="demo"></p>
|
||||
|
||||
<script>
|
||||
function myFunction() {
|
||||
var a = document.getElementsByTagName("HTML")[0];
|
||||
alert(a.outerHTML);
|
||||
}
|
||||
|
||||
function myFunction2() {
|
||||
document.getElementById('demo').remove();
|
||||
var a = document.getElementsByTagName("HTML")[0];
|
||||
alert(a.outerHTML);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user