mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Merge pull request #1071 from lightpanda-io/nikneym/element-dir
Add `element.dir` getter & setter
This commit is contained in:
@@ -104,6 +104,14 @@ pub const Element = struct {
|
|||||||
return try parser.nodeName(parser.elementToNode(self));
|
return try parser.nodeName(parser.elementToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_dir(self: *parser.Element) ![]const u8 {
|
||||||
|
return try parser.elementGetAttribute(self, "dir") orelse "";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dir(self: *parser.Element, dir: []const u8) !void {
|
||||||
|
return parser.elementSetAttribute(self, "dir", dir);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_id(self: *parser.Element) ![]const u8 {
|
pub fn get_id(self: *parser.Element) ![]const u8 {
|
||||||
return try parser.elementGetAttribute(self, "id") orelse "";
|
return try parser.elementGetAttribute(self, "id") orelse "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<script src="../testing.js"></script>
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content" dir="ltr">
|
||||||
<a id="link" href="foo" class="ok">OK</a>
|
<a id="link" href="foo" class="ok">OK</a>
|
||||||
<p id="para-empty" class="ok empty">
|
<p id="para-empty" class="ok empty">
|
||||||
<span id="para-empty-child"></span>
|
<span id="para-empty-child"></span>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
testing.expectEqual('div', content.localName);
|
testing.expectEqual('div', content.localName);
|
||||||
testing.expectEqual('DIV', content.tagName);
|
testing.expectEqual('DIV', content.tagName);
|
||||||
testing.expectEqual('content', content.id);
|
testing.expectEqual('content', content.id);
|
||||||
|
testing.expectEqual('ltr', content.dir);
|
||||||
|
|
||||||
content.id = 'foo';
|
content.id = 'foo';
|
||||||
testing.expectEqual('foo', content.id);
|
testing.expectEqual('foo', content.id);
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
|
|
||||||
let p1 = document.getElementById('para-empty');
|
let p1 = document.getElementById('para-empty');
|
||||||
testing.expectEqual('ok empty', p1.className);
|
testing.expectEqual('ok empty', p1.className);
|
||||||
|
testing.expectEqual('', p1.dir);
|
||||||
|
|
||||||
p1.className = 'foo bar baz';
|
p1.className = 'foo bar baz';
|
||||||
testing.expectEqual('foo bar baz', p1.className);
|
testing.expectEqual('foo bar baz', p1.className);
|
||||||
@@ -52,16 +54,16 @@
|
|||||||
|
|
||||||
<script id=attributes>
|
<script id=attributes>
|
||||||
testing.expectEqual(true, content.hasAttributes());
|
testing.expectEqual(true, content.hasAttributes());
|
||||||
testing.expectEqual(1, content.attributes.length);
|
testing.expectEqual(2, content.attributes.length);
|
||||||
testing.expectEqual(['id'], content.getAttributeNames());
|
testing.expectEqual(['id', 'dir'], content.getAttributeNames());
|
||||||
testing.expectEqual('content', content.getAttribute('id'));
|
testing.expectEqual('content', content.getAttribute('id'));
|
||||||
testing.expectEqual('content', content.attributes['id'].value);
|
testing.expectEqual('content', content.attributes['id'].value);
|
||||||
|
|
||||||
let x = '';
|
let x = '';
|
||||||
for (const attr of content.attributes) {
|
for (const attr of content.attributes) {
|
||||||
x += attr.name + '=' + attr.value;
|
x += attr.name + '=' + attr.value + ',';
|
||||||
}
|
}
|
||||||
testing.expectEqual('id=content', x);
|
testing.expectEqual('id=content,dir=ltr,', x);
|
||||||
|
|
||||||
testing.expectEqual(false, content.hasAttribute('foo'));
|
testing.expectEqual(false, content.hasAttribute('foo'));
|
||||||
testing.expectEqual(null, content.getAttribute('foo'));
|
testing.expectEqual(null, content.getAttribute('foo'));
|
||||||
@@ -69,7 +71,7 @@
|
|||||||
content.setAttribute('foo', 'bar');
|
content.setAttribute('foo', 'bar');
|
||||||
testing.expectEqual(true, content.hasAttribute('foo'));
|
testing.expectEqual(true, content.hasAttribute('foo'));
|
||||||
testing.expectEqual('bar', content.getAttribute('foo'));
|
testing.expectEqual('bar', content.getAttribute('foo'));
|
||||||
testing.expectEqual(['id', 'foo'], content.getAttributeNames());
|
testing.expectEqual(['id', 'dir', 'foo'], content.getAttributeNames());
|
||||||
|
|
||||||
testing.expectError('Error: InvalidCharacterError', () => {
|
testing.expectError('Error: InvalidCharacterError', () => {
|
||||||
content.setAttribute('.foo', 'invalid')
|
content.setAttribute('.foo', 'invalid')
|
||||||
@@ -263,3 +265,18 @@
|
|||||||
$('#to-remove').remove();
|
$('#to-remove').remove();
|
||||||
testing.expectEqual(null, $('#to-remove'));
|
testing.expectEqual(null, $('#to-remove'));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=elementDir>
|
||||||
|
const divElement = document.createElement("div");
|
||||||
|
// Always initialized with empty string if `dir` attribute not provided.
|
||||||
|
testing.expectEqual("", divElement.dir);
|
||||||
|
|
||||||
|
divElement.dir = "ltr";
|
||||||
|
testing.expectEqual("ltr", divElement.dir);
|
||||||
|
|
||||||
|
divElement.dir = "rtl";
|
||||||
|
testing.expectEqual("rtl", divElement.dir);
|
||||||
|
|
||||||
|
divElement.dir = "auto";
|
||||||
|
testing.expectEqual("auto", divElement.dir);
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user