3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
22 constructor: function(size, activeCls){
24 this.activeCls = activeCls;
30 var tpl = Ext.create('Ext.XTemplate',
32 '<div class="square">{.}</div>',
33 '<tpl if="xindex % ' + this.size + ' === 0"><div class="x-clear"></div></tpl>',
37 max = this.size * this.size;
39 for (; i < max; ++i) {
43 this.cells = el.select('.square');
46 getIndex: function(xy){
47 return this.size * xy[0] + xy[1];
50 constrain: function(x, y) {
51 x = Ext.Number.constrain(x, 0, this.size - 1);
52 y = Ext.Number.constrain(y, 0, this.size - 1);
56 setActive: function(x, y) {
57 var xy = this.constrain(x, y),
58 cell = this.cells.item(this.getIndex(xy));
60 cell.radioCls(this.activeCls);
64 setActiveCls: function(activeCls){
65 this.cells.removeCls(this.activeCls);
66 this.activeCls = activeCls;
67 var active = this.active;
68 this.setActive(active[0], active[1]);
71 highlightActive: function(){
72 var cell = this.cells.item(this.getIndex(this.active));
73 Ext.create('Ext.fx.Anim', {
79 backgroundColor: '#FFFF00'
82 cell.setStyle('background-color', '');
88 var active = this.active;
89 this.setActive(active[0] - 1, active[1]);
93 var active = this.active;
94 this.setActive(active[0] + 1, active[1]);
98 var active = this.active;
99 this.setActive(active[0], active[1] - 1);
102 moveRight: function(){
103 var active = this.active;
104 this.setActive(active[0], active[1] + 1);
108 Ext.onReady(function(){
110 var cls = 'active-green';
111 var board = new Board(4, cls);
112 board.render('board');
113 board.setActive(0, 0);
115 var nav = Ext.create('Ext.util.KeyNav', Ext.getDoc(), {
117 left: board.moveLeft,
119 right: board.moveRight,
120 down: board.moveDown,
121 space: board.highlightActive,
123 cls = Ext.String.toggle(cls, 'active-green', 'active-red');
124 board.setActiveCls(cls);