rave-accessibility.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. (function() {
  2. // $source: com/ibm/rave/accessibility/internal/nativeImpl/ModuleHeader
  3. /************************************************************************
  4. ** IBM Confidential
  5. **
  6. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  7. **
  8. ** (C) Copyright IBM Corp. 2014, 2015
  9. **
  10. ** The source code for this program is not published or otherwise divested of its trade secrets,
  11. ** irrespective of what has been deposited with the U.S. Copyright Office.
  12. ************************************************************************/
  13. // setup
  14. var rave = window["rave"], rave_document = rave["_"]["rave_document"], rave_externs={},
  15. com_ibm_rave_core_Rave = rave,
  16. com_ibm_rave_core_nativeImpl_Declare = rave["_"]["com_ibm_rave_core_nativeImpl_Declare"],
  17. com_ibm_rave_core_selector_Selector = rave["internal"]["Selector"],
  18. com_ibm_rave_core_selector_SelectorDelegate = rave["internal"]["SelectorDelegate"],
  19. com_ibm_rave_navigation_focus_FocusController = rave["navigation"]["internal"]["FocusController"],
  20. com_ibm_rave_navigation_Navigation = rave["navigation"];
  21. // $source: com/ibm/rave/accessibility/AccessibilityConstants
  22. /************************************************************************
  23. ** IBM Confidential
  24. **
  25. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  26. **
  27. ** (C) Copyright IBM Corp. 2015
  28. **
  29. ** The source code for this program is not published or otherwise divested of its trade secrets,
  30. ** irrespective of what has been deposited with the U.S. Copyright Office.
  31. ************************************************************************/
  32. // GENERATED
  33. var com_ibm_rave_accessibility_AccessibilityConstants = rave_externs["AccessibilityConstants"] = {
  34. };
  35. /**
  36. * Key for the accessibility selector. To access accessibility methods on a selector, get the accessibility selector from the core selector this way: <code> AccessibilitySelector a11ySelector = (AccessibilitySelector) Rave.select("id").extension( Accessibility.SELECTOR_ID); </code>
  37. */
  38. /** @expose */
  39. com_ibm_rave_accessibility_AccessibilityConstants.SELECTOR_ID = "raveAccessibility";
  40. /**
  41. * Property key for accessible info. The accessible info must be of type {@link (Object) AccessibleInfo} .
  42. */
  43. /** @expose */
  44. com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY = "__accessibleInfo__";
  45. /**
  46. * Property key for shadow tree builder. The shadow tree builder must be of type {@link (com.ibm.rave.accessibility.ShadowTreeBuilder) ShadowTreeBuilder} .
  47. */
  48. /** @expose */
  49. com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY = "__shadowTreeBuilder__";
  50. // $source: com/ibm/rave/accessibility/internal/AccessibleNavigationSceneNodeExtension
  51. /************************************************************************
  52. ** IBM Confidential
  53. **
  54. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  55. **
  56. ** (C) Copyright IBM Corp. 2015
  57. **
  58. ** The source code for this program is not published or otherwise divested of its trade secrets,
  59. ** irrespective of what has been deposited with the U.S. Copyright Office.
  60. ************************************************************************/
  61. // GENERATED
  62. //@import com/ibm/rave/core/Rave (static) // Rave
  63. //@import com/ibm/rave/accessibility/internal/AccessibilityUtil (runtime) // getShadowTreeBuilder, recursiveSetShadowTreeBuilder
  64. //@import com/ibm/rave/accessibility/AccessibilityConstants (runtime) // AccessibilityConstants
  65. var com_ibm_rave_accessibility_internal_AccessibleNavigationSceneNodeExtension = {
  66. //constructor : function() {}
  67. };
  68. com_ibm_rave_accessibility_internal_AccessibleNavigationSceneNodeExtension.extend = function(baseNode) {
  69. var oriAppendChild = baseNode.appendChild;
  70. baseNode.appendChild = function(node) {
  71. oriAppendChild.call(this, node);
  72. com_ibm_rave_core_Rave.configuration.extendRecursive(node);
  73. var builder = com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder(this);
  74. if (builder) {
  75. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder(node, builder);
  76. builder.onAppend(this, node);
  77. }
  78. };
  79. var oriInsertBefore = baseNode.insertBefore;
  80. baseNode.insertBefore = function(node, before) {
  81. oriInsertBefore.call(this, node, before);
  82. com_ibm_rave_core_Rave.configuration.extendRecursive(node);
  83. var builder = com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder(this);
  84. if (builder) {
  85. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder(node, builder);
  86. builder.onInsert(this, node, before);
  87. }
  88. };
  89. var oriRemoveChild = baseNode.removeChild;
  90. baseNode.removeChild = function(node) {
  91. var i = this.rave_getChildNodes().indexOf(node);
  92. if (i != -1) {
  93. oriRemoveChild.call(this, node);
  94. com_ibm_rave_core_Rave.configuration.extendRecursive(node);
  95. var builder = com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder(node);
  96. if (builder) {
  97. builder.onRemove(this, node, i);
  98. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder(node, null);
  99. }
  100. return true;
  101. }
  102. return false;
  103. };
  104. var oriSetProperty = baseNode.rave_setProperty;
  105. baseNode.rave_setProperty = function(key, value) {
  106. oriSetProperty.call(this, key, value);
  107. if (com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY == key) {
  108. var builder = com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder(this);
  109. if (builder) {
  110. builder.onChange(this);
  111. }
  112. }
  113. };
  114. };
  115. com_ibm_rave_accessibility_internal_AccessibleNavigationSceneNodeExtension.register = function() {
  116. com_ibm_rave_core_Rave.configuration.addSceneNodeExtensionFactory("http://www.w3.org/2000/svg", function(node, context) {
  117. if ((context && context.rave_hasProperty(com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY)) || node.rave_hasProperty(com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY)) {
  118. com_ibm_rave_accessibility_internal_AccessibleNavigationSceneNodeExtension.extend(node);
  119. }
  120. }, 0);
  121. };
  122. // $source: com/ibm/rave/accessibility/internal/AccessibilityUtil
  123. /************************************************************************
  124. ** IBM Confidential
  125. **
  126. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  127. **
  128. ** (C) Copyright IBM Corp. 2015
  129. **
  130. ** The source code for this program is not published or otherwise divested of its trade secrets,
  131. ** irrespective of what has been deposited with the U.S. Copyright Office.
  132. ************************************************************************/
  133. // GENERATED
  134. //@import com/ibm/rave/accessibility/AccessibilityConstants (static) // AccessibilityConstants
  135. //@import com/ibm/rave/core/selector/Selector (static) // extension
  136. //@import com/ibm/rave/accessibility/selector/AccessibilitySelector (runtime) // new
  137. var com_ibm_rave_accessibility_internal_AccessibilityUtil = {
  138. //constructor : function() {}
  139. };
  140. com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder = function(node) {
  141. return node.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY);
  142. };
  143. com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo = function(node) {
  144. return node.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY) != null;
  145. };
  146. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder = function(node, builder) {
  147. node.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY, builder);
  148. if (node.rave_hasChildNodes()) {
  149. for (var __i_enFor0 = 0, __exp_enFor0 = node.rave_getChildNodes(), __len_enFor0 = __exp_enFor0.length;
  150. __i_enFor0 < __len_enFor0; ++__i_enFor0) {
  151. var child = __exp_enFor0[__i_enFor0];
  152. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder(child, builder);
  153. }
  154. }
  155. };
  156. com_ibm_rave_accessibility_internal_AccessibilityUtil.registerSelector = function() {
  157. com_ibm_rave_core_selector_Selector.extension(com_ibm_rave_accessibility_AccessibilityConstants.SELECTOR_ID, function() {
  158. return new com_ibm_rave_accessibility_selector_AccessibilitySelector();
  159. });
  160. };
  161. // $source: com/ibm/rave/accessibility/selector/AccessibilitySelector
  162. /************************************************************************
  163. ** IBM Confidential
  164. **
  165. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  166. **
  167. ** (C) Copyright IBM Corp. 2015
  168. **
  169. ** The source code for this program is not published or otherwise divested of its trade secrets,
  170. ** irrespective of what has been deposited with the U.S. Copyright Office.
  171. ************************************************************************/
  172. // GENERATED
  173. //@import com/ibm/rave/core/nativeImpl/Declare (loadtime) // declare
  174. //@import com/ibm/rave/core/selector/SelectorDelegate (loadtime) // superclass
  175. //@import com/ibm/rave/accessibility/internal/nativeImpl/AccessibleContext (runtime) // getDescription, setDescription
  176. //@import com/ibm/rave/accessibility/AccessibilityConstants (runtime) // AccessibilityConstants
  177. /**
  178. * Accessibility extension to {@link (com.ibm.rave.core.selector.SelectorDelegate) SelectorDelegate} . Adds the ability to perform accessibility related functions to a selector.
  179. */
  180. var com_ibm_rave_accessibility_selector_AccessibilitySelector = rave_externs["AccessibilitySelector"] = com_ibm_rave_core_nativeImpl_Declare(com_ibm_rave_core_selector_SelectorDelegate, {
  181. /**
  182. * Constructor
  183. */
  184. /** @expose */
  185. constructor : function() {},
  186. /**
  187. * @see {@link this.SelectorDelegate#this.create}
  188. */
  189. /** @expose */
  190. create : function(s) {
  191. var as = new com_ibm_rave_accessibility_selector_AccessibilitySelector();
  192. return as.setDelegate(s);
  193. },
  194. /**
  195. * Get the accessible description for the first SceneNode in this Selector. In JavaScript, this gets the "aria-label".
  196. * @return (String) the accessible description of the first SceneNode in this Selector
  197. */
  198. description$0 : function() {
  199. var node = this.node();
  200. var owner = node ? node.rave_getOwner() : null;
  201. return !owner ? null : com_ibm_rave_accessibility_internal_nativeImpl_AccessibleContext.getDescription(owner);
  202. },
  203. /**
  204. * Set an accessible description for each owner of SceneNode in this Selector. In JavaScript, this sets the "aria-label".
  205. * @param (String) description the description
  206. * @return (com.ibm.rave.accessibility.selector.AccessibilitySelector) this {@link (com.ibm.rave.accessibility.selector.AccessibilitySelector) AccessibilitySelector}
  207. */
  208. description$1 : function(description) {
  209. this.each(function(data, index, groupIndex) {
  210. var owner = this.rave_getOwner();
  211. if (owner) {
  212. com_ibm_rave_accessibility_internal_nativeImpl_AccessibleContext.setDescription(owner, description);
  213. if (description != null) {
  214. var info = owner.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY);
  215. if (!info) {
  216. info = {};
  217. info["label"] = description;
  218. owner.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY, info);
  219. }
  220. }
  221. }
  222. });
  223. return this;
  224. },
  225. /**
  226. * Set an accessible description for each owner of SceneNode in this Selector. In JavaScript, this sets the "aria-label".
  227. * @param (com.ibm.rave.core.selector.ValueFunction) valueFunction a function which returns a description
  228. * @return (com.ibm.rave.core.selector.Selector) this {@link (com.ibm.rave.accessibility.selector.AccessibilitySelector) AccessibilitySelector}
  229. */
  230. description$2 : function(valueFunction) {
  231. this.each(function(data, index, groupIndex) {
  232. var owner = this.rave_getOwner();
  233. if (owner) {
  234. var value = valueFunction.call(owner, owner.rave_getData(), index, groupIndex);
  235. var description = value != null ? value + "" : "";
  236. com_ibm_rave_accessibility_internal_nativeImpl_AccessibleContext.setDescription(owner, description);
  237. if (description != null) {
  238. var info = owner.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY);
  239. if (!info) {
  240. info = {};
  241. info["label"] = description;
  242. owner.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY, info);
  243. }
  244. }
  245. }
  246. });
  247. return this;
  248. },
  249. /**
  250. * Get the accessible info for the first SceneNode in this Selector.
  251. * @return (Object) the accessible info of the first SceneNode in this Selector
  252. */
  253. info$0 : function() {
  254. var node = this.node();
  255. return !node ? null : node.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY);
  256. },
  257. /**
  258. * Set an accessible info for each SceneNode in this Selector.
  259. * @param (Object) info the accessible info
  260. * @return (com.ibm.rave.accessibility.selector.AccessibilitySelector) this {@link (com.ibm.rave.accessibility.selector.AccessibilitySelector) AccessibilitySelector}
  261. */
  262. info$1 : function(info) {
  263. this.each(function(data, index, groupIndex) {
  264. this.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY, info);
  265. });
  266. return this;
  267. },
  268. /**
  269. * Set an accessible info for each SceneNode in this Selector.
  270. * @param (com.ibm.rave.core.selector.ValueFunction) valueFunction a function which returns a {@link (Object) AccessibleInfo}
  271. * @return (com.ibm.rave.accessibility.selector.AccessibilitySelector) this {@link (com.ibm.rave.accessibility.selector.AccessibilitySelector) AccessibilitySelector}
  272. */
  273. info$2 : function(valueFunction) {
  274. this.each(function(data, index, groupIndex) {
  275. this.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY, valueFunction.call(this, data, index, groupIndex));
  276. });
  277. return this;
  278. },
  279. /** @expose */
  280. description : function(a0) {
  281. var args = arguments;
  282. if (args.length == 0) {
  283. return this.description$0();
  284. }
  285. if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
  286. return this.description$1(a0);
  287. }
  288. return this.description$2(a0);
  289. },
  290. /** @expose */
  291. info : function(a0) {
  292. var args = arguments;
  293. if (args.length == 0) {
  294. return this.info$0();
  295. }
  296. if (args.length == 1 && typeof a0 === "function") {
  297. return this.info$2(a0);
  298. }
  299. return this.info$1(a0);
  300. }
  301. });
  302. // $source: com/ibm/rave/accessibility/internal/nativeImpl/ShadowDOMBuilder
  303. /************************************************************************
  304. ** IBM Confidential
  305. **
  306. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  307. **
  308. ** (C) Copyright IBM Corp. 2014, 2015
  309. **
  310. ** The source code for this program is not published or otherwise divested of its trade secrets,
  311. ** irrespective of what has been deposited with the U.S. Copyright Office.
  312. ************************************************************************/
  313. // @import com/ibm/rave/core/nativeImpl/Declare
  314. // @import com/ibm/rave/accessibility/AccessibilityConstants
  315. // @import com/ibm/rave/core/internal/nativeImpl/event/Event
  316. var com_ibm_rave_accessibility_internal_nativeImpl_ShadowDOMBuilder = (function() {
  317. var shadowDomNodeKey = "__shadowDomNode__";
  318. var sceneNodeKey = "__sceneNode__";
  319. function removeShadowDomNode(domNode) {
  320. if (domNode[shadowDomNodeKey]) {
  321. delete domNode[shadowDomNodeKey][sceneNodeKey];
  322. delete domNode[shadowDomNodeKey];
  323. }
  324. var childNodes = domNode.childNodes;
  325. for (var i = 0; i < childNodes.length; i++) {
  326. removeShadowDomNode(childNodes[i]);
  327. }
  328. }
  329. function setAttributes(shadowDomNode, info) {
  330. // set the known properties
  331. shadowDomNode.setAttribute("aria-label", info["label"] || "");
  332. shadowDomNode.setAttribute("aria-hint", info["hint"] || "");
  333. shadowDomNode.setAttribute("role", info["role"] || "");
  334. // clear all custom properties
  335. for (var i = 0, nodeName, atts = shadowDomNode.attributes; i < atts.length; i++) {
  336. nodeName = atts[i].nodeName;
  337. if (nodeName.indexOf("data-") == 0) {
  338. shadowDomNode.removeAttribute(nodeName);
  339. }
  340. }
  341. // set all custom properties
  342. for (var key in info) {
  343. if (info.hasOwnProperty(key)) {
  344. switch (key) {
  345. case "label":
  346. case "hint":
  347. case "role":
  348. break;
  349. default:
  350. shadowDomNode.setAttribute("data-" + key, info[key]);
  351. }
  352. }
  353. }
  354. }
  355. function setText(shadowDomNode, info) {
  356. if (info && info["label"] && info["label"].length) {
  357. shadowDomNode.textContent = info["label"];
  358. }
  359. }
  360. function appendOrInsert(parent, child, before) {
  361. var info = child.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY);
  362. if (info) {
  363. var shadowDomNode = child.rave_getProperty(shadowDomNodeKey),
  364. ps = rave.select(parent.rave_getProperty(shadowDomNodeKey)),
  365. ul = ps.select("ul");
  366. if (!shadowDomNode) {
  367. if (ul.empty()) {
  368. ul = ps.append("ul");
  369. }
  370. shadowDomNode = rave_document.createElement("li");
  371. shadowDomNode[sceneNodeKey] = child;
  372. child.rave_setProperty(shadowDomNodeKey, shadowDomNode);
  373. setAttributes(shadowDomNode, info);
  374. setText(shadowDomNode, info);
  375. // recursively add its children
  376. if (child.rave_hasChildNodes()) {
  377. var children = child.rave_getChildNodes();
  378. for (var i = 0; i < children.length; i++) {
  379. this.onAppend(child, children[i]);
  380. }
  381. }
  382. }
  383. // get the real ul dom node
  384. ul = ul.node();
  385. if (arguments.length == 3) {
  386. ul.insertBefore(shadowDomNode, before.rave_getProperty(shadowDomNodeKey));
  387. } else {
  388. ul.appendChild(shadowDomNode);
  389. }
  390. }
  391. }
  392. return com_ibm_rave_core_nativeImpl_Declare({
  393. onAppend : appendOrInsert,
  394. onInsert : appendOrInsert,
  395. onRemove : function(parent, child, index) {
  396. var shadowDomNode = child[shadowDomNodeKey], newFocus;
  397. if (shadowDomNode == this._currentFocus) {
  398. newFocus = shadowDomNode.previousElementSibling;
  399. if (!newFocus) {
  400. newFocus = shadowDomNode.nextElementSibling;
  401. if (!newFocus) {
  402. // -> ul -> next parent
  403. newFocus = shadowDomNode.parentNode.parentNode;
  404. }
  405. }
  406. }
  407. this.tearDown(child);
  408. if (newFocus) {
  409. // select the scene node
  410. this._focusEventHandler.fireFocus(newFocus[sceneNodeKey]);
  411. }
  412. },
  413. onChange : function(domNode) {
  414. var info = domNode.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY),
  415. shadowDomNode = domNode.rave_getProperty(shadowDomNodeKey);
  416. if (!info) {
  417. // if no info remove the shadow dom node
  418. if (shadowDomNode) {
  419. this.tearDown(domNode);
  420. }
  421. } else if (!shadowDomNode) {
  422. var parentNode = domNode.parentNode;
  423. if (parentNode) {
  424. appendOrInsert(parentNode, domNode);
  425. }
  426. } else {
  427. // update attributes
  428. setAttributes(shadowDomNode, info);
  429. // cannot use #setText because text may be spread across multiple text nodes
  430. // remove all text nodes
  431. var childNodes = shadowDomNode.childNodes;
  432. for (var i = 0; i < childNodes.length; i++) {
  433. if (childNodes[i].nodeType == 3) {
  434. shadowDomNode.removeChild(childNodes[i]);
  435. }
  436. }
  437. if (info.label && info.label.length) {
  438. // add new text node
  439. shadowDomNode.insertBefore(rave_document.createTextNode(info.label), shadowDomNode.firstChild);
  440. }
  441. }
  442. },
  443. setUp : function(domNode, focusEventHandler) {
  444. this._focusEventHandler = focusEventHandler;
  445. var shadowDomNode = domNode[shadowDomNodeKey],
  446. info = domNode.rave_getProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY);
  447. if (!info) {
  448. info = {};
  449. domNode.rave_setProperty(com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY, info);
  450. }
  451. if (!shadowDomNode) {
  452. shadowDomNode = rave_document.createElement("div");
  453. shadowDomNode[sceneNodeKey] = domNode;
  454. shadowDomNode.setAttribute("class", "rave-a11y");
  455. rave.select(shadowDomNode).style({
  456. "width": 0,
  457. "height": 0,
  458. "left": -10000,
  459. "top": -10000,
  460. "position": "absolute",
  461. "overflow": "hidden"
  462. }, "important");
  463. domNode.parentNode.insertBefore(shadowDomNode, domNode);
  464. domNode[shadowDomNodeKey] = shadowDomNode;
  465. setAttributes(shadowDomNode, info);
  466. setText(shadowDomNode, info);
  467. if (domNode.rave_hasChildNodes()) {
  468. var children = domNode.rave_getChildNodes();
  469. for (var i = 0; i < children.length; i++) {
  470. this.onAppend(domNode, children[i]);
  471. }
  472. }
  473. // make the visualization focusable
  474. this._tabIndex = +domNode.getAttribute("tabindex");
  475. domNode.removeAttribute("tabindex");
  476. // set the current focus to the root shadow dom node
  477. this._currentFocus = shadowDomNode;
  478. this._currentFocus.setAttribute("tabindex", this._tabIndex);
  479. }
  480. },
  481. tearDown : function(domNode) {
  482. shadowDomNode = domNode[shadowDomNodeKey];
  483. if (shadowDomNode) {
  484. // remove from the DOM
  485. shadowDomNode.parentNode.removeChild(shadowDomNode);
  486. // remove stored data from the scene tree
  487. removeShadowDomNode(domNode);
  488. }
  489. },
  490. focus : function(domNode) {
  491. var shadowDomNode;
  492. if (domNode) {
  493. shadowDomNode = domNode[shadowDomNodeKey];
  494. }
  495. if (this._currentFocus != shadowDomNode) {
  496. var refocus = document.activeElement === this._currentFocus;
  497. if (this._currentFocus) {
  498. this._currentFocus.removeAttribute("tabindex");
  499. this._currentFocus.blur();
  500. }
  501. if (shadowDomNode) {
  502. shadowDomNode.setAttribute("tabindex", this._tabIndex);
  503. if (refocus) {
  504. shadowDomNode.focus();
  505. }
  506. }
  507. this._currentFocus = shadowDomNode;
  508. }
  509. }
  510. });
  511. })();
  512. // $source: com/ibm/rave/accessibility/internal/nativeImpl/AccessibleContext
  513. /************************************************************************
  514. ** IBM Confidential
  515. **
  516. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  517. **
  518. ** (C) Copyright IBM Corp. 2014
  519. **
  520. ** The source code for this program is not published or otherwise divested of its trade secrets,
  521. ** irrespective of what has been deposited with the U.S. Copyright Office.
  522. ************************************************************************/
  523. // Utility to setup accessible context on a scene node
  524. // @import ./ShadowDOMBuilder
  525. var com_ibm_rave_accessibility_internal_nativeImpl_AccessibleContext = {
  526. getDescription : function(node) {
  527. return node.getAttribute("aria-label");
  528. },
  529. setDescription : function(node, description) {
  530. node.setAttribute("aria-label", description);
  531. },
  532. createShadowTreeBuilder : function() {
  533. return new com_ibm_rave_accessibility_internal_nativeImpl_ShadowDOMBuilder();
  534. }
  535. };
  536. // $source: com/ibm/rave/accessibility/navigation/AccessibleNavigation
  537. /************************************************************************
  538. ** IBM Confidential
  539. **
  540. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  541. **
  542. ** (C) Copyright IBM Corp. 2015
  543. **
  544. ** The source code for this program is not published or otherwise divested of its trade secrets,
  545. ** irrespective of what has been deposited with the U.S. Copyright Office.
  546. ************************************************************************/
  547. // GENERATED
  548. //@import com/ibm/rave/core/nativeImpl/Declare (loadtime) // declare
  549. //@import com/ibm/rave/accessibility/navigation/AccessibleKeyboard (runtime) // new
  550. var com_ibm_rave_accessibility_navigation_AccessibleNavigation = com_ibm_rave_core_nativeImpl_Declare({
  551. /**
  552. * Creates a new instance of {@link (com.ibm.rave.accessibility.navigation.AccessibleKeyboard) AccessibleKeyboard} .
  553. * @return (com.ibm.rave.accessibility.navigation.AccessibleKeyboard) new instance of {@link (com.ibm.rave.accessibility.navigation.AccessibleKeyboard) AccessibleKeyboard}
  554. */
  555. /** @expose */
  556. keyboard : function() {
  557. return new com_ibm_rave_accessibility_navigation_AccessibleKeyboard();
  558. }
  559. //constructor : function() {}
  560. });
  561. /** @expose */
  562. com_ibm_rave_accessibility_navigation_AccessibleNavigation.INSTANCE = new com_ibm_rave_accessibility_navigation_AccessibleNavigation();
  563. // $source: com/ibm/rave/accessibility/Accessibility
  564. /************************************************************************
  565. ** IBM Confidential
  566. **
  567. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  568. **
  569. ** (C) Copyright IBM Corp. 2015
  570. **
  571. ** The source code for this program is not published or otherwise divested of its trade secrets,
  572. ** irrespective of what has been deposited with the U.S. Copyright Office.
  573. ************************************************************************/
  574. // GENERATED
  575. //@import com/ibm/rave/accessibility/internal/AccessibleNavigationSceneNodeExtension (static) // register
  576. //@import com/ibm/rave/accessibility/internal/AccessibilityUtil (static) // registerSelector
  577. //@import com/ibm/rave/accessibility/AccessibilityConstants (static) // AccessibilityConstants
  578. //@import com/ibm/rave/accessibility/navigation/AccessibleNavigation (static) // AccessibleNavigation
  579. /**
  580. * The accessibility layer. Provides entry points into functionality provided by the accessibility layer.
  581. */
  582. var com_ibm_rave_accessibility_Accessibility = rave_externs["Accessibility"] = {
  583. //constructor : function() {}
  584. };
  585. /**
  586. * Initialize the Accessibility feature. This needs to be called before using any accessibility features.
  587. */
  588. /** @expose */
  589. com_ibm_rave_accessibility_Accessibility.init = function() {
  590. com_ibm_rave_accessibility_internal_AccessibleNavigationSceneNodeExtension.register();
  591. com_ibm_rave_accessibility_internal_AccessibilityUtil.registerSelector();
  592. };
  593. /**
  594. * @see this.AccessibilityConstants#com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY
  595. */
  596. /** @expose */
  597. com_ibm_rave_accessibility_Accessibility.ACCESSIBLE_INFO_KEY = com_ibm_rave_accessibility_AccessibilityConstants.ACCESSIBLE_INFO_KEY;
  598. /**
  599. * @see this.AccessibilityConstants#com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY
  600. */
  601. /** @expose */
  602. com_ibm_rave_accessibility_Accessibility.SHADOW_TREE_BUILDER_KEY = com_ibm_rave_accessibility_AccessibilityConstants.SHADOW_TREE_BUILDER_KEY;
  603. /**
  604. * @see this.AccessibilityConstants#com_ibm_rave_accessibility_AccessibilityConstants.SELECTOR_ID
  605. */
  606. /** @expose */
  607. com_ibm_rave_accessibility_Accessibility.SELECTOR_ID = com_ibm_rave_accessibility_AccessibilityConstants.SELECTOR_ID;
  608. /**
  609. * @see (com.ibm.rave.accessibility.navigation.AccessibleNavigation) AccessibleNavigation
  610. */
  611. /** @expose */
  612. com_ibm_rave_accessibility_Accessibility.navigation = com_ibm_rave_accessibility_navigation_AccessibleNavigation.INSTANCE;
  613. // $source: com/ibm/rave/accessibility/internal/nativeImpl/Module
  614. /************************************************************************
  615. ** IBM Confidential
  616. **
  617. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  618. **
  619. ** (C) Copyright IBM Corp. 2014
  620. **
  621. ** The source code for this program is not published or otherwise divested of its trade secrets,
  622. ** irrespective of what has been deposited with the U.S. Copyright Office.
  623. ************************************************************************/
  624. // @OnDemandLoad("rave-accessibility")
  625. // Must be the first import
  626. // @import ./ModuleHeader
  627. // Other module dependencies
  628. // @import com/ibm/rave/navigation/internal/nativeImpl/Module
  629. // @import com/ibm/rave/accessibility/Accessibility
  630. com_ibm_rave_accessibility_Accessibility.init();
  631. // expose a11y class to the global variable rave
  632. rave["accessibility"] = com_ibm_rave_accessibility_Accessibility;
  633. // $source: com/ibm/rave/accessibility/navigation/AccessibleKeyboard
  634. /************************************************************************
  635. ** IBM Confidential
  636. **
  637. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  638. **
  639. ** (C) Copyright IBM Corp. 2015
  640. **
  641. ** The source code for this program is not published or otherwise divested of its trade secrets,
  642. ** irrespective of what has been deposited with the U.S. Copyright Office.
  643. ************************************************************************/
  644. // GENERATED
  645. //@import com/ibm/rave/core/nativeImpl/Declare (loadtime) // declare
  646. //@import com/ibm/rave/navigation/Navigation (runtime) // keybinding
  647. //@import com/ibm/rave/core/Rave (runtime) // select, Rave
  648. //@import com/ibm/rave/accessibility/internal/nativeImpl/AccessibleContext (runtime) // createShadowTreeBuilder
  649. //@import com/ibm/rave/navigation/focus/FocusController (runtime) // nextFocusableNode, nextLevelFocusableNode, previousFocusableNodeFromEnd, previousLevelFocusableNode, nextFocusableNodeFromStart, previousFocusableNode
  650. //@import com/ibm/rave/accessibility/internal/AccessibilityUtil (runtime) // getShadowTreeBuilder, recursiveSetShadowTreeBuilder, hasAccessibleInfo
  651. var com_ibm_rave_accessibility_navigation_AccessibleKeyboard = rave_externs["AccessibleKeyboard"] = com_ibm_rave_core_nativeImpl_Declare({
  652. //kb : null,
  653. //eventHandler : null,
  654. //treeBuilder : null,
  655. //next : null,
  656. //previous : null,
  657. //nextStep : null,
  658. //previousStep : null,
  659. //first : null,
  660. //last : null,
  661. //nextLevel : null,
  662. //previousLevel : null,
  663. _$functionClassMethod : function() {
  664. var _$self = function(args) {
  665. if (args !== null || arguments.length > 1){
  666. args = Array.prototype.slice.call(arguments, 0);
  667. }
  668. {
  669. _$self.bind(args[0]);
  670. return null;
  671. }
  672. };
  673. return _$self;
  674. },
  675. constructor : function() {
  676. this.kb = com_ibm_rave_navigation_Navigation.keybinding();
  677. this.eventHandler = com_ibm_rave_core_Rave.behavior.focusEventHandler();
  678. this.treeBuilder = function(data, index, groupIndex) {
  679. return com_ibm_rave_accessibility_internal_nativeImpl_AccessibleContext.createShadowTreeBuilder();
  680. };
  681. {
  682. var self = this;
  683. this.next = function(args) {
  684. if (args !== null || arguments.length > 1){
  685. args = Array.prototype.slice.call(arguments, 0);
  686. }
  687. {
  688. var focused = self.eventHandler.focusedNode;
  689. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  690. var nextSibling = focused;
  691. while ((nextSibling = com_ibm_rave_navigation_focus_FocusController.nextFocusableNode(nextSibling))) {
  692. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(nextSibling)) {
  693. self.eventHandler.fireFocus(nextSibling);
  694. break;
  695. }
  696. }
  697. }
  698. rave.event.preventDefault();
  699. return null;
  700. }
  701. };
  702. this.previous = function(args) {
  703. if (args !== null || arguments.length > 1){
  704. args = Array.prototype.slice.call(arguments, 0);
  705. }
  706. {
  707. var focused = self.eventHandler.focusedNode;
  708. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  709. var previousSibling = focused;
  710. while ((previousSibling = com_ibm_rave_navigation_focus_FocusController.previousFocusableNode(previousSibling))) {
  711. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(previousSibling)) {
  712. self.eventHandler.fireFocus(previousSibling);
  713. break;
  714. }
  715. }
  716. }
  717. rave.event.preventDefault();
  718. return null;
  719. }
  720. };
  721. this.nextStep = function(args) {
  722. if (args !== null || arguments.length > 1){
  723. args = Array.prototype.slice.call(arguments, 0);
  724. }
  725. {
  726. var focused = self.eventHandler.focusedNode;
  727. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  728. var stepCount = 0;
  729. var nextSibling = focused, temp = focused;
  730. while (stepCount < 20 && temp) {
  731. temp = com_ibm_rave_navigation_focus_FocusController.nextFocusableNode(temp);
  732. if (temp) {
  733. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(temp)) {
  734. nextSibling = temp;
  735. stepCount++;
  736. }
  737. }
  738. }
  739. if (nextSibling != focused) {
  740. self.eventHandler.fireFocus(nextSibling);
  741. }
  742. }
  743. rave.event.preventDefault();
  744. return null;
  745. }
  746. };
  747. this.previousStep = function(args) {
  748. if (args !== null || arguments.length > 1){
  749. args = Array.prototype.slice.call(arguments, 0);
  750. }
  751. {
  752. var focused = self.eventHandler.focusedNode;
  753. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  754. var stepCount = 0;
  755. var previousSibling = focused, temp = focused;
  756. while (stepCount < 20 && temp) {
  757. temp = com_ibm_rave_navigation_focus_FocusController.previousFocusableNode(temp);
  758. if (temp) {
  759. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(temp)) {
  760. previousSibling = temp;
  761. stepCount++;
  762. }
  763. }
  764. }
  765. if (previousSibling != focused) {
  766. self.eventHandler.fireFocus(previousSibling);
  767. }
  768. }
  769. rave.event.preventDefault();
  770. return null;
  771. }
  772. };
  773. this.first = function(args) {
  774. if (args !== null || arguments.length > 1){
  775. args = Array.prototype.slice.call(arguments, 0);
  776. }
  777. {
  778. var focused = self.eventHandler.focusedNode;
  779. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  780. var firstNode = com_ibm_rave_navigation_focus_FocusController.nextFocusableNodeFromStart(focused);
  781. if (!(com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(firstNode))) {
  782. while ((firstNode = com_ibm_rave_navigation_focus_FocusController.nextFocusableNode(firstNode))) {
  783. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(firstNode)) {
  784. break;
  785. }
  786. }
  787. }
  788. if (firstNode && focused != firstNode) {
  789. self.eventHandler.fireFocus(firstNode);
  790. }
  791. }
  792. rave.event.preventDefault();
  793. return null;
  794. }
  795. };
  796. this.last = function(args) {
  797. if (args !== null || arguments.length > 1){
  798. args = Array.prototype.slice.call(arguments, 0);
  799. }
  800. {
  801. var focused = self.eventHandler.focusedNode;
  802. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  803. var lastNode = com_ibm_rave_navigation_focus_FocusController.previousFocusableNodeFromEnd(focused);
  804. if (!(com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(lastNode))) {
  805. while ((lastNode = com_ibm_rave_navigation_focus_FocusController.previousFocusableNode(lastNode))) {
  806. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(lastNode)) {
  807. break;
  808. }
  809. }
  810. }
  811. if (lastNode && focused != lastNode) {
  812. self.eventHandler.fireFocus(lastNode);
  813. }
  814. }
  815. rave.event.preventDefault();
  816. return null;
  817. }
  818. };
  819. this.nextLevel = function(args) {
  820. if (args !== null || arguments.length > 1){
  821. args = Array.prototype.slice.call(arguments, 0);
  822. }
  823. {
  824. var focused = self.eventHandler.focusedNode;
  825. if (focused) {
  826. if (focused.rave_hasChildNodes()) {
  827. var child = com_ibm_rave_navigation_focus_FocusController.nextLevelFocusableNode(focused);
  828. if (!(com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(child))) {
  829. while ((child = com_ibm_rave_navigation_focus_FocusController.nextFocusableNode(child))) {
  830. if (com_ibm_rave_accessibility_internal_AccessibilityUtil.hasAccessibleInfo(child)) {
  831. break;
  832. }
  833. }
  834. }
  835. if (child) {
  836. self.eventHandler.fireFocus(child);
  837. }
  838. }
  839. }
  840. rave.event.preventDefault();
  841. return null;
  842. }
  843. };
  844. this.previousLevel = function(args) {
  845. if (args !== null || arguments.length > 1){
  846. args = Array.prototype.slice.call(arguments, 0);
  847. }
  848. {
  849. var focused = self.eventHandler.focusedNode;
  850. if (focused && !(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot(focused))) {
  851. var parent = com_ibm_rave_navigation_focus_FocusController.previousLevelFocusableNode(focused);
  852. if (parent) {
  853. self.eventHandler.fireFocus(parent);
  854. }
  855. }
  856. rave.event.preventDefault();
  857. return null;
  858. }
  859. };
  860. }
  861. {
  862. this.kb.on(40, this.next).on(38, this.previous).on(34, this.nextStep).on(33, this.previousStep).on(36, this.first).on(35, this.last).on(39, this.nextLevel).on(37, this.previousLevel);
  863. }
  864. },
  865. /** @expose */
  866. bind : function(g) {
  867. var self = this;
  868. g.each(function(data, index, groupIndex) {
  869. var s = com_ibm_rave_core_Rave.select(this);
  870. var stb = self.treeBuilder.call(this, data, index, groupIndex);
  871. com_ibm_rave_accessibility_internal_AccessibilityUtil.recursiveSetShadowTreeBuilder(this, stb);
  872. com_ibm_rave_core_Rave.configuration.extendRecursive(this);
  873. stb.setUp(this, self.eventHandler);
  874. s.on("ravefocus", com_ibm_rave_accessibility_navigation_AccessibleKeyboard.FOCUS_LISTENER);
  875. com_ibm_rave_core_Rave.select(this.rave_getOwner()).call(self.kb);
  876. s.property(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.NATIVATION_ROOT, true);
  877. self.eventHandler.focusedNode = this;
  878. });
  879. },
  880. shadowTreeBuilder$0 : function() {
  881. return this.treeBuilder;
  882. },
  883. shadowTreeBuilder$1 : function(shadowTreeBuilder) {
  884. this.treeBuilder = shadowTreeBuilder;
  885. return this;
  886. },
  887. /** @expose */
  888. keyBinding : function() {
  889. return this.kb;
  890. },
  891. focusEventHandler$0 : function() {
  892. return this.eventHandler;
  893. },
  894. focusEventHandler$1 : function(handler) {
  895. this.eventHandler = handler;
  896. return this;
  897. },
  898. /** @expose */
  899. shadowTreeBuilder : function(a0) {
  900. var args = arguments;
  901. if (args.length == 0) {
  902. return this.shadowTreeBuilder$0();
  903. }
  904. return this.shadowTreeBuilder$1(a0);
  905. },
  906. /** @expose */
  907. focusEventHandler : function(a0) {
  908. var args = arguments;
  909. if (args.length == 0) {
  910. return this.focusEventHandler$0();
  911. }
  912. return this.focusEventHandler$1(a0);
  913. }
  914. });
  915. com_ibm_rave_accessibility_navigation_AccessibleKeyboard.isNavigationRoot = function(item) {
  916. return item.rave_getProperty(com_ibm_rave_accessibility_navigation_AccessibleKeyboard.NATIVATION_ROOT) != null;
  917. };
  918. com_ibm_rave_accessibility_navigation_AccessibleKeyboard.NATIVATION_ROOT = "__rave-kbnav-root__";
  919. com_ibm_rave_accessibility_navigation_AccessibleKeyboard.STEP = 20;
  920. com_ibm_rave_accessibility_navigation_AccessibleKeyboard.FOCUS_LISTENER = function(data, index, groupIndex, event) {
  921. var stb = com_ibm_rave_accessibility_internal_AccessibilityUtil.getShadowTreeBuilder(event.target);
  922. if (event.target) {
  923. stb.focus(event.target);
  924. } else {
  925. stb.focus(null);
  926. }
  927. };
  928. })();