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.

813 lines
22 KiB

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