diff options
author | Rogan Creswick <creswick@gmail.com> | 2013-11-22 15:24:38 -0800 |
---|---|---|
committer | Rogan Creswick <creswick@gmail.com> | 2013-11-22 15:24:38 -0800 |
commit | 976abddf13893f85897fe709cafebadfacea962b (patch) | |
tree | aebbb0329769612f3b05bbebecd67d57a94cb703 /guidelines/wikipedia/color.js | |
parent | ce6e46a2fdb9de1c5f7d1c02e604ba0f8000c335 (diff) |
added color guidelines for wikipedia, and factored some color checks into the prelude
Diffstat (limited to 'guidelines/wikipedia/color.js')
-rw-r--r-- | guidelines/wikipedia/color.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/guidelines/wikipedia/color.js b/guidelines/wikipedia/color.js new file mode 100644 index 0000000..2ff1f42 --- /dev/null +++ b/guidelines/wikipedia/color.js @@ -0,0 +1,31 @@ +exports.name = "Color use"; +exports.description = "Use colors that have sufficient contrast and avoid issues with common forms of color blindness."; + +var fc = fiveui.color; +var AA_RATIO = 4.5; +var AAA_RATIO = 7; + +exports.rule = function (report) { + $5('#mw-content-text *') + // filter for lowest level elts having non-empty text + .filter(function () { + var $this = $(this); + return $this.children().length == 0 && $.trim($this.text()).length > 0; + }) + .each(function (i) { + var fg = fc.colorToRGB($(this).css('color')); + var bg = fc.findBGColor($(this)); + if (fg && bg) { + var ratio = fc.contrast(fc.luminance(fg), fc.luminance(bg)); + + if (ratio < AA_RATIO) { + report.error('Element has poor contrast: ' + ratio + + " ratio should be greater than " + AA_RATIO, this); + } else if (ratio < AAA_RATIO){ + report.warning('Element has poor contrast: ' + ratio + + " ratio should be greater than " + AAA_RATIO, this); + } + } + }); + +}; |