~ubuntu-it-wiki/wiki-ubuntu-it/wiki-repo

« back to all changes in this revision

Viewing changes to htdocs/light/js/accessibility.js

  • Committer: Leo Iannacone
  • Date: 2011-06-01 19:48:26 UTC
  • Revision ID: l3on@ubuntu.com-20110601194826-a8zt6and1d9gqmfu
Update light theme to ubuntu-it style

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** This file contains function to enable and
 
3
** disable Accessibility stylesheet in ubuntu-it
 
4
*/
 
5
 
 
6
ACCESSIBILITY_CSS_THEME_DIR = 'light-drupal-theme/styles';
 
7
ACCESSIBILITY_CSS_FILE_NAME = 'accessibility.css' ;
 
8
ACCESSIBILITY_COOKIE_VALUE_ON = 'on';
 
9
ACCESSIBILITY_COOKIE_VALUE_OFF = 'off';
 
10
 
 
11
// This function adds the accessibility css into the Head section
 
12
// and set the cookie value ON
 
13
function accessibility_set_on () {
 
14
  // Get the absolute path of theme dir from other css files
 
15
  head = document.getElementsByTagName('head')[0];
 
16
  links = head.getElementsByTagName('link');
 
17
  theme_dir = '';
 
18
  for (i = 0 ; i < links.length ; i++) {
 
19
    link = links[i];
 
20
    if (link.hasAttribute('type') && 
 
21
        link.getAttribute('type') == 'text/css' &&
 
22
        link.hasAttribute('href') &&
 
23
        link.getAttribute('href').indexOf(ACCESSIBILITY_CSS_THEME_DIR) >= 0) {
 
24
          // set theme_dir 
 
25
          theme_dir = link.getAttribute('href').replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '');
 
26
 
 
27
          break;
 
28
        }
 
29
  }
 
30
 
 
31
  accessibility_css_file = theme_dir + '/' + ACCESSIBILITY_CSS_FILE_NAME;
 
32
 
 
33
  link = document.createElement('link');
 
34
  link.setAttribute('type','text/css');
 
35
  link.setAttribute('rel', 'stylesheet');
 
36
  link.setAttribute('media', 'all');
 
37
  link.setAttribute('href', accessibility_css_file);
 
38
  
 
39
  head.appendChild(link);
 
40
  set_cookie_accessibility( ACCESSIBILITY_COOKIE_VALUE_ON );
 
41
}
 
42
 
 
43
// This function removes the accessibility css from the Head section
 
44
// and set the cookie offset
 
45
function accessibility_set_off() {
 
46
  head = document.getElementsByTagName('head')[0];
 
47
  links = head.getElementsByTagName('link');
 
48
  for (i = 0 ; i < links.length ; i++) {
 
49
    link = links[i];
 
50
    if (link.hasAttribute('type') && 
 
51
        link.getAttribute('type') == 'text/css' &&
 
52
        link.hasAttribute('href') &&
 
53
        link.getAttribute('href').indexOf(ACCESSIBILITY_CSS_THEME_DIR + "/" + ACCESSIBILITY_CSS_FILE_NAME) >= 0) {
 
54
        head.removeChild(link);
 
55
        break;
 
56
    }
 
57
  }
 
58
  set_cookie_accessibility( ACCESSIBILITY_COOKIE_VALUE_OFF );
 
59
}
 
60
 
 
61
 
 
62
function accessibility_toggle () {
 
63
  value = get_cookie_accessibility();
 
64
 
 
65
  // console.info('Accessibility: ' + value)
 
66
 
 
67
  // If accessibility is ON, add the css stylesheet
 
68
  if (value == ACCESSIBILITY_COOKIE_VALUE_OFF)
 
69
    accessibility_set_on();
 
70
  else
 
71
    accessibility_set_off();
 
72
}
 
73
 
 
74
// The main function
 
75
function accessibility () {
 
76
  accessibility_toggle();
 
77
}