'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['jquery', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function ($, Class) { /** * This is a utility class to assist with ScreenReader interaction. * It provides a standard method to allow callouts on events or other occurances when * direct update of the UI is not available to the screen reader. * It creates a textbox input that hidden off screen and uses the aria-live attribute * to call out the string message. * * Example Usage: * * this.myScreenReader = new ScreenReaderUtil(); * * someEventHandler: function( event ){ * * this.myScreenReader.callOut( 'event happened' ); * } * * @class ScreenReaderUtil */ var ScreenReaderUtil = null; ScreenReaderUtil = Class.extend({ INPUTBOX_ID: 'boardScreenReaderInputBox', CLEAR_TIMER_DURATION: 500, oCallOutClearTimer: null, init: function init() { ScreenReaderUtil.inherited('init', this, arguments); // check to see if the textbox exists and create as necessary if ($('#' + this.INPUTBOX_ID).length === 0) { // create the screen reader global input box to be used to call out for events etc. // position it off screen (must be visible for the screen reader to read it) var divScreenReaderCallout = document.createElement('div'); divScreenReaderCallout.style.width = '0px'; divScreenReaderCallout.style.height = '0px'; divScreenReaderCallout.style.overflow = 'hidden'; divScreenReaderCallout.style.position = 'absolute'; divScreenReaderCallout.style.top = '-1px'; divScreenReaderCallout.style.left = '-1px'; var txtScreenReaderCallout = document.createElement('input'); txtScreenReaderCallout.type = 'text'; txtScreenReaderCallout.id = this.INPUTBOX_ID; txtScreenReaderCallout.setAttribute('aria-selected', 'false'); txtScreenReaderCallout.setAttribute('aria-live', 'assertive'); txtScreenReaderCallout.setAttribute('tabIndex', '-1'); $(divScreenReaderCallout).append(txtScreenReaderCallout); $('body').append(divScreenReaderCallout); } }, callOut: function callOut(sMessage) { // cancel any existing timer if (this.oCallOutClearTimer) { clearInterval(this.oCallOutClearTimer); } // set the value and clear timer $('#' + this.INPUTBOX_ID).val(sMessage); this.oCallOutClearTimer = setTimeout(function () { $('#' + this.INPUTBOX_ID).val(''); }.bind(this), this.CLEAR_TIMER_DURATION); }, destroy: function destroy() { // remove textbox and container $('#' + this.INPUTBOX_ID).parent().remove(); // complete inherited destroy operations ScreenReaderUtil.inherited('destroy', this, arguments); } }); return ScreenReaderUtil; }); //# sourceMappingURL=ScreenReaderUtil.js.map