mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[js] hasAttributes
This commit is contained in:
parent
0bdbb6aca6
commit
d9073ea9b1
@ -817,9 +817,11 @@ element_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
|
||||||
const spidermonkeyFunctionSpec element_funcs[] = {
|
const spidermonkeyFunctionSpec element_funcs[] = {
|
||||||
{ "hasAttribute", element_hasAttribute, 1 },
|
{ "hasAttribute", element_hasAttribute, 1 },
|
||||||
|
{ "hasAttributes", element_hasAttributes, 0 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -850,6 +852,32 @@ element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
element_hasAttributes(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());
|
||||||
|
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL)) {
|
||||||
|
args.rval().setBoolean(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tree<HTML::Node> *el = JS_GetPrivate(hobj);
|
||||||
|
tree<HTML::Node>::iterator it = el->begin();
|
||||||
|
it->parseAttributes();
|
||||||
|
const std::map<std::string, std::string> attrs = it->attributes();
|
||||||
|
args.rval().setBoolean(!attrs.empty());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JSObject *
|
JSObject *
|
||||||
getElement(JSContext *ctx, void *node)
|
getElement(JSContext *ctx, void *node)
|
||||||
|
17
test/ecmascript/hasAttributes.html
Normal file
17
test/ecmascript/hasAttributes.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<a href="/home">BBB</a>
|
||||||
|
<b id="aaaa">bbb</b>
|
||||||
|
<a id="blabla" href="/" rel="nofollow">
|
||||||
|
<b>AAA</b><u id="ble">UUU</u>AAAAAAA
|
||||||
|
</a>
|
||||||
|
<a id="bb" href="/">BB</a>
|
||||||
|
<script>
|
||||||
|
function aa()
|
||||||
|
{
|
||||||
|
alert(document.getElementById('blabla').hasAttributes());
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<button onclick="return aa()">blabla has attributes</button>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user