How to use the ariatemplates/utils/Dom.isAncestor function in ariatemplates

To help you get started, we’ve selected a few ariatemplates examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ariatemplates / ariatemplates / test / aria / widgets / dropdown / touchDevices / Base.js View on Github external
checkFocusDesktop : function (widget) {
            // the active element after selecting something in the popup on desktops
            // must be the text field in the widget
            var activeElement = this.testWindow.document.activeElement;
            this.assertTrue(ariaUtilsDom.isAncestor(activeElement, widget.getDom()), "Widget " + widget.$class
                    + " should be focused");
            this.assertEquals(activeElement.tagName.toLowerCase(), "input", "The input in widget " + widget.$class
                    + " should be focused");
        },
github ariatemplates / ariatemplates / test / aria / widgets / dropdown / touchDevices / RobotBase.js View on Github external
checkFocusDesktop : function (widget) {
            // the active element after selecting something in the popup on desktops
            // must be the text field in the widget
            var activeElement = this.testWindow.document.activeElement;
            this.assertTrue(ariaUtilsDom.isAncestor(activeElement, widget.getDom()), "Widget " + widget.$class
                    + " should be focused");
            this.assertEquals(activeElement.tagName.toLowerCase(), "input", "The input in widget " + widget.$class
                    + " should be focused");
        },
github ariatemplates / ariatemplates / test / EnhancedRobotBase.js View on Github external
_isFocused : function (element, strict) {
        // ---------------------------------------------------------- processing

        var activeElement = this._getActiveElement();

        var result;
        if (strict) {
            result = activeElement === element;
        } else {
            result = ariaUtilsDom.isAncestor(activeElement, element);
        }

        // -------------------------------------------------------------- return

        return result;
    },
github ariatemplates / ariatemplates / test / aria / utils / domNavigationManager / DomNavigationManagerRobotTestCase.js View on Github external
// --------------------------------------------------- destructuring

            var ancestor = this._currentNode;

            var document = Aria.$window.document;
            var focusedElement = document.activeElement;
            var textContent = focusedElement.textContent || focusedElement.innerText;

            // ------------------------------------------------------ processing

            var result;
            var message;

            // -----------------------------------------------------------------

            result = ariaUtilsDom.isAncestor(focusedElement, ancestor);
            message = 'Focused element should%1be contained inside the element';

            var subtitution;
            if (shouldBeContained) {
                subtitution = ' ';
            } else {
                subtitution = ' not ';
                result = !result;
            }

            message = subst(message, subtitution);
            this.assertTrue(result, message);

            // -----------------------------------------------------------------

            result = !!(expectedTextContent === textContent);
github ariatemplates / ariatemplates / test / aria / widgets / wai / autoComplete / AutoCompleteRobotBase.js View on Github external
this.assertTruthy(listBoxElt, "no item has the listbox role");
                    for (var i = 0, l = optionsElt.length; i < l; i++) {
                        var curOption = optionsElt[i];
                        this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
                    }
                }
            }

            var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
            var ariaActiveDescendantElt;
            if (ariaActiveDescendant) {
                ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
                this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
                this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
                this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
                var selectedIdx = listWidget._cfg.selectedIndex;
                this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
                var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");
                var labelFromWidget = listWidget._cfg.items[selectedIdx].label;
                this.assertEquals(labelFromDom, labelFromWidget);
            }
        },
github ariatemplates / ariatemplates / test / aria / widgets / wai / autoComplete / AutoCompleteRobotBase.js View on Github external
for (var i = 0, l = optionsElt.length; i < l; i++) {
                        var curOption = optionsElt[i];
                        this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
                    }
                }
            }

            var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
            var ariaActiveDescendantElt;
            if (ariaActiveDescendant) {
                ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
                this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
                this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
                this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
                var selectedIdx = listWidget._cfg.selectedIndex;
                this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
                var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");
                var labelFromWidget = listWidget._cfg.items[selectedIdx].label;
                this.assertEquals(labelFromDom, labelFromWidget);
            }
        },
github ariatemplates / ariatemplates / test / aria / widgets / wai / autoComplete / AutoCompleteRobotBase.js View on Github external
for (var i = 0, l = childrenWithRole.length; i < l; i++) {
                        var curChild = childrenWithRole[i];
                        var curRole = curChild.getAttribute("role");
                        this.assertTrue(curRole === "listbox" || curRole === "option");
                        if (curRole == "listbox") {
                            this.assertFalsy(listBoxElt, "several items have the listbox role");
                            listBoxElt = curChild;
                        } else if (curRole == "option") {
                            optionsElt.push(curChild);
                        }
                    }
                    this.assertEquals(listWidget._cfg.items.length, optionsElt.length, "the number of items in listWidget._cfg.items (%1) is not the same as the number of DOM element with role=option (%2)");
                    this.assertTruthy(listBoxElt, "no item has the listbox role");
                    for (var i = 0, l = optionsElt.length; i < l; i++) {
                        var curOption = optionsElt[i];
                        this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
                    }
                }
            }

            var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
            var ariaActiveDescendantElt;
            if (ariaActiveDescendant) {
                ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
                this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
                this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
                this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
                this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
                var selectedIdx = listWidget._cfg.selectedIndex;
                this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
                var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");