3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.SwitchButton = Ext.extend(Ext.Component, {
\r
9 initComponent : function(){
\r
10 Ext.SwitchButton.superclass.initComponent.call(this);
\r
12 var mc = new Ext.util.MixedCollection();
\r
13 mc.addAll(this.items);
\r
16 this.addEvents('change');
\r
19 this.on('change', this.handler, this.scope || this);
\r
23 onRender : function(ct, position){
\r
25 var el = document.createElement('table');
\r
27 el.className = 'x-rbtn';
\r
30 var row = document.createElement('tr');
\r
31 el.appendChild(row);
\r
33 var count = this.items.length;
\r
34 var last = count - 1;
\r
35 this.activeItem = this.items.get(this.activeItem);
\r
37 for(var i = 0; i < count; i++){
\r
38 var item = this.items.itemAt(i);
\r
40 var cell = row.appendChild(document.createElement('td'));
\r
41 cell.id = this.id + '-rbi-' + i;
\r
43 var cls = i == 0 ? 'x-rbtn-first' : (i == last ? 'x-rbtn-last' : 'x-rbtn-item');
\r
46 if(this.activeItem == item){
\r
49 cell.className = cls;
\r
51 var button = document.createElement('button');
\r
52 button.innerHTML = ' ';
\r
53 button.className = item.iconCls;
\r
54 button.qtip = item.tooltip;
\r
56 cell.appendChild(button);
\r
61 this.el = Ext.get(ct.dom.appendChild(el));
\r
63 this.el.on('click', this.onClick, this);
\r
66 getActiveItem : function(){
\r
67 return this.activeItem;
\r
70 setActiveItem : function(item){
\r
71 if(typeof item != 'object' && item !== null){
\r
72 item = this.items.get(item);
\r
74 var current = this.getActiveItem();
\r
75 if(item != current){
\r
77 Ext.fly(current.cell).removeClass(current.baseCls + '-active');
\r
80 Ext.fly(item.cell).addClass(item.baseCls + '-active');
\r
82 this.activeItem = item;
\r
83 this.fireEvent('change', this, item);
\r
88 onClick : function(e){
\r
89 var target = e.getTarget('td', 2);
\r
90 if(!this.disabled && target){
\r
91 this.setActiveItem(parseInt(target.id.split('-rbi-')[1], 10));
\r
96 Ext.reg('switch', Ext.SwitchButton);
\r