blob: 5330c5cf6dcda6c004841877e8f26b26e1c40609 [file] [log] [blame]
import 'dart:html';
/// Create anchor element with download attribute
AnchorElement createAnchorElement(String href, String? suggestedName) {
final element = AnchorElement(href: href);
if (suggestedName == null) {
element.download = 'download';
} else {
element.download = suggestedName;
}
return element;
}
/// Add an element to a container and click it
void addElementToContainerAndClick(Element container, Element element) {
// Add the element and click it
// All previous elements will be removed before adding the new one
container.children.add(element);
element.click();
}
/// Initializes a DOM container where we can host elements.
Element ensureInitialized(String id) {
var target = querySelector('#${id}');
if (target == null) {
final Element targetElement = Element.tag('flt-x-file')..id = id;
querySelector('body')!.children.add(targetElement);
target = targetElement;
}
return target;
}