mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-29 15:13:28 +00:00 
			
		
		
		
	Merge pull request #899 from lightpanda-io/element_remove
Add element.remove() (needed by reddit)
This commit is contained in:
		| @@ -508,6 +508,16 @@ pub const Element = struct { | ||||
|         _ = opts; | ||||
|         return Animation.constructor(effect, null); | ||||
|     } | ||||
|  | ||||
|     pub fn _remove(self: *parser.Element) !void { | ||||
|         // TODO: This hasn't been tested to make sure all references to this | ||||
|         // node are properly updated. A lot of libdom is lazy and will look | ||||
|         // for related elements JIT by walking the tree, but there could be | ||||
|         // cases in libdom or the Zig WebAPI where this reference is kept | ||||
|         const as_node: *parser.Node = @ptrCast(self); | ||||
|         const parent = try parser.nodeParentNode(as_node) orelse return; | ||||
|         _ = try Node._removeChild(parent, as_node); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| // Tests | ||||
| @@ -767,4 +777,13 @@ test "Browser.DOM.Element" { | ||||
|         .{ "fc; (fc = document.createElement('div')).innerHTML = '<script><\\/script><p>hello</p>'", null }, | ||||
|         .{ "fc.outerHTML", "<div><script></script><p>hello</p></div>" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "const rm = document.createElement('div')", null }, | ||||
|         .{ "rm.id = 'to-remove'", null }, | ||||
|         .{ "document.getElementsByTagName('body')[0].appendChild(rm)", null }, | ||||
|         .{ "document.getElementById('to-remove') != null", "true" }, | ||||
|         .{ "rm.remove()", "undefined" }, | ||||
|         .{ "document.getElementById('to-remove') != null", "false" }, | ||||
|     }, .{}); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Karl Seguin
					Karl Seguin