mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[js] screen.width
This commit is contained in:
parent
719f484422
commit
54a7bd7339
@ -59,10 +59,12 @@ JSClass screen_class = {
|
|||||||
|
|
||||||
static bool screen_get_property_availHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool screen_get_property_availHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool screen_get_property_availWidth(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool screen_get_property_availWidth(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool screen_get_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
JSPropertySpec screen_props[] = {
|
JSPropertySpec screen_props[] = {
|
||||||
JS_PSG("availHeight", screen_get_property_availHeight, JSPROP_ENUMERATE),
|
JS_PSG("availHeight", screen_get_property_availHeight, JSPROP_ENUMERATE),
|
||||||
JS_PSG("availWidth", screen_get_property_availWidth, JSPROP_ENUMERATE),
|
JS_PSG("availWidth", screen_get_property_availWidth, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("width", screen_get_property_width, JSPROP_ENUMERATE),
|
||||||
JS_PS_END
|
JS_PS_END
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,3 +141,47 @@ screen_get_property_availWidth(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
screen_get_property_width(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, &screen_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
|
||||||
|
if (!doc_view) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct session *ses = doc_view->session;
|
||||||
|
|
||||||
|
if (!ses) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.rval().setInt32(ses->tab->term->width * 8);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
19
test/ecmascript/width.html
Normal file
19
test/ecmascript/width.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Click the button to display the width of your screen, in pixels.</p>
|
||||||
|
|
||||||
|
<button onclick="myFunction()">Try it</button>
|
||||||
|
|
||||||
|
<p id="demo"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function myFunction() {
|
||||||
|
var x = "Width: " + screen.width + "px";
|
||||||
|
alert(x);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user