8 constructor: function(size, activeCls){
10 this.activeCls = activeCls;
16 var tpl = Ext.create('Ext.XTemplate',
18 '<div class="square">{.}</div>',
19 '<tpl if="xindex % ' + this.size + ' === 0"><div class="x-clear"></div></tpl>',
23 max = this.size * this.size;
25 for (; i < max; ++i) {
29 this.cells = el.select('.square');
32 getIndex: function(xy){
33 return this.size * xy[0] + xy[1];
36 constrain: function(x, y) {
37 x = Ext.Number.constrain(x, 0, this.size - 1);
38 y = Ext.Number.constrain(y, 0, this.size - 1);
42 setActive: function(x, y) {
43 var xy = this.constrain(x, y),
44 cell = this.cells.item(this.getIndex(xy));
46 cell.radioCls(this.activeCls);
50 setActiveCls: function(activeCls){
51 this.cells.removeCls(this.activeCls);
52 this.activeCls = activeCls;
53 var active = this.active;
54 this.setActive(active[0], active[1]);
57 highlightActive: function(){
58 var cell = this.cells.item(this.getIndex(this.active));
59 Ext.create('Ext.fx.Anim', {
65 backgroundColor: '#FFFF00'
68 cell.setStyle('background-color', '');
74 var active = this.active;
75 this.setActive(active[0] - 1, active[1]);
79 var active = this.active;
80 this.setActive(active[0] + 1, active[1]);
84 var active = this.active;
85 this.setActive(active[0], active[1] - 1);
88 moveRight: function(){
89 var active = this.active;
90 this.setActive(active[0], active[1] + 1);
94 Ext.onReady(function(){
96 var cls = 'active-green';
97 var board = new Board(4, cls);
98 board.render('board');
99 board.setActive(0, 0);
101 var nav = Ext.create('Ext.util.KeyNav', Ext.getDoc(), {
103 left: board.moveLeft,
105 right: board.moveRight,
106 down: board.moveDown,
107 space: board.highlightActive,
109 cls = Ext.String.toggle(cls, 'active-green', 'active-red');
110 board.setActiveCls(cls);