Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

823 lines
23 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. (function(){
  16. Ext.ns('Ext.a11y');
  17. Ext.a11y.Frame = Ext.extend(Object, {
  18. initialized: false,
  19. constructor: function(size, color){
  20. this.setSize(size || 1);
  21. this.setColor(color || '15428B');
  22. },
  23. init: function(){
  24. if (!this.initialized) {
  25. this.sides = [];
  26. var s, i;
  27. this.ct = Ext.DomHelper.append(document.body, {
  28. cls: 'x-a11y-focusframe'
  29. }, true);
  30. for (i = 0; i < 4; i++) {
  31. s = Ext.DomHelper.append(this.ct, {
  32. cls: 'x-a11y-focusframe-side',
  33. style: 'background-color: #' + this.color
  34. }, true);
  35. s.visibilityMode = Ext.Element.DISPLAY;
  36. this.sides.push(s);
  37. }
  38. this.frameTask = new Ext.util.DelayedTask(function(el){
  39. var newEl = Ext.get(el);
  40. if (newEl != this.curEl) {
  41. var w = newEl.getWidth();
  42. var h = newEl.getHeight();
  43. this.sides[0].show().setSize(w, this.size).anchorTo(el, 'tl', [0, -1]);
  44. this.sides[2].show().setSize(w, this.size).anchorTo(el, 'bl', [0, -1]);
  45. this.sides[1].show().setSize(this.size, h).anchorTo(el, 'tr', [-1, 0]);
  46. this.sides[3].show().setSize(this.size, h).anchorTo(el, 'tl', [-1, 0]);
  47. this.curEl = newEl;
  48. }
  49. }, this);
  50. this.unframeTask = new Ext.util.DelayedTask(function(){
  51. if (this.initialized) {
  52. this.sides[0].hide();
  53. this.sides[1].hide();
  54. this.sides[2].hide();
  55. this.sides[3].hide();
  56. this.curEl = null;
  57. }
  58. }, this);
  59. this.initialized = true;
  60. }
  61. },
  62. frame: function(el){
  63. this.init();
  64. this.unframeTask.cancel();
  65. this.frameTask.delay(2, false, false, [el]);
  66. },
  67. unframe: function(){
  68. this.init();
  69. this.unframeTask.delay(2);
  70. },
  71. setSize: function(size){
  72. this.size = size;
  73. },
  74. setColor: function(color){
  75. this.color = color;
  76. }
  77. });
  78. Ext.a11y.FocusFrame = new Ext.a11y.Frame(2, '15428B');
  79. Ext.a11y.RelayFrame = new Ext.a11y.Frame(1, '6B8CBF');
  80. Ext.a11y.Focusable = Ext.extend(Ext.util.Observable, {
  81. constructor: function(el, relayTo, noFrame, frameEl){
  82. Ext.a11y.Focusable.superclass.constructor.call(this);
  83. this.addEvents('focus', 'blur', 'left', 'right', 'up', 'down', 'esc', 'enter', 'space');
  84. if (el instanceof Ext.Component) {
  85. this.el = el.el;
  86. this.setComponent(el);
  87. }
  88. else {
  89. this.el = Ext.get(el);
  90. this.setComponent(null);
  91. }
  92. this.setRelayTo(relayTo)
  93. this.setNoFrame(noFrame);
  94. this.setFrameEl(frameEl);
  95. this.init();
  96. Ext.a11y.FocusMgr.register(this);
  97. },
  98. init: function(){
  99. this.el.dom.tabIndex = '1';
  100. this.el.addClass('x-a11y-focusable');
  101. this.el.on({
  102. focus: this.onFocus,
  103. blur: this.onBlur,
  104. keydown: this.onKeyDown,
  105. scope: this
  106. });
  107. },
  108. setRelayTo: function(relayTo){
  109. this.relayTo = relayTo ? Ext.a11y.FocusMgr.get(relayTo) : null;
  110. },
  111. setNoFrame: function(noFrame){
  112. this.noFrame = (noFrame === true) ? true : false;
  113. },
  114. setFrameEl: function(frameEl){
  115. this.frameEl = frameEl && Ext.get(frameEl) || this.el;
  116. },
  117. setComponent: function(cmp){
  118. this.component = cmp || null;
  119. },
  120. onKeyDown: function(e, t){
  121. var k = e.getKey(), SK = Ext.a11y.Focusable.SpecialKeys, ret, tf;
  122. tf = (t !== this.el.dom) ? Ext.a11y.FocusMgr.get(t, true) : this;
  123. if (!tf) {
  124. // this can happen when you are on a focused item within a panel body
  125. // that is not a Ext.a11y.Focusable
  126. tf = Ext.a11y.FocusMgr.get(Ext.fly(t).parent('.x-a11y-focusable'));
  127. }
  128. if (SK[k] !== undefined) {
  129. ret = this.fireEvent(SK[k], e, t, tf, this);
  130. }
  131. if (ret === false || this.fireEvent('keydown', e, t, tf, this) === false) {
  132. e.stopEvent();
  133. }
  134. },
  135. focus: function(){
  136. this.el.dom.focus();
  137. },
  138. blur: function(){
  139. this.el.dom.blur();
  140. },
  141. onFocus: function(e, t){
  142. this.el.addClass('x-a11y-focused');
  143. if (this.relayTo) {
  144. this.relayTo.el.addClass('x-a11y-focused-relay');
  145. if (!this.relayTo.noFrame) {
  146. Ext.a11y.FocusFrame.frame(this.relayTo.frameEl);
  147. }
  148. if (!this.noFrame) {
  149. Ext.a11y.RelayFrame.frame(this.frameEl);
  150. }
  151. }
  152. else {
  153. if (!this.noFrame) {
  154. Ext.a11y.FocusFrame.frame(this.frameEl);
  155. }
  156. }
  157. this.fireEvent('focus', e, t, this);
  158. },
  159. onBlur: function(e, t){
  160. if (this.relayTo) {
  161. this.relayTo.el.removeClass('x-a11y-focused-relay');
  162. Ext.a11y.RelayFrame.unframe();
  163. }
  164. this.el.removeClass('x-a11y-focused');
  165. Ext.a11y.FocusFrame.unframe();
  166. this.fireEvent('blur', e, t, this);
  167. },
  168. destroy: function(){
  169. this.el.un('keydown', this.onKeyDown);
  170. this.el.un('focus', this.onFocus);
  171. this.el.un('blur', this.onBlur);
  172. this.el.removeClass('x-a11y-focusable');
  173. this.el.removeClass('x-a11y-focused');
  174. if (this.relayTo) {
  175. this.relayTo.el.removeClass('x-a11y-focused-relay');
  176. }
  177. }
  178. });
  179. Ext.a11y.FocusItem = Ext.extend(Object, {
  180. constructor: function(el, enableTabbing){
  181. Ext.a11y.FocusItem.superclass.constructor.call(this);
  182. this.el = Ext.get(el);
  183. this.fi = new Ext.a11y.Focusable(el);
  184. this.fi.setComponent(this);
  185. this.fi.on('tab', this.onTab, this);
  186. this.enableTabbing = enableTabbing === true ? true : false;
  187. },
  188. getEnterItem: function(){
  189. if (this.enableTabbing) {
  190. var items = this.getFocusItems();
  191. if (items && items.length) {
  192. return items[0];
  193. }
  194. }
  195. },
  196. getFocusItems: function(){
  197. if (this.enableTabbing) {
  198. return this.el.query('a, button, input, select');
  199. }
  200. return null;
  201. },
  202. onTab: function(e, t){
  203. var items = this.getFocusItems(), i;
  204. if (items && items.length && (i = items.indexOf(t)) !== -1) {
  205. if (e.shiftKey && i > 0) {
  206. e.stopEvent();
  207. items[i - 1].focus();
  208. Ext.a11y.FocusFrame.frame.defer(20, Ext.a11y.FocusFrame, [this.el]);
  209. return;
  210. }
  211. else
  212. if (!e.shiftKey && i < items.length - 1) {
  213. e.stopEvent();
  214. items[i + 1].focus();
  215. Ext.a11y.FocusFrame.frame.defer(20, Ext.a11y.FocusFrame, [this.el]);
  216. return;
  217. }
  218. }
  219. },
  220. focus: function(){
  221. if (this.enableTabbing) {
  222. var items = this.getFocusItems();
  223. if (items && items.length) {
  224. items[0].focus();
  225. Ext.a11y.FocusFrame.frame.defer(20, Ext.a11y.FocusFrame, [this.el]);
  226. return;
  227. }
  228. }
  229. this.fi.focus();
  230. },
  231. blur: function(){
  232. this.fi.blur();
  233. }
  234. });
  235. Ext.a11y.FocusMgr = function(){
  236. var all = new Ext.util.MixedCollection();
  237. return {
  238. register: function(f){
  239. all.add(f.el && Ext.id(f.el), f);
  240. },
  241. unregister: function(f){
  242. all.remove(f);
  243. },
  244. get: function(el, noCreate){
  245. return all.get(Ext.id(el)) || (noCreate ? false : new Ext.a11y.Focusable(el));
  246. },
  247. all: all
  248. }
  249. }();
  250. Ext.a11y.Focusable.SpecialKeys = {};
  251. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.LEFT] = 'left';
  252. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.RIGHT] = 'right';
  253. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.DOWN] = 'down';
  254. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.UP] = 'up';
  255. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.ESC] = 'esc';
  256. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.ENTER] = 'enter';
  257. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.SPACE] = 'space';
  258. Ext.a11y.Focusable.SpecialKeys[Ext.EventObjectImpl.prototype.TAB] = 'tab';
  259. // we use the new observeClass method to fire our new initFocus method on components
  260. Ext.util.Observable.observeClass(Ext.Component);
  261. Ext.Component.on('render', function(cmp){
  262. cmp.initFocus();
  263. cmp.initARIA();
  264. });
  265. Ext.override(Ext.Component, {
  266. initFocus: Ext.emptyFn,
  267. initARIA: Ext.emptyFn
  268. });
  269. Ext.override(Ext.Container, {
  270. isFocusable: true,
  271. noFocus: false,
  272. // private
  273. initFocus: function(){
  274. if (!this.fi && !this.noFocus) {
  275. this.fi = new Ext.a11y.Focusable(this);
  276. }
  277. this.mon(this.fi, {
  278. focus: this.onFocus,
  279. blur: this.onBlur,
  280. tab: this.onTab,
  281. enter: this.onEnter,
  282. esc: this.onEsc,
  283. scope: this
  284. });
  285. if (this.hidden) {
  286. this.isFocusable = false;
  287. }
  288. this.on('show', function(){
  289. this.isFocusable = true;
  290. }, this);
  291. this.on('hide', function(){
  292. this.isFocusable = false;
  293. }, this);
  294. },
  295. focus: function(){
  296. this.fi.focus();
  297. },
  298. blur: function(){
  299. this.fi.blur();
  300. },
  301. enter: function(){
  302. var eitem = this.getEnterItem();
  303. if (eitem) {
  304. eitem.focus();
  305. }
  306. },
  307. onFocus: Ext.emptyFn,
  308. onBlur: Ext.emptyFn,
  309. onTab: function(e, t, tf){
  310. var rf = tf.relayTo || tf;
  311. if (rf.component && rf.component !== this) {
  312. e.stopEvent();
  313. var item = e.shiftKey ? this.getPreviousFocus(rf.component) : this.getNextFocus(rf.component);
  314. item.focus();
  315. }
  316. },
  317. onEnter: function(e, t, tf){
  318. // check to see if enter is pressed while "on" the panel
  319. if (tf.component && tf.component === this) {
  320. e.stopEvent();
  321. this.enter();
  322. }
  323. e.stopPropagation();
  324. },
  325. onEsc: function(e, t){
  326. e.preventDefault();
  327. // check to see if esc is pressed while "inside" the panel
  328. // or while "on" the panel
  329. if (t === this.el.dom) {
  330. // "on" the panel, check if this panel has an owner panel and focus that
  331. // we dont stop the event in this case so that this same check will be
  332. // done for this ownerCt
  333. if (this.ownerCt) {
  334. this.ownerCt.focus();
  335. }
  336. }
  337. else {
  338. // we were inside the panel when esc was pressed,
  339. // so go back "on" the panel
  340. if (this.ownerCt && this.ownerCt.isFocusable) {
  341. var si = this.ownerCt.getFocusItems();
  342. if (si && si.getCount() > 1) {
  343. e.stopEvent();
  344. }
  345. }
  346. this.focus();
  347. }
  348. },
  349. getFocusItems: function(){
  350. return this.items &&
  351. this.items.filterBy(function(o){
  352. return o.isFocusable;
  353. }) ||
  354. null;
  355. },
  356. getEnterItem: function(){
  357. var ci = this.getFocusItems(), length = ci ? ci.getCount() : 0;
  358. if (length === 1) {
  359. return ci.first().getEnterItem && ci.first().getEnterItem() || ci.first();
  360. }
  361. else if (length > 1) {
  362. return ci.first();
  363. }
  364. },
  365. getNextFocus: function(current){
  366. var items = this.getFocusItems(), next = current, i = items.indexOf(current), length = items.getCount();
  367. if (i === length - 1) {
  368. next = items.first();
  369. }
  370. else {
  371. next = items.get(i + 1);
  372. }
  373. return next;
  374. },
  375. getPreviousFocus: function(current){
  376. var items = this.getFocusItems(), prev = current, i = items.indexOf(current), length = items.getCount();
  377. if (i === 0) {
  378. prev = items.last();
  379. }
  380. else {
  381. prev = items.get(i - 1);
  382. }
  383. return prev;
  384. },
  385. getFocusable : function() {
  386. return this.fi;
  387. }
  388. });
  389. Ext.override(Ext.Panel, {
  390. <div id="cfg-Ext.ux.DataViewTransition-enableTabbing"></div>/**
  391. * @cfg {Boolean} enableTabbing <tt>true</tt> to enable tabbing. Default is <tt>false</tt>.
  392. */
  393. getFocusItems: function(){
  394. // items gets all the items inside the body
  395. var items = Ext.Panel.superclass.getFocusItems.call(this), bodyFocus = null;
  396. if (!items) {
  397. items = new Ext.util.MixedCollection();
  398. this.bodyFocus = this.bodyFocus || new Ext.a11y.FocusItem(this.body, this.enableTabbing);
  399. items.add('body', this.bodyFocus);
  400. }
  401. // but panels can also have tbar, bbar, fbar
  402. if (this.tbar && this.topToolbar) {
  403. items.insert(0, this.topToolbar);
  404. }
  405. if (this.bbar && this.bottomToolbar) {
  406. items.add(this.bottomToolbar);
  407. }
  408. if (this.fbar) {
  409. items.add(this.fbar);
  410. }
  411. return items;
  412. }
  413. });
  414. Ext.override(Ext.TabPanel, {
  415. // private
  416. initFocus: function(){
  417. Ext.TabPanel.superclass.initFocus.call(this);
  418. this.mon(this.fi, {
  419. left: this.onLeft,
  420. right: this.onRight,
  421. scope: this
  422. });
  423. },
  424. onLeft: function(e){
  425. if (!this.activeTab) {
  426. return;
  427. }
  428. e.stopEvent();
  429. var prev = this.items.itemAt(this.items.indexOf(this.activeTab) - 1);
  430. if (prev) {
  431. this.setActiveTab(prev);
  432. }
  433. return false;
  434. },
  435. onRight: function(e){
  436. if (!this.activeTab) {
  437. return;
  438. }
  439. e.stopEvent();
  440. var next = this.items.itemAt(this.items.indexOf(this.activeTab) + 1);
  441. if (next) {
  442. this.setActiveTab(next);
  443. }
  444. return false;
  445. }
  446. });
  447. Ext.override(Ext.tree.TreeNodeUI, {
  448. // private
  449. focus: function(){
  450. this.node.getOwnerTree().bodyFocus.focus();
  451. }
  452. });
  453. Ext.override(Ext.tree.TreePanel, {
  454. // private
  455. afterRender : function(){
  456. Ext.tree.TreePanel.superclass.afterRender.call(this);
  457. this.root.render();
  458. if(!this.rootVisible){
  459. this.root.renderChildren();
  460. }
  461. this.bodyFocus = new Ext.a11y.FocusItem(this.body.down('.x-tree-root-ct'));
  462. this.bodyFocus.fi.setFrameEl(this.body);
  463. }
  464. });
  465. Ext.override(Ext.grid.GridPanel, {
  466. initFocus: function(){
  467. Ext.grid.GridPanel.superclass.initFocus.call(this);
  468. this.bodyFocus = new Ext.a11y.FocusItem(this.view.focusEl);
  469. this.bodyFocus.fi.setFrameEl(this.body);
  470. }
  471. });
  472. Ext.override(Ext.Button, {
  473. isFocusable: true,
  474. noFocus: false,
  475. initFocus: function(){
  476. Ext.Button.superclass.initFocus.call(this);
  477. this.fi = this.fi || new Ext.a11y.Focusable(this.btnEl, null, null, this.el);
  478. this.fi.setComponent(this);
  479. this.mon(this.fi, {
  480. focus: this.onFocus,
  481. blur: this.onBlur,
  482. scope: this
  483. });
  484. if (this.menu) {
  485. this.mon(this.fi, 'down', this.showMenu, this);
  486. this.on('menuhide', this.focus, this);
  487. }
  488. if (this.hidden) {
  489. this.isFocusable = false;
  490. }
  491. this.on('show', function(){
  492. this.isFocusable = true;
  493. }, this);
  494. this.on('hide', function(){
  495. this.isFocusable = false;
  496. }, this);
  497. },
  498. focus: function(){
  499. this.fi.focus();
  500. },
  501. blur: function(){
  502. this.fi.blur();
  503. },
  504. onFocus: function(){
  505. if (!this.disabled) {
  506. this.el.addClass("x-btn-focus");
  507. }
  508. },
  509. onBlur: function(){
  510. this.el.removeClass("x-btn-focus");
  511. }
  512. });
  513. Ext.override(Ext.Toolbar, {
  514. initFocus: function(){
  515. Ext.Toolbar.superclass.initFocus.call(this);
  516. this.mon(this.fi, {
  517. left: this.onLeft,
  518. right: this.onRight,
  519. scope: this
  520. });
  521. this.on('focus', this.onButtonFocus, this, {
  522. stopEvent: true
  523. });
  524. },
  525. add: function(){
  526. var item = Ext.Toolbar.superclass.add.apply(this, arguments);
  527. if(!item || !item.events) {
  528. return item;
  529. }
  530. if (item.rendered && item.fi !== undefined) {
  531. item.fi.setRelayTo(this.el);
  532. this.relayEvents(item.fi, ['focus']);
  533. }
  534. else {
  535. item.on('render', function(){
  536. if (item.fi !== undefined) {
  537. item.fi.setRelayTo(this.el);
  538. this.relayEvents(item.fi, ['focus']);
  539. }
  540. }, this, {
  541. single: true
  542. });
  543. }
  544. return item;
  545. },
  546. onFocus: function(){
  547. var items = this.getFocusItems();
  548. if (items && items.getCount() > 0) {
  549. if (this.lastFocus && items.indexOf(this.lastFocus) !== -1) {
  550. this.lastFocus.focus();
  551. }
  552. else {
  553. items.first().focus();
  554. }
  555. }
  556. },
  557. onButtonFocus: function(e, t, tf){
  558. this.lastFocus = tf.component || null;
  559. },
  560. onLeft: function(e, t, tf){
  561. e.stopEvent();
  562. this.getPreviousFocus(tf.component).focus();
  563. },
  564. onRight: function(e, t, tf){
  565. e.stopEvent();
  566. this.getNextFocus(tf.component).focus();
  567. },
  568. getEnterItem: Ext.emptyFn,
  569. onTab: Ext.emptyFn,
  570. onEsc: Ext.emptyFn
  571. });
  572. Ext.override(Ext.menu.BaseItem, {
  573. initFocus: function(){
  574. this.fi = new Ext.a11y.Focusable(this, this.parentMenu && this.parentMenu.el || null, true);
  575. }
  576. });
  577. Ext.override(Ext.menu.Menu, {
  578. initFocus: function(){
  579. this.fi = new Ext.a11y.Focusable(this);
  580. this.focusEl = this.fi;
  581. }
  582. });
  583. Ext.a11y.WindowMgr = new Ext.WindowGroup();
  584. Ext.apply(Ext.WindowMgr, {
  585. bringToFront: function(win){
  586. Ext.a11y.WindowMgr.bringToFront.call(this, win);
  587. if (win.modal) {
  588. win.enter();
  589. }
  590. else {
  591. win.focus();
  592. }
  593. }
  594. });
  595. Ext.override(Ext.Window, {
  596. initFocus: function(){
  597. Ext.Window.superclass.initFocus.call(this);
  598. this.on('beforehide', function(){
  599. Ext.a11y.RelayFrame.unframe();
  600. Ext.a11y.FocusFrame.unframe();
  601. });
  602. }
  603. });
  604. Ext.override(Ext.form.Field, {
  605. isFocusable: true,
  606. noFocus: false,
  607. initFocus: function(){
  608. this.fi = this.fi || new Ext.a11y.Focusable(this, null, true);
  609. Ext.form.Field.superclass.initFocus.call(this);
  610. if (this.hidden) {
  611. this.isFocusable = false;
  612. }
  613. this.on('show', function(){
  614. this.isFocusable = true;
  615. }, this);
  616. this.on('hide', function(){
  617. this.isFocusable = false;
  618. }, this);
  619. }
  620. });
  621. Ext.override(Ext.FormPanel, {
  622. initFocus: function(){
  623. Ext.FormPanel.superclass.initFocus.call(this);
  624. this.on('focus', this.onFieldFocus, this, {
  625. stopEvent: true
  626. });
  627. },
  628. // private
  629. createForm: function(){
  630. delete this.initialConfig.listeners;
  631. var form = new Ext.form.BasicForm(null, this.initialConfig);
  632. form.afterMethod('add', this.formItemAdd, this);
  633. return form;
  634. },
  635. formItemAdd: function(item){
  636. item.on('render', function(field){
  637. field.fi.setRelayTo(this.el);
  638. this.relayEvents(field.fi, ['focus']);
  639. }, this, {
  640. single: true
  641. });
  642. },
  643. onFocus: function(){
  644. var items = this.getFocusItems();
  645. if (items && items.getCount() > 0) {
  646. if (this.lastFocus && items.indexOf(this.lastFocus) !== -1) {
  647. this.lastFocus.focus();
  648. }
  649. else {
  650. items.first().focus();
  651. }
  652. }
  653. },
  654. onFieldFocus: function(e, t, tf){
  655. this.lastFocus = tf.component || null;
  656. },
  657. onTab: function(e, t, tf){
  658. if (tf.relayTo.component === this) {
  659. var item = e.shiftKey ? this.getPreviousFocus(tf.component) : this.getNextFocus(tf.component);
  660. if (item) {
  661. ev.stopEvent();
  662. item.focus();
  663. return;
  664. }
  665. }
  666. Ext.FormPanel.superclass.onTab.apply(this, arguments);
  667. },
  668. getNextFocus: function(current){
  669. var items = this.getFocusItems(), i = items.indexOf(current), length = items.getCount();
  670. return (i < length - 1) ? items.get(i + 1) : false;
  671. },
  672. getPreviousFocus: function(current){
  673. var items = this.getFocusItems(), i = items.indexOf(current), length = items.getCount();
  674. return (i > 0) ? items.get(i - 1) : false;
  675. }
  676. });
  677. Ext.override(Ext.Viewport, {
  678. initFocus: function(){
  679. Ext.Viewport.superclass.initFocus.apply(this);
  680. this.mon(Ext.get(document), 'focus', this.focus, this);
  681. this.mon(Ext.get(document), 'blur', this.blur, this);
  682. this.fi.setNoFrame(true);
  683. },
  684. onTab: function(e, t, tf, f){
  685. e.stopEvent();
  686. if (tf === f) {
  687. items = this.getFocusItems();
  688. if (items && items.getCount() > 0) {
  689. items.first().focus();
  690. }
  691. }
  692. else {
  693. var rf = tf.relayTo || tf;
  694. var item = e.shiftKey ? this.getPreviousFocus(rf.component) : this.getNextFocus(rf.component);
  695. item.focus();
  696. }
  697. }
  698. });
  699. })();</pre>
  700. </body>
  701. </html>