+++ /dev/null
-<html>\r
-<head>\r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js">Ext.SwitchButton = Ext.extend(Ext.Component, {\r
- initComponent : function(){\r
- Ext.SwitchButton.superclass.initComponent.call(this);\r
- \r
- var mc = new Ext.util.MixedCollection();\r
- mc.addAll(this.items);\r
- this.items = mc;\r
- \r
- this.addEvents('change');\r
- \r
- if(this.handler){\r
- this.on('change', this.handler, this.scope || this);\r
- }\r
- },\r
- \r
- onRender : function(ct, position){\r
- \r
- var el = document.createElement('table');\r
- el.cellSpacing = 0;\r
- el.className = 'x-rbtn';\r
- el.id = this.id;\r
- \r
- var row = document.createElement('tr');\r
- el.appendChild(row);\r
- \r
- var count = this.items.length;\r
- var last = count - 1;\r
- this.activeItem = this.items.get(this.activeItem);\r
- \r
- for(var i = 0; i < count; i++){\r
- var item = this.items.itemAt(i);\r
- \r
- var cell = row.appendChild(document.createElement('td'));\r
- cell.id = this.id + '-rbi-' + i;\r
- \r
- var cls = i == 0 ? 'x-rbtn-first' : (i == last ? 'x-rbtn-last' : 'x-rbtn-item');\r
- item.baseCls = cls;\r
- \r
- if(this.activeItem == item){\r
- cls += '-active';\r
- }\r
- cell.className = cls;\r
- \r
- var button = document.createElement('button');\r
- button.innerHTML = ' ';\r
- button.className = item.iconCls;\r
- button.qtip = item.tooltip;\r
- \r
- cell.appendChild(button);\r
- \r
- item.cell = cell;\r
- }\r
- \r
- this.el = Ext.get(ct.dom.appendChild(el));\r
- \r
- this.el.on('click', this.onClick, this);\r
- },\r
- \r
- getActiveItem : function(){\r
- return this.activeItem;\r
- },\r
- \r
- setActiveItem : function(item){\r
- if(typeof item != 'object' && item !== null){\r
- item = this.items.get(item);\r
- }\r
- var current = this.getActiveItem();\r
- if(item != current){\r
- if(current){\r
- Ext.fly(current.cell).removeClass(current.baseCls + '-active');\r
- }\r
- if(item) {\r
- Ext.fly(item.cell).addClass(item.baseCls + '-active');\r
- }\r
- this.activeItem = item;\r
- this.fireEvent('change', this, item);\r
- }\r
- return item;\r
- },\r
- \r
- onClick : function(e){\r
- var target = e.getTarget('td', 2);\r
- if(!this.disabled && target){\r
- this.setActiveItem(parseInt(target.id.split('-rbi-')[1], 10));\r
- }\r
- }\r
-});\r
-\r
-Ext.reg('switch', Ext.SwitchButton);\r
-</pre> \r
-</body>\r
-</html>
\ No newline at end of file