aboutsummaryrefslogtreecommitdiff
path: root/exampleData/ruleSets/fontRules.json
blob: a07fab4db815171aeace667b77b043f2221f45c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * fontRules.json
 * Author: Benjamin Jones <bjones@galois.com>
 *
 * Simple rules for checking that fonts (family/weight/size) of specific elements are
 * in a specific set.
 *
 * Test using exampleData/basic/testFontRules.html
 */

{ 'name': "Fonts (family/size/style) are in a specified set"
, 'description': "All fonts used on a page should be in a specificed set"
, 'rules': [
             { 'name': "Font set"
             , 'description': "Font (family/weight/size) should be in the set ..."
             , 'rule':
             function() { //----------------------------------------------
               var allowableFonts = {
                 "Verdana": { "bold": ["25", "22", "12", "10"]
                            , "normal": ["12", "11", "10"] } }
               fiveui.query('body *').each(
                   function(i, elt) {
                     var family =  $(elt).css('font-family');
                     var sizeTxt =  $(elt).css('font-size');
                     var size = /([1-9][0-9])/.exec(sizeTxt)[0];
                     var weight =  $(elt).css('font-weight');
                     console.log('Found font: ' + family + size + weight);
                     if (!(family in allowableFonts) ||
                         !(weight in allowableFonts[family]) ||
                         !(size in allowableFonts[family][weight])) {
                       report('Disallowed font: ' +
                              family + size + weight, $(elt));
                     }
                   });
             } //---------------------------------------------------------
             }//==============================================================
           ]
}