62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
(function () {
|
|
// Text data
|
|
var textData = {
|
|
'in': {
|
|
'button': 'Deactivate Accessibility Tools',
|
|
'snippet': 'Activated'
|
|
},
|
|
'out': {
|
|
'button': 'Activate Accessibility Tools',
|
|
'snippet': 'Not Activated'
|
|
}
|
|
};
|
|
// get page elements
|
|
var activation_button = document.getElementById('ae_activation');
|
|
var activation_snippet = document.getElementById('ae_activation_snippet');
|
|
// listen for click
|
|
activation_button.addEventListener('click', function () {
|
|
if (!window.AudioEye || !window.AudioEye.optIn) {
|
|
throw new Error('AudioEye Opt in not supported');
|
|
}
|
|
// toggle opt in state
|
|
toggle(
|
|
AudioEye.optIn,
|
|
textData,
|
|
activation_button,
|
|
activation_snippet
|
|
);
|
|
});
|
|
|
|
//Toggle user's opt in state and manage page state
|
|
//@param optIn {object} - AudioEye.optIn
|
|
//@param textData {object} - text data for in and out states
|
|
//@param button {DOMNode} - text data for in and out states
|
|
//@param snippet {DOMNode} - text data for in and out states
|
|
|
|
function toggle(optIn, textData, button, snippet) {
|
|
// get opposite state
|
|
var new_state = (optIn.state('BASE')) ? 'out' : 'in';
|
|
// fix site menu dash
|
|
$ae('.ae-accessible-menu-button:contains("Site-Menu")').text('Site Menu');
|
|
|
|
// Request opt in/out
|
|
optIn.opt(new_state, 'BASE');
|
|
// Update display state
|
|
button.innerText = textData[new_state].button;
|
|
snippet.innerText = textData[new_state].snippet;
|
|
}
|
|
var pollOptIn = window.setInterval(function () {
|
|
|
|
// user is opted in - restore previous state
|
|
if (window.AudioEye && window.AudioEye.optIn && window.AudioEye.optIn.state('BASE')) {
|
|
|
|
// stop polling
|
|
window.clearInterval(pollOptIn);
|
|
// Fix site menu dash
|
|
$ae('.ae-accessible-menu-button:contains("Site-Menu")').text('Site Menu');
|
|
// Update display state
|
|
activation_button.innerText = textData['in'].button;
|
|
activation_snippet.innerText = textData['in'].snippet;
|
|
}
|
|
}, 50);
|
|
})(); |