mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[js] tagName
This commit is contained in:
parent
adadc03821
commit
63b07c01d8
@ -46,6 +46,11 @@
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace htmlcxx;
|
||||
|
||||
static bool element_get_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
@ -54,6 +59,7 @@ static bool element_get_property_innerHtml(JSContext *ctx, unsigned int argc, JS
|
||||
static bool element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool element_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool element_get_property_tagName(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool element_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool element_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
@ -73,6 +79,7 @@ JSPropertySpec element_props[] = {
|
||||
JS_PSGS("id", element_get_property_id, element_set_property_id, JSPROP_ENUMERATE),
|
||||
JS_PSGS("innerHTML", element_get_property_innerHtml, element_set_property_innerHtml, JSPROP_ENUMERATE),
|
||||
JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE),
|
||||
JS_PSG("tagName", element_get_property_tagName, JSPROP_ENUMERATE),
|
||||
JS_PSGS("title", element_get_property_title, element_set_property_title, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
@ -120,6 +127,48 @@ element_get_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_get_property_tagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct view_state *vs;
|
||||
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||
|
||||
if (!comp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||
|
||||
/* This can be called if @obj if not itself an instance of the
|
||||
* appropriate class but has one in its prototype chain. Fail
|
||||
* such calls. */
|
||||
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL))
|
||||
return false;
|
||||
|
||||
vs = interpreter->vs;
|
||||
if (!vs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tree<HTML::Node> *el = JS_GetPrivate(hobj);
|
||||
|
||||
if (!el) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
tree<HTML::Node>::iterator it = el->begin();
|
||||
std::string v = it->tagName();
|
||||
std::transform(v.begin(), v.end(), v.begin(), ::toupper);
|
||||
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
|
17
test/ecmascript/tagName.html
Normal file
17
test/ecmascript/tagName.html
Normal file
@ -0,0 +1,17 @@
|
||||
<html>
|
||||
<body>
|
||||
<a href="/home">BBB</a>
|
||||
<textarea cols="5" rows="10" id="aaaa">bbb</textarea>
|
||||
<a id="blabla" href="/">
|
||||
<b>AAA</b><u id="ble" title="test">UUU</u>AAAAAAA
|
||||
</a>
|
||||
<a id="bb" href="/">BB</a>
|
||||
<script>
|
||||
function aa()
|
||||
{
|
||||
alert(document.getElementById('aaaa').tagName);
|
||||
}
|
||||
</script>
|
||||
<button onclick="return aa()">Click me!</button>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user