diff --git a/dom4/dom4-tests.ts b/dom4/dom4-tests.ts new file mode 100644 index 0000000000..9d1a7220d9 --- /dev/null +++ b/dom4/dom4-tests.ts @@ -0,0 +1,16 @@ +/// + +function testDocument() { + document.query(".container-a").classList; + document.queryAll(".container-b")[0].className; + document.queryAll(".container-c").childElementCount; +} + +function testElement(el: Element) { + let isInDocument: boolean = el.closest("document") != null; + let isButton: boolean = el.matches("button"); + + el.firstElementChild.getAttribute("foo"); + el.lastElementChild.getAttribute("bar"); +} + diff --git a/dom4/dom4.d.ts b/dom4/dom4.d.ts new file mode 100644 index 0000000000..6139a6f7ea --- /dev/null +++ b/dom4/dom4.d.ts @@ -0,0 +1,57 @@ +// Type definitions for dom4 v1.5 +// Project: https://github.com/WebReflection/dom4 +// Definitions by: Adi Dahiya , Gilad Gray +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface ParentNode { + /** + * Returns the child elements. + */ + children: HTMLCollection; + + /** + * Returns the first child that is an element, and null otherwise. + */ + firstElementChild: Element; + + /** + * Returns the last child that is an element, and null otherwise. + */ + lastElementChild: Element; + + /** + * Returns the number of children that are elements. + */ + childElementCount: number; + + /** + * Returns the first element that is a descendant of node that matches relativeSelectors. + */ + query(relativeSelectors: string): Element; + + /** + * Returns all element descendants of node that match relativeSelectors. + */ + queryAll(relativeSelectors: string): Elements; +} + +interface Element extends ParentNode { + /** + * Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise. + */ + closest(selectors: string): Element; + + /** + * Returns true if matching selectors against element’s root yields element, and false otherwise. + */ + matches(selectors: string): boolean; +} + +interface Elements extends ParentNode, Array { +} + +interface Document extends ParentNode { +} + +interface DocumentFragment extends ParentNode { +}