summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/etc/accessibility.js
blob: 31ddaf2324a0ee2570809a22e9477e2a8cf473bf (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var accessibility = (function() {

  var accessibility = {}
  accessibility.voiceOver = false

  accessibility.DEBUG = false

  accessibility.init = function(ready) {
    console.log('Accessibility init')
    accessibility.bind()
    if (accessibility.DEBUG) {
      console.log('Accessibility debug mode')
      app.accessible = true
      accessibility.voiceOver = true
      $('html').addClass('vscroll')
      $('html').addClass('accessible')
      return ready()
    }
    if ('MobileAccessibility' in window) {
      console.log('init accessibility')
      accessibility.build(ready)
    } else {
      console.log('MobileAccessibility not found')
      ready()
    }
  }

  accessibility.build = function(ready) {
    MobileAccessibility.usePreferredTextZoom(true);
    MobileAccessibility.getTextZoom(function getTextZoomCallback(textZoom) {
      console.log('WebView text should be scaled to the preferred value ' + textZoom + '%')
      if (textZoom > 100) {
        app.accessible = true
        $("html").addClass('accessible')
      }
    });
    MobileAccessibility.isVoiceOverRunning(function(state){
      console.log('Screen reader: ' + state)
      accessibility.voiceOver = state
      if (state) {
        console.log(">>>>>> actual debug mode!")
        app.accessible = true
        $("html").addClass('accessible')
        $('html').addClass('vscroll')
      } else {
        $('html').addClass('iscroll')
      }
      ready()
    })
  }

  accessibility.bind = function() {
    $("h1").each(function(){
      this['aria-label'] = 'Section title is ' + this.innerText
    })
    if ('MobileAccessibilityNotifications' in window) {
      window.addEventListener(MobileAccessibilityNotifications.SCREEN_READER_STATUS_CHANGED,
        accessibility.onScreenReaderStatusChanged, false)
    }
  }

  accessibility.onScreenReaderStatusChanged = function(info) {
    if (info && typeof info.isScreenReaderRunning !== "undefined") {
      if (info.isScreenReaderRunning) {
        console.log("Screen reader: ON");
      } else {
        console.log("Screen reader: OFF");
      }
    }
  }

  return accessibility
})()

function stonewash (s) {
  return s.replace(/'9/g, '19').replace(/'0/g, '20').replace(/_/g, ' ').replace(/-/g, ' - ').replace(/^[013456789][0-9]+/, '')
}