From 296ca3e5a2166965df546e1db4250366403a7d47 Mon Sep 17 00:00:00 2001 From: Benjamin Jones Date: Thu, 13 Jun 2013 15:21:37 -0700 Subject: converted basicUIRules.json rulesets to new format --- exampleData/ruleSets/basic/basicUIRules.json | 6 ++++++ exampleData/ruleSets/basic/emptyHeadings.js | 13 +++++++++++++ exampleData/ruleSets/basic/emptyHrefs.js | 12 ++++++++++++ exampleData/ruleSets/basic/labelFields.js | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 exampleData/ruleSets/basic/basicUIRules.json create mode 100644 exampleData/ruleSets/basic/emptyHeadings.js create mode 100644 exampleData/ruleSets/basic/emptyHrefs.js create mode 100644 exampleData/ruleSets/basic/labelFields.js (limited to 'exampleData') diff --git a/exampleData/ruleSets/basic/basicUIRules.json b/exampleData/ruleSets/basic/basicUIRules.json new file mode 100644 index 0000000..bfa755d --- /dev/null +++ b/exampleData/ruleSets/basic/basicUIRules.json @@ -0,0 +1,6 @@ +{ "name": "Basic HTML guidelines" +, "description": "A selection of simple HTML guidelines for improved usability and consistency" +, "rules": [ "labelFields.js", + "emptyHeadings.js", + "emptyHrefs.js" ] +} diff --git a/exampleData/ruleSets/basic/emptyHeadings.js b/exampleData/ruleSets/basic/emptyHeadings.js new file mode 100644 index 0000000..4d2db46 --- /dev/null +++ b/exampleData/ruleSets/basic/emptyHeadings.js @@ -0,0 +1,13 @@ +exports.name = "Don't use empty headings"; +exports.description = 'Empty headings confuse layout'; +exports.rule = + function() { + var that = this; + fiveui.query(':header').each( + function(i, elt) { + if ($(elt).text() == '') { + that.report('Heading is empty', elt); + } + } + ); + }; diff --git a/exampleData/ruleSets/basic/emptyHrefs.js b/exampleData/ruleSets/basic/emptyHrefs.js new file mode 100644 index 0000000..a333842 --- /dev/null +++ b/exampleData/ruleSets/basic/emptyHrefs.js @@ -0,0 +1,12 @@ +exports.name': "Don't use empty hrefs." +exports.description': "Links with no text can't generally be used." +exports.rule = + function() { + var that = this; + fiveui.query('a').each( + function(i, elt) { + if ($(elt).text() == '' && elt.title == '') { + that.report('Link has no text', elt); + } + }); + }; diff --git a/exampleData/ruleSets/basic/labelFields.js b/exampleData/ruleSets/basic/labelFields.js new file mode 100644 index 0000000..e93c370 --- /dev/null +++ b/exampleData/ruleSets/basic/labelFields.js @@ -0,0 +1,23 @@ +exports.name = 'All input fields have exactly one label.'; +exports.description = '

Screen readers rely on HTML attributes to identify the purpose ' + + "of form widgets on-screen. These tools use label tags with 'for' " + + 'attributes that specify the id of the form element they pertain to. ' + + 'Some of the components of this web page do not have those labels.

'; + +exports.rule = function() { + var that = this; + fiveui.query(':input').each( + function(i, elt) { + if (elt.id) { + var $label = fiveui.query("label[for='" + elt.id + "']"); + + if (1 < $label.size()) { + that.report('Form element has too many labels', elt); + } + + if (0 == $label.size()) { + that.report('Form element has no label', elt); + } + } + }); +} -- cgit v1.2.3