mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
dom: add element children and getelementsby*
This commit is contained in:
@@ -6,6 +6,8 @@ const jsruntime = @import("jsruntime");
|
|||||||
const Case = jsruntime.test_utils.Case;
|
const Case = jsruntime.test_utils.Case;
|
||||||
const checkCases = jsruntime.test_utils.checkCases;
|
const checkCases = jsruntime.test_utils.checkCases;
|
||||||
|
|
||||||
|
const collection = @import("html_collection.zig");
|
||||||
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
const HTMLElem = @import("../html/elements.zig");
|
const HTMLElem = @import("../html/elements.zig");
|
||||||
pub const Union = @import("../html/elements.zig").Union;
|
pub const Union = @import("../html/elements.zig").Union;
|
||||||
@@ -122,6 +124,40 @@ pub const Element = struct {
|
|||||||
// Return true.
|
// Return true.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn _getElementsByTagName(
|
||||||
|
self: *parser.Element,
|
||||||
|
alloc: std.mem.Allocator,
|
||||||
|
tag_name: []const u8,
|
||||||
|
) !collection.HTMLCollection {
|
||||||
|
return try collection.HTMLCollectionByTagName(
|
||||||
|
alloc,
|
||||||
|
parser.elementToNode(self),
|
||||||
|
tag_name,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn _getElementsByClassName(
|
||||||
|
self: *parser.Element,
|
||||||
|
alloc: std.mem.Allocator,
|
||||||
|
classNames: []const u8,
|
||||||
|
) !collection.HTMLCollection {
|
||||||
|
return try collection.HTMLCollectionByClassName(
|
||||||
|
alloc,
|
||||||
|
parser.elementToNode(self),
|
||||||
|
classNames,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParentNode
|
||||||
|
// https://dom.spec.whatwg.org/#parentnode
|
||||||
|
pub fn get_children(self: *parser.Element) !collection.HTMLCollection {
|
||||||
|
return try collection.HTMLCollectionChildren(parser.elementToNode(self), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(_: *parser.Element, _: std.mem.Allocator) void {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
|||||||
@@ -357,7 +357,12 @@ pub fn testExecFn(
|
|||||||
.{ .src = "getElementsByTagNameAll.item(7).localName", .ex = "p" },
|
.{ .src = "getElementsByTagNameAll.item(7).localName", .ex = "p" },
|
||||||
.{ .src = "getElementsByTagNameAll.namedItem('para-empty-child').localName", .ex = "span" },
|
.{ .src = "getElementsByTagNameAll.namedItem('para-empty-child').localName", .ex = "span" },
|
||||||
|
|
||||||
|
.{ .src = "document.getElementById('content').getElementsByTagName('*').length", .ex = "4" },
|
||||||
|
.{ .src = "document.getElementById('content').getElementsByTagName('p').length", .ex = "2" },
|
||||||
|
.{ .src = "document.getElementById('content').getElementsByTagName('div').length", .ex = "0" },
|
||||||
|
|
||||||
.{ .src = "document.children.length", .ex = "1" },
|
.{ .src = "document.children.length", .ex = "1" },
|
||||||
|
.{ .src = "document.getElementById('content').children.length", .ex = "3" },
|
||||||
|
|
||||||
// check liveness
|
// check liveness
|
||||||
.{ .src = "let content = document.getElementById('content')", .ex = "undefined" },
|
.{ .src = "let content = document.getElementById('content')", .ex = "undefined" },
|
||||||
|
|||||||
Reference in New Issue
Block a user