1(function () { 2 var COOKIE_NAME = 'etna_accessibility_toolbar'; 3 var COOKIE_DAYS = 180; 4 var FONT_MIN = 100; 5 var FONT_MAX = 150; 6 var FONT_STEP = 10; 7 var FONT_STYLE_ID = 'etnaA11yContentFontStyle'; 8 var FONT_TARGET_SELECTOR = 'body .pagearea h1, body .pagearea h2, body .pagearea h3, body .pagearea h4, body .pagearea h5, body .pagearea h6, body .pagearea p, body .pagearea li, body .pagearea dt, body .pagearea dd, body .pagearea th, body .pagearea td, body .pagearea a, body .pagearea span, body .pagearea small, body .pagearea strong, body .pagearea b, body .pagearea em, body .pagearea label, body .pagearea legend, body .pagearea figcaption, body .pagearea blockquote, body .pagearea button, body .pagearea input, body .pagearea textarea, body .pagearea select'; 9 var ORIGINAL_FONT_SIZE_ATTR = 'data-etna-a11y-original-font-size'; 10 var ORIGINAL_INLINE_FONT_SIZE_ATTR = 'data-etna-a11y-inline-font-size'; 11 var EMPTY_INLINE_FONT_SIZE = '__empty__'; 12 var defaults = { 13 v: 1, 14 fontSize: 100, 15 contrast: false, 16 underline: false, 17 reduceMotion: false 18 }; 19 20 function extendDefaults(value) { 21 var state = {}; 22 var key; 23 for (key in defaults) { 24 if (Object.prototype.hasOwnProperty.call(defaults, key)) { 25 state[key] = defaults[key]; 26 } 27 } 28 if (value && typeof value === 'object') { 29 if (isValidFont(value.fontSize)) { 30 state.fontSize = value.fontSize; 31 } 32 state.contrast = value.contrast === true; 33 state.underline = value.underline === true; 34 state.reduceMotion = value.reduceMotion === true; 35 } 36 return state; 37 } 38 39 function isValidFont(value) { 40 return typeof value === 'number' && value >= FONT_MIN && value <= FONT_MAX && value % FONT_STEP === 0; 41 } 42 43 function getCookie(name) { 44 var prefix = name + '='; 45 var cookies = document.cookie ? document.cookie.split(';') : []; 46 var i; 47 var item; 48 for (i = 0; i < cookies.length; i += 1) { 49 item = cookies[i].replace(/^\s+/, ''); 50 if (item.indexOf(prefix) === 0) { 51 return item.substring(prefix.length); 52 } 53 } 54 return ''; 55 } 56 57 function setCookie(name, value, days) { 58 var expires = new Date(); 59 var secure = window.location.protocol === 'https:' ? '; Secure' : ''; 60 expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000)); 61 document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires.toUTCString() + '; path=/; SameSite=Lax' + secure; 62 } 63 64 function removeCookie(name) { 65 var secure = window.location.protocol === 'https:' ? '; Secure' : ''; 66 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax' + secure; 67 } 68 69 function readState() { 70 var raw = getCookie(COOKIE_NAME); 71 if (!raw) { 72 return extendDefaults(); 73 } 74 try { 75 return extendDefaults(JSON.parse(decodeURIComponent(raw))); 76 } catch (e) { 77 return extendDefaults(); 78 } 79 } 80 81 function writeState(state) { 82 if (state.fontSize === defaults.fontSize && !state.contrast && !state.underline && !state.reduceMotion) { 83 removeCookie(COOKIE_NAME); 84 return; 85 } 86 setCookie(COOKIE_NAME, JSON.stringify(state), COOKIE_DAYS); 87 } 88 89 function hasClass(el, className) { 90 if (el.classList) { 91 return el.classList.contains(className); 92 } 93 return (' ' + el.className + ' ').indexOf(' ' + className + ' ') > -1; 94 } 95 96 function addClass(el, className) { 97 if (el.classList) { 98 el.classList.add(className); 99 } else if (!hasClass(el, className)) { 100 el.className += ' ' + className; 101 } 102 } 103 104 function removeClass(el, className) { 105 if (el.classList) { 106 el.classList.remove(className); 107 } else { 108 el.className = (' ' + el.className + ' ').replace(' ' + className + ' ', ' ').replace(/^\s+|\s+$/g, ''); 109 } 110 } 111 112 function toggleClass(el, className, enabled) { 113 if (enabled) { 114 addClass(el, className); 115 } else { 116 removeClass(el, className); 117 } 118 } 119 120 function setStyleText(style, cssText) { 121 if (style.styleSheet) { 122 style.styleSheet.cssText = cssText; 123 } else { 124 style.textContent = cssText; 125 } 126 } 127 128 function applyContentFontSize(value) { 129 var doc = document.documentElement; 130 var body = document.body; 131 var head = document.getElementsByTagName('head')[0]; 132 var style = document.getElementById(FONT_STYLE_ID); 133 var targets = document.querySelectorAll ? document.querySelectorAll(FONT_TARGET_SELECTOR) : []; 134 var cssText; 135 var factor = value / 100; 136 var i; 137 var el; 138 var originalFontSize; 139 var originalInlineFontSize; 140 141 doc.style.fontSize = ''; 142 if (body) { 143 body.style.fontSize = ''; 144 } 145 146 if (value === defaults.fontSize) { 147 if (style && style.parentNode) { 148 style.parentNode.removeChild(style); 149 } 150 for (i = 0; i < targets.length; i += 1) { 151 el = targets[i]; 152 originalInlineFontSize = el.getAttribute(ORIGINAL_INLINE_FONT_SIZE_ATTR); 153 if (originalInlineFontSize !== null) { 154 el.style.fontSize = originalInlineFontSize === EMPTY_INLINE_FONT_SIZE ? '' : originalInlineFontSize; 155 el.removeAttribute(ORIGINAL_INLINE_FONT_SIZE_ATTR); 156 } 157 el.removeAttribute(ORIGINAL_FONT_SIZE_ATTR); 158 } 159 return; 160 } 161 162 if (!head) { 163 return; 164 } 165 166 if (!style) { 167 style = document.createElement('style'); 168 style.id = FONT_STYLE_ID; 169 style.type = 'text/css'; 170 head.appendChild(style); 171 } 172 173 setStyleText(style, ''); 174 175 for (i = 0; i < targets.length; i += 1) { 176 el = targets[i]; 177 originalFontSize = el.getAttribute(ORIGINAL_FONT_SIZE_ATTR); 178 if (!originalFontSize) { 179 originalFontSize = window.getComputedStyle ? window.getComputedStyle(el).fontSize : el.currentStyle.fontSize; 180 el.setAttribute(ORIGINAL_FONT_SIZE_ATTR, originalFontSize); 181 el.setAttribute(ORIGINAL_INLINE_FONT_SIZE_ATTR, el.style.fontSize || EMPTY_INLINE_FONT_SIZE); 182 } 183 if (!isNaN(parseFloat(originalFontSize))) { 184 el.style.fontSize = (parseFloat(originalFontSize) * factor) + 'px'; 185 } 186 } 187 188 cssText = 'body .pagearea {font-size: ' + value + '% !important;}'; 189 setStyleText(style, cssText); 190 } 191 192 function ready(callback) { 193 if (document.readyState === 'loading') { 194 document.addEventListener('DOMContentLoaded', callback); 195 } else { 196 callback(); 197 } 198 } 199 200 ready(function () { 201 var root = document.querySelector('[data-etna-a11y-root]'); 202 if (!root) { 203 return; 204 } 205 206 var doc = document.documentElement; 207 var body = document.body; 208 var state = readState(); 209 var lang = root.getAttribute('data-lang') === 'en' ? 'en' : 'it'; 210 var toggle = document.getElementById('etnaA11yToggle'); 211 var panel = document.getElementById('etnaA11yPanel'); 212 var status = root.querySelector('[data-etna-a11y-status]'); 213 var btnIncrease = root.querySelector('[data-etna-a11y-action="increase-font"]'); 214 var btnDecrease = root.querySelector('[data-etna-a11y-action="decrease-font"]'); 215 var btnContrast = root.querySelector('[data-etna-a11y-action="contrast"]'); 216 var btnUnderline = root.querySelector('[data-etna-a11y-action="underline"]'); 217 var btnReduceMotion = root.querySelector('[data-etna-a11y-action="reduce-motion"]'); 218 var btnReset = root.querySelector('[data-etna-a11y-action="reset"]'); 219 var statusText = lang === 'en' ? 'Accessibility preferences updated' : 'Preferenze di accessibilita aggiornate'; 220 221 function announce() { 222 if (!status) { 223 return; 224 } 225 status.textContent = ''; 226 window.setTimeout(function () { 227 status.textContent = statusText; 228 }, 20); 229 } 230 231 function setDisabled(button, disabled) { 232 if (!button) { 233 return; 234 } 235 button.disabled = disabled; 236 button.setAttribute('aria-disabled', disabled ? 'true' : 'false'); 237 } 238 239 function setPressed(button, pressed) { 240 if (!button) { 241 return; 242 } 243 button.setAttribute('aria-pressed', pressed ? 'true' : 'false'); 244 } 245 246 function applyState(options) { 247 var persist = !options || options.persist !== false; 248 applyContentFontSize(state.fontSize); 249 toggleClass(doc, 'etna-a11y-high-contrast', state.contrast); 250 toggleClass(doc, 'etna-a11y-underline-links', state.underline); 251 toggleClass(doc, 'etna-a11y-reduce-motion', state.reduceMotion); 252 setDisabled(btnDecrease, state.fontSize <= FONT_MIN); 253 setDisabled(btnIncrease, state.fontSize >= FONT_MAX); 254 setPressed(btnContrast, state.contrast); 255 setPressed(btnUnderline, state.underline); 256 setPressed(btnReduceMotion, state.reduceMotion); 257 if (persist) { 258 writeState(state); 259 announce(); 260 } 261 } 262
263 function openPanel() { 264 if (!panel || !toggle) { 265 return; 266 } 267 panel.hidden = false; 268 panel.setAttribute('aria-hidden', 'false'); 269 toggle.setAttribute('aria-expanded', 'true'); 270 } 271 272 function closePanel() { 273 if (!panel || !toggle) { 274 return; 275 } 276 panel.hidden = true; 277 panel.setAttribute('aria-hidden', 'true'); 278 toggle.setAttribute('aria-expanded', 'false'); 279 } 280 281 function togglePanel() { 282 if (!panel || !toggle) { 283 return; 284 } 285 if (panel.hidden) { 286 openPanel(); 287 } else { 288 closePanel(); 289 } 290 } 291 292 function resetState() { 293 state = extendDefaults(); 294 closePanel(); 295 applyState(); 296 } 297 298 applyState({persist: false}); 299 300 if (toggle) { 301 toggle.addEventListener('click', togglePanel); 302 } 303 if (btnIncrease) { 304 btnIncrease.addEventListener('click', function () { 305 if (state.fontSize < FONT_MAX) { 306 state.fontSize += FONT_STEP; 307 applyState(); 308 } 309 }); 310 } 311 if (btnDecrease) { 312 btnDecrease.addEventListener('click', function () { 313 if (state.fontSize > FONT_MIN) { 314 state.fontSize -= FONT_STEP; 315 applyState(); 316 } 317 }); 318 } 319 if (btnContrast) { 320 btnContrast.addEventListener('click', function () { 321 state.contrast = !state.contrast; 322 applyState(); 323 }); 324 } 325 if (btnUnderline) { 326 btnUnderline.addEventListener('click', function () { 327 state.underline = !state.underline; 328 applyState(); 329 }); 330 } 331 if (btnReduceMotion) { 332 btnReduceMotion.addEventListener('click', function () { 333 state.reduceMotion = !state.reduceMotion; 334 applyState(); 335 }); 336 } 337 if (btnReset) { 338 btnReset.addEventListener('click', resetState); 339 } 340 341 document.addEventListener('keydown', function (event) { 342 if ((event.key === 'Escape' || event.keyCode === 27) && panel && !panel.hidden) { 343 closePanel(); 344 if (toggle) { 345 toggle.focus(); 346 } 347 } 348 }); 349 }); 350})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.