.forEach(function (element) { if (DOM.getAttribute(element, 'dir')) { currentDirection = DOM.getAttribute(element, 'dir').toLowerCase(); } else { var dirScope = DOM.parents(element).find((parent) => { return DOM.hasAttribute(parent, 'dir'); }); var dir = DOM.getAttribute(dirScope, 'dir'); currentDirection = dir || currentDirection; } if (typeof textDirection[currentDirection] === 'undefined') { currentDirection = 'ltr'; } oppositeDirection = (currentDirection === 'ltr') ? 'rtl' : 'ltr'; var text = GetTextContentsComponent(element); var matches = text.match(textDirection[oppositeDirection]); var _case = test.add(Case({ element: element })); if (!matches) { _case.set({status: 'inapplicable'}); return; } var first = text.search(textDirection[oppositeDirection]); var last = text.lastIndexOf(matches.pop()); while (punctuation = punctuationRegex.exec(text)) { if (punctuation.index === first - 1 || punctuation.index === last + 1) { _case.set({status: 'failed'}); return; } } _case.set({status: 'passed'}); });
/** * Get header cells based on the headers getAttributeibute of a cell */ function getHeadersFromAttr (cell) { var table = DOM.parents(cell).find((parent) => DOM.is(parent, 'table'))[0]; var ids = cell.getAttribute('headers').split(/\s/); var headerCells = []; // For each IDREF select an element with that ID from the table // Only th/td cells in the same table can be headers ids.forEach(function (id) { headerCells.push(DOM.scry('th#' + id + ', td#' + id, table)); }); return headerCells; }
anchors.forEach(function (element) { var $p = DOM.parents(element).find((parent) => DOM.is(parent, 'p')); var $parent = element.parentNode; var _case = Case({ element: element }); test.add(_case); var aText = DOM.text(element).trim(); // Get all text of the p element with all anchors removed var pClone = $p.cloneNode(true); DOM.scry('a[href]', pClone).forEach((link) => { link.parentNode.removeChild(link); }); var pText = DOM.text(pClone).trim(); if (aText === '' || pText.match(allowedPText)) { _case.set('status', 'inapplicable'); } else if ( DOM.getComputedStyle(element, 'color') === DOM.getComputedStyle($p, 'color') ) { _case.set('status', 'passed'); } else if (elmHasDistinctStyle(element, $p)) { _case.set('status', 'passed'); } else if (elmHasDistinctPosition(element)) { _case.set('status', 'passed'); } else if (DOM.scry('img', element).length > 0) { _case.set('status', 'passed'); } else if (DOM.text($parent).trim() === aText && elmHasDistinctStyle($parent, $p)) { _case.set('status', 'passed'); } else { _case.set('status', 'failed'); } });
function getHeadersFromGroups (cell, tableMap) { var cellCoords = findCellInTableMap(tableMap, cell); var headers = []; let parents = DOM.parents(cell); let thead = parents.find((parent) => DOM.is(parent, 'thead')); let tbody = parents.find((parent) => DOM.is(parent, 'tbody')); let tfoot = parents.find((parent) => DOM.is(parent, 'tfoot')); DOM.scry( 'th[scope=rowgroup]', [thead, tbody, tfoot] ).forEach(function (element) { var headerCoords = findCellInTableMap(tableMap, element); if (headerCoords.x <= cellCoords.x && headerCoords.y <= cellCoords.y) { headers.push(element); } }); // TODO colgroups }
function countDirAttributes (element) { var currentDirection = DOM.getAttribute(element, 'dir'); if (!currentDirection) { var dirScope = DOM.parents(element).find((parent) => { return DOM.hasAttribute(parent, 'dir'); }); var parentDir = dirScope && DOM.getAttribute(dirScope, 'dir'); currentDirection = parentDir || currentDirection; } if (typeof currentDirection === 'string') { currentDirection = currentDirection.toLowerCase(); } if (typeof textDirection[currentDirection] === 'undefined') { currentDirection = 'ltr'; } var oppositeDirection = (currentDirection === 'ltr') ? 'rtl' : 'ltr'; var text = GetTextContentsComponent(element); var textMatches = text.match(textDirection[oppositeDirection]); if (!textMatches) { return; } var matches = textMatches.length; DOM.scry('[dir=' + oppositeDirection + ']', element).forEach(function () { var childMatches = element.textContent.match(textDirection[oppositeDirection]); if (childMatches) { matches -= childMatches.length; } }); var _case = test.add(Case({ element: element })); _case.set({ status: (matches > 0) ? 'failed' : 'passed' }); }
DOM.scry(options.selector, scope).forEach(function (element) { let label = DOM.scry('label[for=\"' + element.getAttribute('id') + '\"]', scope)[0]; let labelParent = DOM.parents(element).find((parent) => DOM.is(parent, 'label')); let hasLabelText = false; let hasLabelParentText = false; if (label) { hasLabelText = /\S/.test(label.innerText); } if (labelParent) { hasLabelParentText = /\S/.test(labelParent.innerText); } if (!hasLabelText && !hasLabelParentText) { test.add(Case({ element: element, status: 'failed' })); } else { test.add(Case({ element: element, status: 'passed' })); } });