Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / widgets / CycleButton.js
index 7089665..a57bdfd 100644 (file)
@@ -1,6 +1,6 @@
 /*!
- * Ext JS Library 3.0.0
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.1.1
+ * Copyright(c) 2006-2010 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
@@ -81,8 +81,8 @@ Ext.CycleButton = Ext.extend(Ext.SplitButton, {
      * @param {Boolean} suppressEvent True to prevent the button's change event from firing (defaults to false)\r
      */\r
     setActiveItem : function(item, suppressEvent){\r
-        if(typeof item != 'object'){\r
-            item = this.menu.items.get(item);\r
+        if(!Ext.isObject(item)){\r
+            item = this.menu.getComponent(item);\r
         }\r
         if(item){\r
             if(!this.rendered){\r
@@ -97,7 +97,7 @@ Ext.CycleButton = Ext.extend(Ext.SplitButton, {
             }\r
             this.activeItem = item;\r
             if(!item.checked){\r
-                item.setChecked(true, true);\r
+                item.setChecked(true, false);\r
             }\r
             if(this.forceIcon){\r
                 this.setIconClass(this.forceIcon);\r
@@ -138,23 +138,23 @@ Ext.CycleButton = Ext.extend(Ext.SplitButton, {
         this.itemCount = this.items.length;\r
 \r
         this.menu = {cls:'x-cycle-menu', items:[]};\r
-        var checked;\r
-        for(var i = 0, len = this.itemCount; i < len; i++){\r
-            var item = this.items[i];\r
-            item.group = item.group || this.id;\r
-            item.itemIndex = i;\r
-            item.checkHandler = this.checkHandler;\r
-            item.scope = this;\r
-            item.checked = item.checked || false;\r
+        var checked = 0;\r
+        Ext.each(this.items, function(item, i){\r
+            Ext.apply(item, {\r
+                group: item.group || this.id,\r
+                itemIndex: i,\r
+                checkHandler: this.checkHandler,\r
+                scope: this,\r
+                checked: item.checked || false\r
+            });\r
             this.menu.items.push(item);\r
             if(item.checked){\r
-                checked = item;\r
+                checked = i;\r
             }\r
-        }\r
-        this.setActiveItem(checked, true);\r
+        }, this);\r
         Ext.CycleButton.superclass.initComponent.call(this);\r
-\r
         this.on('click', this.toggleSelected, this);\r
+        this.setActiveItem(checked, true);\r
     },\r
 \r
     // private\r
@@ -170,13 +170,18 @@ Ext.CycleButton = Ext.extend(Ext.SplitButton, {
      * the active item will be set to the first item in the menu.\r
      */\r
     toggleSelected : function(){\r
-        this.menu.render();\r
+        var m = this.menu;\r
+        m.render();\r
+        // layout if we haven't before so the items are active\r
+        if(!m.hasLayout){\r
+            m.doLayout();\r
+        }\r
         \r
         var nextIdx, checkItem;\r
         for (var i = 1; i < this.itemCount; i++) {\r
             nextIdx = (this.activeItem.itemIndex + i) % this.itemCount;\r
             // check the potential item\r
-            checkItem = this.menu.items.itemAt(nextIdx);\r
+            checkItem = m.items.itemAt(nextIdx);\r
             // if its not disabled then check it.\r
             if (!checkItem.disabled) {\r
                 checkItem.setChecked(true);\r