mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 15:58:57 +00:00
element: add prefix and localName accessors
This commit is contained in:
@@ -28,5 +28,13 @@
|
||||
|
||||
const regularDiv = document.createElement('div');
|
||||
testing.expectEqual('DIV', regularDiv.tagName);
|
||||
testing.expectEqual('div', regularDiv.localName);
|
||||
testing.expectEqual(null, regularDiv.prefix);
|
||||
testing.expectEqual('http://www.w3.org/1999/xhtml', regularDiv.namespaceURI);
|
||||
|
||||
const custom = document.createElementNS('test', 'te:ST');
|
||||
testing.expectEqual('TE:ST', custom.tagName); // Should be te:ST
|
||||
testing.expectEqual('te', custom.prefix);
|
||||
testing.expectEqual('ST', custom.localName);
|
||||
testing.expectEqual('http://www.w3.org/1999/xhtml', custom.namespaceURI); // Should be test
|
||||
</script>
|
||||
|
||||
@@ -913,6 +913,26 @@ pub const JsApi = struct {
|
||||
return buf.written();
|
||||
}
|
||||
|
||||
pub const prefix = bridge.accessor(_prefix, null, .{});
|
||||
fn _prefix(self: *Element) ?[]const u8 {
|
||||
const name = self.getTagNameLower();
|
||||
if (std.mem.indexOfPos(u8, name, 0, ":")) |pos| {
|
||||
return name[0..pos];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub const localName = bridge.accessor(_localName, null, .{});
|
||||
fn _localName(self: *Element) []const u8 {
|
||||
const name = self.getTagNameLower();
|
||||
if (std.mem.indexOfPos(u8, name, 0, ":")) |pos| {
|
||||
return name[pos + 1 ..];
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
pub const id = bridge.accessor(Element.getId, Element.setId, .{});
|
||||
pub const className = bridge.accessor(Element.getClassName, Element.setClassName, .{});
|
||||
pub const classList = bridge.accessor(Element.getClassList, null, .{});
|
||||
|
||||
Reference in New Issue
Block a user