|
| 1 | +type t = Dom.htmlFormControlsCollection; |
| 2 | + |
| 3 | +type t_namedItem = [ |
| 4 | + | `RadioNodeList(Dom.radioNodeList) |
| 5 | + | `Button(Dom.htmlButtonElement) |
| 6 | + | `Fieldset(Dom.htmlFieldSetElement) |
| 7 | + | `Input(Dom.htmlInputElement) |
| 8 | + | `Object(Dom.htmlObjectElement) |
| 9 | + | `Output(Dom.htmlOutputElement) |
| 10 | + | `Select(Dom.htmlSelectElement) |
| 11 | + | `Textarea(Dom.htmlTextAreaElement) |
| 12 | +]; |
| 13 | + |
| 14 | +include Webapi__Dom__HtmlCollection.Impl({ type nonrec t = t; }); |
| 15 | + |
| 16 | +let isRadioNodeList: 'a => bool = [%raw {| |
| 17 | + function(x) { return x instanceof RadioNodeList; } |
| 18 | +|}]; |
| 19 | + |
| 20 | +[@bs.send] [@bs.return nullable] external _namedItem: (t, string) => option('a) = "namedItem"; |
| 21 | +let namedItem = (t, string) => |
| 22 | + switch (_namedItem(t, string)) { |
| 23 | + | Some(el) => |
| 24 | + if (Webapi__Dom__RadioNodeList.unsafeAsRadioNodeList(el)->isRadioNodeList) { |
| 25 | + el->Obj.magic->`RadioNodeList->Some; |
| 26 | + } else { |
| 27 | + switch (Webapi__Dom__Element.tagName(el)) { |
| 28 | + // fixme: this should be a classify function in Webapi__Dom__HtmlElement |
| 29 | + | "button" => el->Obj.magic->`Button->Some |
| 30 | + | "fieldset" => el->Obj.magic->`Fieldset->Some |
| 31 | + | "input" => el->Obj.magic->`Input->Some |
| 32 | + | "object" => el->Obj.magic->`Object->Some |
| 33 | + | "output" => el->Obj.magic->`Output->Some |
| 34 | + | "select" => el->Obj.magic->`Select->Some |
| 35 | + | "textarea" => el->Obj.magic->`Textarea->Some |
| 36 | + | _ => None |
| 37 | + }; |
| 38 | + } |
| 39 | + | None => None |
| 40 | + }; |
0 commit comments