diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-16 21:51:32 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-16 21:56:01 +0100 |
| commit | 8e791fdffa8276a46109f15664bf4b2f69d058ef (patch) | |
| tree | de57665d8af36c1df6937a2d576cea7aaa02aca5 /src/html | |
| parent | 90d6faeb5c109f166f99bdeac12b79c8af349d03 (diff) | |
| download | chawan-8e791fdffa8276a46109f15664bf4b2f69d058ef.tar.gz | |
dom: add Option constructor
Diffstat (limited to 'src/html')
| -rw-r--r-- | src/html/dom.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 0f51fbef..424d9904 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -5862,9 +5862,22 @@ x.width = width; x.height = height; return x; """) + let optionFun = ctx.newFunction( + ["text", "value", "defaultSelected", "selected"], """ +text = text ? text + "" : ""; +const option = document.createElement("option"); +if (text !== "") + option.appendChild(new Text(text)); +option.value = value; +option.defaultSelected = defaultSelected; +option.selected = selected; +return option; +""") doAssert JS_SetConstructorBit(ctx, imageFun, true) + doAssert JS_SetConstructorBit(ctx, optionFun, true) let jsWindow = JS_GetGlobalObject(ctx) ctx.definePropertyCW(jsWindow, "Image", imageFun) + ctx.definePropertyCW(jsWindow, "Option", optionFun) ctx.definePropertyCW(jsWindow, "HTMLDocument", JS_GetPropertyStr(ctx, jsWindow, "Document")) JS_FreeValue(ctx, jsWindow) |