aboutsummaryrefslogtreecommitdiff
path: root/guidelines/WCAG-1.0
diff options
context:
space:
mode:
Diffstat (limited to 'guidelines/WCAG-1.0')
-rw-r--r--guidelines/WCAG-1.0/conformance-A.json9
-rw-r--r--guidelines/WCAG-1.0/guideline-1.js95
-rw-r--r--guidelines/WCAG-1.0/guideline-2.js43
-rw-r--r--guidelines/WCAG-1.0/guideline-3.js66
4 files changed, 213 insertions, 0 deletions
diff --git a/guidelines/WCAG-1.0/conformance-A.json b/guidelines/WCAG-1.0/conformance-A.json
new file mode 100644
index 0000000..fe49346
--- /dev/null
+++ b/guidelines/WCAG-1.0/conformance-A.json
@@ -0,0 +1,9 @@
+{ "name": "W3C Accessibility Guidelines (Conformance A)"
+, "description": "See: www.w3.org/TR/WCAG10/"
+, "license": "BSD3"
+, "rules":
+ [ "guideline-1.js"
+ , "guideline-2.js"
+ , "guideline-3.js"
+ ]
+}
diff --git a/guidelines/WCAG-1.0/guideline-1.js b/guidelines/WCAG-1.0/guideline-1.js
new file mode 100644
index 0000000..61e1384
--- /dev/null
+++ b/guidelines/WCAG-1.0/guideline-1.js
@@ -0,0 +1,95 @@
+/**
+ * Provide equivalent alternatives to auditory and visual content
+ */
+
+exports.name = "Equivalent Alternatives";
+exports.description = "";
+
+exports.rule = function(report) {
+
+
+ /* Checkpoint 1.1 [Priority 1] **********************************************/
+
+ var hasAlt = function(ix) {
+ // TODO: strip space from the alt attribute to prevent ' ' from passing
+ // the test
+ if(_.isEmpty($(this).attr('alt')) && _.isEmpty($(this).attr('longdesc'))) {
+ report.error('No alt/longdesc specified', this);
+ }
+ };
+
+ var hasText = function(ix) {
+ // TODO: strip space from the text to prevent ' ' from passing the test
+ if(_.isEmpty($(this).text())) {
+ report.error('No text node', this);
+ }
+ };
+
+ // images with semantic meaning should have an alt attribute.
+ $5('a').find('img')
+ .add($5('dl').find('img'))
+ .add($5('dd').find('img'))
+ .each(hasAlt);
+
+ // All `input` tags must have an alt attribute.
+ $5('input').each(hasAlt);
+
+ // All `applet` tags must have a text node
+ $5('applet').each(hasText);
+
+ // All `object` tags must have a text node
+ $5('object').each(hasText).each(hasAlt);
+
+ // TODO: what's the best way to classify content that's `complex`?
+
+ // All `area` elements of an image map should have alt attributes. It's also a
+ // bit overzealous, as it looks at all maps, not just maps that are referenced
+ // from images.
+ $5('map').find('area')
+ .add($5('map').find('a'))
+ .each(hasAlt);
+
+ // TODO: figure out a good way to handle frames.
+ // TODO: figure out a good way to handle scripts.
+
+
+ /* Checkpoint 1.2 [Priority 1] **********************************************/
+
+ // `ismap` is a boolean attribute. If it's present on an image, require that
+ // there's also a corresponding `usemap` attribute that can be used in lieu of
+ // having the server information present. This is a bit of an under
+ // approximation, as if you can provide a client-side map that doesn't cover
+ // everything that the server does. It's more of a sanity check, that this
+ // has been thought of.
+ $5('img').filter('[ismap]').each(function(ix) {
+ if(_.isEmpty($(this).attr('usemap'))) {
+ report.error('No usemap attribute to supplement a use of ismap', this);
+ }
+ });
+
+
+ /* Checkpoint 1.3 [Priority 1] **********************************************/
+
+ // TODO: Not really sure if this is something that we can check; the guideline
+ // seems to be more of a subjective check.
+
+
+ /* Checkpoint 1.4 [Priority 1] **********************************************/
+
+ // TODO: Again, not sure if this is something we can check here.
+
+
+ /* Checkpoint 1.5 [Priority 3] **********************************************/
+
+ // Make sure that every link in an image map has a corresponding text link
+ // somewhere else in the document.
+ var hrefs = $5('a').map(function() { return $(this).attr('href'); });
+ $5('map').find('area').each(function() {
+ var href = $(this).attr('href');
+ if(!_.contains(href, hrefs)) {
+ report.error('Image map contains a link not present in a text link',
+ this);
+ }
+ });
+
+};
diff --git a/guidelines/WCAG-1.0/guideline-2.js b/guidelines/WCAG-1.0/guideline-2.js
new file mode 100644
index 0000000..7dcf28d
--- /dev/null
+++ b/guidelines/WCAG-1.0/guideline-2.js
@@ -0,0 +1,43 @@
+exports.name = "colorDifference";
+exports.description = "Elements should provide sufficient color difference";
+exports.rule = function(report) {
+
+ /* Checkpoint 2.1 ***********************************************************/
+
+ // TODO: not sure about the best way to test that information isn't hidden
+ // when colors go away.
+
+
+ /* Checkpoint 2.2 ***********************************************************/
+
+ var fc = fiveui.color;
+ var MIN_COLOR_DIFF = 500; // http://www.w3.org/TR/2000/WD-AERT-20000426#color
+
+ /**
+ * Return the absolute "color difference" between two * given RGB color
+ * objects.
+ * Input is two RGB color objects.
+ */
+ var colorDiff = function (c1, c2) {
+ return Math.abs(c1.r - c2.r) +
+ Math.abs(c1.g - c2.g) +
+ Math.abs(c1.b - c2.b);
+ };
+
+ fiveui.query('*')
+ .filter(function () { // filter for lowest level elts having non-empty text
+ var $this = $(this);
+ return $this.children().length == 0 && $.trim($this.text()).length > 0;
+ })
+ .each(function (i) {
+ // TODO take into account fg alpha values
+ var fg = fc.colorToRGB($(this).css('color'));
+ var bg = fc.findBGColor($(this));
+ if (fg && bg) {
+ var diff = colorDiff(fg, bg);
+ if (diff < MIN_COLOR_DIFF) {
+ report.error('Element has poor color difference: ' + diff, this);
+ }
+ }
+ });
+};
diff --git a/guidelines/WCAG-1.0/guideline-3.js b/guidelines/WCAG-1.0/guideline-3.js
new file mode 100644
index 0000000..1be4354
--- /dev/null
+++ b/guidelines/WCAG-1.0/guideline-3.js
@@ -0,0 +1,66 @@
+
+exports.name = 'W3C Guideline 3';
+exports.description = '';
+exports.rule = function(report) {
+
+ /* Checkpoint 3.1 [Priority 2] **********************************************/
+
+ // TODO: this seems pretty subjective, as you have to be able to understand
+ // the intent of the content. The math example is tough, as you'd have to be
+ // able to pick out a situation where text wasn't marked up, but was also
+ // mathematical notation.
+
+
+ /* Checkpoint 3.2 [Priority 2] **********************************************/
+
+ // require that the document contains a dtd.
+ // TODO: how should we apply this check to iframes and such?
+ if(!document.doctype) {
+ report.error('No doctype given for the document', null);
+ }
+
+
+ /* Checkpoint 3.3 [Priority 2] **********************************************/
+
+ // use style sheets instead of HTML attributes to specify formatting
+ // information.
+ $5('b').each(function() {
+ report.error('The b tag shouldn\'t be used, use strong instead', this);
+ });
+
+ $5('i').each(function() {
+ report.error('The i tag shouldn\'t be used, use em', this);
+ });
+
+ $5('[font]').each(function() {
+ report.error('Use css instead of the font attribute for formatting', this);
+ });
+
+ // TODO: there are other cases to handle here, not sure about the best path
+ // forward.
+
+
+ /* Checkpoint 3.4 [Priority 2] **********************************************/
+
+ // TODO: not sure what the best way to select everything that's not
+ // automatically positioned. Additionally, many fancy user interfaces will
+ // use pixels when positioning content, which isn't necessarily wrong.
+
+
+ /* Checkpoint 3.5 [Priority 2] **********************************************/
+
+ // TODO: what's the best way to select siblings that match a given pattern in
+ // jquery? Essentially, we just want to match situations where h1 is followed
+ // by something that's both a header, and not h2 (for example).
+
+
+ /* Checkpoint 3.6 [Priority 2] **********************************************/
+
+
+ /* Checkpoint 3.7 [Priority 2] **********************************************/
+
+ // TODO: is there any way that we can detect quotations that aren't inside of
+ // a blockquote region?
+
+
+};