Permalink
Browse files

gallery-2011.09.28-20-29 kloots gallery-a11ychecker-base

  • Loading branch information...
1 parent 9624c66 commit ad715b7a59bfeb8270ba6eb19d33e35b6baf05da YUI Builder committed Sep 28, 2011
@@ -0,0 +1,22 @@
+# A11y Checker Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=gallery-a11ychecker-base
+
+# The list of files which should be concatenated to create the component
+# NOTE: For a css component. (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+component.jsfiles=log-error.js, dupe-link-checker.js, dupe-link-label-checker.js, label-checker.js, link-button-checker.js
+
+# The list of modules this component. requires. Used to set up the Y.add module call for YUI 3.
+component.requires=node, selector-css3
+
+# If your module has a skin file, set this flag to "true"
+component.skinnable=false
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- YUI 3 Gallery Component Build File -->
+<project name="Accessibility Checker Base" default="local">
+ <description>Accessibility Checker - Build base module</description>
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
+</project>
@@ -0,0 +1,135 @@
+(function () {
+
+var ns = Y.namespace("a11ychecker"),
+ logError = ns.logError,
+ testName = "dupe-link-test",
+ jsLinkRE = /(^#$)|(^javascript:)/,
+ yltRE = /(;_yl[a-z]|_yl[a-z])=(\w|\W)+/g,
+ EMPTY_STRING = "";
+
+
+function getURL(url, ignoreYLT) {
+
+ var returnVal;
+
+ if (url && url.search(jsLinkRE) === -1) {
+ returnVal = ignoreYLT ? url.replace(yltRE, EMPTY_STRING) : url;
+ }
+
+ return returnVal;
+
+}
+
+
+var getParent = (function() {
+
+ var called = 0;
+
+ return function (node, level) {
+
+ level = (Y.Lang.isNumber(level) && level > 0) ? (level - 1) : 2;
+
+ if (node.get("nodeName").toLowerCase() === "body") {
+ called = 0;
+ }
+ else {
+ called = called < level ? (called + 1) : 0;
+ }
+
+ return (called === 0);
+
+ };
+
+}());
+
+
+function findAllDupeLinks(config) {
+
+ config = config || {};
+
+ var duplicateURLs = {},
+ urls = {};
+
+ Y.all("a").each(function(v) {
+
+ var href, entry;
+
+ if ((href = getURL(v.getAttribute("href", 2), config.ignoreYLT)) && !(entry = urls[href])) {
+ entry = urls[href] = [];
+ }
+
+ if (entry) {
+ entry.push(v.generateID());
+ }
+
+ });
+
+ Y.each(urls, function(v, k) {
+ if (urls[k].length > 1) {
+ duplicateURLs[k] = v;
+ }
+ });
+
+ return duplicateURLs;
+
+}
+
+function findDupeSibLinks(id, url, level, ignoreYLT) {
+
+ var node = Y.one("#" + id),
+ parent = node.ancestor(Y.rbind(getParent, null, level)),
+ dupes = [];
+
+ parent.all("a").each(function (v) {
+
+ var href;
+
+ if ((href = getURL(v.getAttribute("href", 2), ignoreYLT)) && href === url) {
+ dupes.push(v);
+ }
+
+ });
+
+ return dupes;
+
+// return parent.all("a[href='" + href + "']");
+// return parent.all("a[href^='" + href + "']");
+
+}
+
+function findDupeLinks(config) {
+
+ config = config || {};
+ duplicateURLs = findAllDupeLinks(config);
+
+ var siblings,
+ len;
+
+ Y.each(duplicateURLs, function(v, k) {
+ Y.each(duplicateURLs[k], function (v) {
+
+ if (config.all) {
+ len = duplicateURLs[k].length;
+ logError(testName, v, (len - 1) + " other instance(s) of this link on this page.", "warn");
+ }
+ else {
+
+ siblings = findDupeSibLinks(v, k, config.level, config.ignoreYLT);
+ len = siblings.length;
+
+ if (len > 1) {
+ Y.each(siblings, function (v) {
+ logError(testName, v, (len - 1) + " other instance(s) of this link within the same parent node.", "warn");
+ });
+ }
+
+ }
+ });
+ });
+}
+
+findDupeLinks.testName = testName;
+
+ns.findDupeLinks = findDupeLinks;
+
+}());
@@ -0,0 +1,43 @@
+(function () {
+
+var ns = Y.namespace("a11ychecker"),
+ testName = "dupe-link-labels-test";
+
+function findDupeLinkLabels() {
+ var dupes = {},
+ labels = {};
+
+ Y.all("a").each(function(v) {
+
+ var label, entry;
+
+ if ((label = v.get("text")) && !(entry = labels[label])) {
+ entry = labels[label] = [];
+ }
+
+ if (entry) {
+ entry.push(v.generateID());
+ }
+
+ });
+
+ Y.each(labels, function(v, k) {
+ if (labels[k].length > 1) {
+ dupes[k] = v;
+ }
+ });
+
+ Y.each(dupes, function(v, k) {
+ Y.each(dupes[k], function (v) {
+ ns.logError(testName, v, "2 or more links found with this link's label.", "warn");
+ });
+ });
+
+ return dupes;
+}
+
+findDupeLinkLabels.testName = testName;
+
+ns.findDupeLinkLabels = findDupeLinkLabels;
+
+}());
Oops, something went wrong.

0 comments on commit ad715b7

Please sign in to comment.