mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
add HTMLElementLink get/set href
This commit is contained in:
@@ -895,6 +895,15 @@ pub const HTMLLinkElement = struct {
|
|||||||
pub fn constructor(page: *Page, js_this: Env.JsThis) !*parser.Element {
|
pub fn constructor(page: *Page, js_this: Env.JsThis) !*parser.Element {
|
||||||
return constructHtmlElement(page, js_this);
|
return constructHtmlElement(page, js_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_href(self: *parser.Link) ![]const u8 {
|
||||||
|
return try parser.linkGetHref(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_href(self: *parser.Link, href: []const u8, page: *const Page) !void {
|
||||||
|
const full = try urlStitch(page.call_arena, href, page.url.raw, .{});
|
||||||
|
return try parser.linkSetHref(self, full);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const HTMLMapElement = struct {
|
pub const HTMLMapElement = struct {
|
||||||
@@ -1581,6 +1590,12 @@ test "Browser.HTML.Element" {
|
|||||||
.{ "document.createElement('a').focus()", null },
|
.{ "document.createElement('a').focus()", null },
|
||||||
.{ "document.activeElement === focused", "true" },
|
.{ "document.activeElement === focused", "true" },
|
||||||
}, .{});
|
}, .{});
|
||||||
|
|
||||||
|
try runner.testCases(&.{
|
||||||
|
.{ "let l2 = document.createElement('link');", null },
|
||||||
|
.{ "l2.href = 'https://lightpanda.io/'", null },
|
||||||
|
.{ "l2.href", "https://lightpanda.io/" },
|
||||||
|
}, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Browser.HTML.Element.DataSet" {
|
test "Browser.HTML.Element.DataSet" {
|
||||||
|
|||||||
@@ -1830,6 +1830,21 @@ pub fn anchorSetRel(a: *Anchor, rel: []const u8) !void {
|
|||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTMLLinkElement
|
||||||
|
|
||||||
|
pub fn linkGetHref(link: *Link) ![]const u8 {
|
||||||
|
var res: ?*String = undefined;
|
||||||
|
const err = c.dom_html_link_element_get_href(link, &res);
|
||||||
|
try DOMErr(err);
|
||||||
|
if (res == null) return "";
|
||||||
|
return strToData(res.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn linkSetHref(link: *Link, href: []const u8) !void {
|
||||||
|
const err = c.dom_html_link_element_set_href(link, try strFromData(href));
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
// ElementsHTML
|
// ElementsHTML
|
||||||
|
|
||||||
pub const MediaElement = struct { base: *c.dom_html_element };
|
pub const MediaElement = struct { base: *c.dom_html_element };
|
||||||
|
|||||||
Reference in New Issue
Block a user