|
| 1 | +define([ |
| 2 | + 'coreJS/adapt' |
| 3 | +], function(Adapt) { |
| 4 | + |
| 5 | + var cookie = (function cookie(){function e(){for(var e=0,n={};e<arguments.length;e++){var t=arguments[e];for(var r in t)n[r]=t[r]}return n}function n(t){function r(n,o,i){var c;if("undefined"!=typeof document){if(arguments.length>1){if(i=e({path:"/"},r.defaults,i),"number"==typeof i.expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}try{c=JSON.stringify(o),/^[\{\[]/.test(c)&&(o=c)}catch(s){}return o=t.write?t.write(o,n):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=encodeURIComponent(String(n)),n=n.replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent),n=n.replace(/[\(\)]/g,escape),document.cookie=[n,"=",o,i.expires&&"; expires="+i.expires.toUTCString(),i.path&&"; path="+i.path,i.domain&&"; domain="+i.domain,i.secure?"; secure":""].join("")}n||(c={});for(var p=document.cookie?document.cookie.split("; "):[],u=/(%[0-9A-Z]{2})+/g,d=0;d<p.length;d++){var f=p[d].split("="),l=f[0].replace(u,decodeURIComponent),m=f.slice(1).join("=");'"'===m.charAt(0)&&(m=m.slice(1,-1));try{if(m=t.read?t.read(m,l):t(m,l)||m.replace(u,decodeURIComponent),this.json)try{m=JSON.parse(m)}catch(s){}if(n===l){c=m;break}n||(c[l]=m)}catch(s){}}return c}}return r.set=r,r.get=function(e){return r(e)},r.getJSON=function(){return r.apply({json:!0},[].slice.call(arguments))},r.defaults={},r.remove=function(n,t){r(n,"",e(t,{expires:-1}))},r.withConverter=n,r}return n(function(){})})(); |
| 6 | + |
| 7 | + var AccessibilityView = Backbone.View.extend({ |
| 8 | + |
| 9 | + el: '#accessibility-toggle', |
| 10 | + |
| 11 | + initialize: function() { |
| 12 | + this.setupHelpers(); |
| 13 | + |
| 14 | + var settings = this.getStoredSettings(); |
| 15 | + Adapt.config.get("_accessibility")._isActive = settings.a11y || false; |
| 16 | + |
| 17 | + this.configureAccessibility(); |
| 18 | + this.setupUsageInstructions(); |
| 19 | + |
| 20 | + this.render(); |
| 21 | + }, |
| 22 | + |
| 23 | + getStoredSettings: function() { |
| 24 | + var str = cookie.get("_languagePicker") || "{}"; |
| 25 | + var settings = JSON.parse(str); |
| 26 | + return settings; |
| 27 | + }, |
| 28 | + |
| 29 | + setStoredSettings: function(settings) { |
| 30 | + var str = JSON.stringify(settings); |
| 31 | + cookie.set("_languagePicker", str); |
| 32 | + }, |
| 33 | + |
| 34 | + events: { |
| 35 | + 'click' : 'toggleAccessibility' |
| 36 | + }, |
| 37 | + |
| 38 | + render: function() { |
| 39 | + var hasAccessibility = Adapt.config.has('_accessibility') |
| 40 | + && Adapt.config.get('_accessibility')._isEnabled; |
| 41 | + |
| 42 | + if (!hasAccessibility) { |
| 43 | + return; |
| 44 | + } else { |
| 45 | + var isActive = Adapt.config.get('_accessibility')._isActive; |
| 46 | + var offLabel = this.model.get("_accessibility") && this.model.get("_accessibility")._accessibilityToggleTextOff; |
| 47 | + var onLabel = this.model.get("_accessibility") && this.model.get("_accessibility")._accessibilityToggleTextOn; |
| 48 | + |
| 49 | + var toggleText = isActive ? offLabel : onLabel; |
| 50 | + |
| 51 | + this.$el.html(toggleText); |
| 52 | + |
| 53 | + if (isActive) { |
| 54 | + $("html").addClass('accessibility'); |
| 55 | + $("#accessibility-instructions").a11y_focus(); |
| 56 | + } else { |
| 57 | + $("html").removeClass('accessibility'); |
| 58 | + } |
| 59 | + } |
| 60 | + }, |
| 61 | + |
| 62 | + toggleAccessibility: function(event) { |
| 63 | + event.preventDefault(); |
| 64 | + |
| 65 | + var hasAccessibility = Adapt.config.get('_accessibility')._isActive; |
| 66 | + |
| 67 | + var toggleAccessibility = (hasAccessibility) ? false : true; |
| 68 | + |
| 69 | + Adapt.config.get('_accessibility')._isActive = toggleAccessibility; |
| 70 | + |
| 71 | + Adapt.trigger('languagepicker:accessibility:toggle'); |
| 72 | + |
| 73 | + this.configureAccessibility(); |
| 74 | + this.setupUsageInstructions(); |
| 75 | + |
| 76 | + this.render(); |
| 77 | + |
| 78 | + window.location.reload(); |
| 79 | + }, |
| 80 | + |
| 81 | + setupHelpers: function() { |
| 82 | + var config = Adapt.config.get("_accessibility"); |
| 83 | + |
| 84 | + Handlebars.registerHelper('a11y_text', function(text) { |
| 85 | + //ALLOW ENABLE/DISABLE OF a11y_text HELPER |
| 86 | + if (config && config._isTextProcessorEnabled === false) { |
| 87 | + return text; |
| 88 | + } else { |
| 89 | + return $.a11y_text(text); |
| 90 | + } |
| 91 | + }); |
| 92 | + }, |
| 93 | + |
| 94 | + configureAccessibility: function() { |
| 95 | + |
| 96 | + var isActive = Adapt.config.get('_accessibility')._isActive; |
| 97 | + |
| 98 | + if (!Modernizr.touch) { |
| 99 | + var settings = { |
| 100 | + a11y: Adapt.config.get("_accessibility")._isActive |
| 101 | + }; |
| 102 | + this.setStoredSettings(settings); |
| 103 | + Adapt.offlineStorage.set("a11y", settings.a11y); |
| 104 | + } |
| 105 | + |
| 106 | + if (isActive) { |
| 107 | + |
| 108 | + _.extend($.a11y.options, { |
| 109 | + isTabbableTextEnabled: true, |
| 110 | + isUserInputControlEnabled: true, |
| 111 | + isFocusControlEnabled: true, |
| 112 | + isFocusLimited: true, |
| 113 | + isRemoveNotAccessiblesEnabled: true, |
| 114 | + isAriaLabelFixEnabled: true, |
| 115 | + isFocusWrapEnabled: true, |
| 116 | + isScrollDisableEnabled: true, |
| 117 | + isScrollDisabledOnPopupEnabled: false, |
| 118 | + isSelectedAlertsEnabled: true, |
| 119 | + isAlertsEnabled: true |
| 120 | + }); |
| 121 | + } else { |
| 122 | + _.extend($.a11y.options, { |
| 123 | + isTabbableTextEnabled: false, |
| 124 | + isUserInputControlEnabled: true, |
| 125 | + isFocusControlEnabled: true, |
| 126 | + isFocusLimited: false, |
| 127 | + isRemoveNotAccessiblesEnabled: true, |
| 128 | + isAriaLabelFixEnabled: true, |
| 129 | + isFocusWrapEnabled: true, |
| 130 | + isScrollDisableEnabled: true, |
| 131 | + isScrollDisabledOnPopupEnabled: false, |
| 132 | + isSelectedAlertsEnabled: false, |
| 133 | + isAlertsEnabled: false |
| 134 | + }); |
| 135 | + } |
| 136 | + |
| 137 | + $.a11y.ready(); |
| 138 | + }, |
| 139 | + |
| 140 | + setupUsageInstructions: function() { |
| 141 | + if (!this.model.get("_accessibility") || !this.model.get("_accessibility")._accessibilityInstructions) { |
| 142 | + $("#accessibility-instructions").remove(); |
| 143 | + return; |
| 144 | + } |
| 145 | + |
| 146 | + var instructionsList = this.model.get("_accessibility")._accessibilityInstructions; |
| 147 | + |
| 148 | + var usageInstructions; |
| 149 | + if (instructionsList[Adapt.device.browser]) { |
| 150 | + usageInstructions = instructionsList[Adapt.device.browser]; |
| 151 | + } else if (Modernizr.touch) { |
| 152 | + usageInstructions = instructionsList.touch || ""; |
| 153 | + } else { |
| 154 | + usageInstructions = instructionsList.notouch || ""; |
| 155 | + } |
| 156 | + |
| 157 | + $("#accessibility-instructions").html( usageInstructions ); |
| 158 | + } |
| 159 | + |
| 160 | + }); |
| 161 | + |
| 162 | + return AccessibilityView; |
| 163 | + |
| 164 | +}); |
0 commit comments