mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[js] document.images
This commit is contained in:
parent
22cd7a0052
commit
35d7847808
@ -312,6 +312,48 @@ document_get_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
document_get_property_images(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
|
||||||
|
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||||
|
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||||
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
|
if (!document->dom) {
|
||||||
|
document->dom = document_parse(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!document->dom) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlpp::Element* root = (xmlpp::Element *)document->dom;
|
||||||
|
|
||||||
|
std::string xpath = "//img";
|
||||||
|
xmlpp::Node::NodeSet *elements = new xmlpp::Node::NodeSet;
|
||||||
|
|
||||||
|
*elements = root->find(xpath);
|
||||||
|
|
||||||
|
if (elements->size() == 0) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject *elem = getCollection(ctx, elements);
|
||||||
|
|
||||||
|
if (elem) {
|
||||||
|
args.rval().setObject(*elem);
|
||||||
|
} else {
|
||||||
|
args.rval().setNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
document_get_property_links(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
document_get_property_links(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -354,7 +396,6 @@ document_get_property_links(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -629,6 +670,7 @@ JSPropertySpec document_props[] = {
|
|||||||
#endif
|
#endif
|
||||||
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
|
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
|
||||||
JS_PSG("head", document_get_property_head, JSPROP_ENUMERATE),
|
JS_PSG("head", document_get_property_head, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("images", document_get_property_images, JSPROP_ENUMERATE),
|
||||||
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
||||||
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
||||||
|
22
test/ecmascript/images.html
Normal file
22
test/ecmascript/images.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<button onclick="myFunction()">Try it</button>
|
||||||
|
|
||||||
|
<a href="/">/</a>
|
||||||
|
<a href="/home">/home</a>
|
||||||
|
<img src="blabla.gif" />
|
||||||
|
<img src="blabla2.gif" />
|
||||||
|
|
||||||
|
<p id="demo"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function myFunction() {
|
||||||
|
var x = document.images.length;
|
||||||
|
alert(x);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user