earcon_util.js revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/** 6 * @fileoverview Earcon utils. 7 */ 8 9goog.provide('cvox.EarconUtil'); 10 11goog.require('cvox.AbstractEarcons'); 12goog.require('cvox.AriaUtil'); 13goog.require('cvox.DomUtil'); 14 15/** 16 * Returns the id of an earcon to play along with the description for a node. 17 * 18 * @param {Node} node The node to get the earcon for. 19 * @return {number?} The earcon id, or null if none applies. 20 */ 21cvox.EarconUtil.getEarcon = function(node) { 22 var earcon = cvox.AriaUtil.getEarcon(node); 23 if (earcon != null) { 24 return earcon; 25 } 26 27 switch (node.tagName) { 28 case 'BUTTON': 29 return cvox.AbstractEarcons.BUTTON; 30 case 'A': 31 if (node.hasAttribute('href')) { 32 return cvox.AbstractEarcons.LINK; 33 } 34 break; 35 case 'IMG': 36 if (cvox.DomUtil.hasLongDesc(node)) { 37 return cvox.AbstractEarcons.LONG_DESC; 38 } 39 break; 40 case 'LI': 41 return cvox.AbstractEarcons.LIST_ITEM; 42 case 'SELECT': 43 return cvox.AbstractEarcons.LISTBOX; 44 case 'TEXTAREA': 45 return cvox.AbstractEarcons.EDITABLE_TEXT; 46 case 'INPUT': 47 switch (node.type) { 48 case 'button': 49 case 'submit': 50 case 'reset': 51 return cvox.AbstractEarcons.BUTTON; 52 case 'checkbox': 53 case 'radio': 54 if (node.checked) { 55 return cvox.AbstractEarcons.CHECK_ON; 56 } else { 57 return cvox.AbstractEarcons.CHECK_OFF; 58 } 59 default: 60 if (cvox.DomUtil.isInputTypeText(node)) { 61 // 'text', 'password', etc. 62 return cvox.AbstractEarcons.EDITABLE_TEXT; 63 } 64 } 65 } 66 return null; 67}; 68