From 792570ef52535c2ce7eb4a6db01f65d1b92d8910 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 17 Apr 2017 11:41:03 +0800 Subject: [PATCH 1/4] adjust toggle event emit timing --- cocos2d/core/components/CCToggle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCToggle.js b/cocos2d/core/components/CCToggle.js index 941d6e48c4..7d01423788 100644 --- a/cocos2d/core/components/CCToggle.js +++ b/cocos2d/core/components/CCToggle.js @@ -160,11 +160,12 @@ var Toggle = cc.Class({ this._updateCheckMark(); - this._emitToggleEvents(event); if(this.toggleGroup) { this.toggleGroup.updateToggles(this); } + + this._emitToggleEvents(event); }, _emitToggleEvents: function () { @@ -187,11 +188,12 @@ var Toggle = cc.Class({ } this.isChecked = true; - this._emitToggleEvents(); if(this.toggleGroup) { this.toggleGroup.updateToggles(this); } + + this._emitToggleEvents(); }, /** From f158c294b8ec3b2352c12e2ba8d35dcdee686fb7 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 17 Apr 2017 13:34:51 +0800 Subject: [PATCH 2/4] disable toggle group when group is disabled --- cocos2d/core/components/CCToggle.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/components/CCToggle.js b/cocos2d/core/components/CCToggle.js index 7d01423788..a791d9d546 100644 --- a/cocos2d/core/components/CCToggle.js +++ b/cocos2d/core/components/CCToggle.js @@ -108,7 +108,7 @@ var Toggle = cc.Class({ if(!CC_EDITOR) { this._registerToggleEvent(); } - if(this.toggleGroup) { + if(this.toggleGroup && this.toggleGroup.enabled) { this.toggleGroup.addToggle(this); } }, @@ -118,14 +118,14 @@ var Toggle = cc.Class({ if(!CC_EDITOR) { this._unregisterToggleEvent(); } - if(this.toggleGroup) { + if(this.toggleGroup && this.toggleGroup.enabled) { this.toggleGroup.removeToggle(this); } }, _updateCheckMark: function () { if(this.checkMark) { - this.checkMark.enabled = !!this.isChecked; + this.checkMark.node.active = !!this.isChecked; } }, @@ -151,7 +151,7 @@ var Toggle = cc.Class({ }, toggle: function (event) { - if(this.toggleGroup && this.isChecked) { + if(this.toggleGroup && this.toggleGroup.enabled && this.isChecked) { if(!this.toggleGroup.allowSwitchOff) { return; } @@ -161,7 +161,7 @@ var Toggle = cc.Class({ this._updateCheckMark(); - if(this.toggleGroup) { + if(this.toggleGroup && this.toggleGroup.enabled) { this.toggleGroup.updateToggles(this); } @@ -181,7 +181,7 @@ var Toggle = cc.Class({ * @method check */ check: function () { - if(this.toggleGroup && this.isChecked) { + if(this.toggleGroup && this.toggleGroup.enabled && this.isChecked) { if(!this.toggleGroup.allowSwitchOff) { return; } @@ -189,7 +189,7 @@ var Toggle = cc.Class({ this.isChecked = true; - if(this.toggleGroup) { + if(this.toggleGroup && this.toggleGroup.enabled) { this.toggleGroup.updateToggles(this); } @@ -202,7 +202,7 @@ var Toggle = cc.Class({ * @method uncheck */ uncheck: function () { - if(this.toggleGroup && this.isChecked) { + if(this.toggleGroup && this.toggleGroup.enabled && this.isChecked) { if(!this.toggleGroup.allowSwitchOff) { return; } From be4b8785e9ff1a85e446823432969678ab57033b Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 17 Apr 2017 16:46:58 +0800 Subject: [PATCH 3/4] toggle group add toggleItems property --- cocos2d/core/components/CCToggleGroup.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos2d/core/components/CCToggleGroup.js b/cocos2d/core/components/CCToggleGroup.js index 1026a8c0d4..db9fec4f10 100644 --- a/cocos2d/core/components/CCToggleGroup.js +++ b/cocos2d/core/components/CCToggleGroup.js @@ -53,6 +53,12 @@ var ToggleGroup = cc.Class({ allowSwitchOff: { tooltip: CC_DEV && 'i18n:COMPONENT.toggle_group.allowSwitchOff', default: false + }, + + toggleItems: { + get: function (){ + return this._toggleItems; + } } }, From 658a12e9abfdf65a87bc49979c97b2c9574ad09f Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 17 Apr 2017 16:51:32 +0800 Subject: [PATCH 4/4] update API docs --- cocos2d/core/components/CCToggleGroup.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos2d/core/components/CCToggleGroup.js b/cocos2d/core/components/CCToggleGroup.js index db9fec4f10..d738f1b4c5 100644 --- a/cocos2d/core/components/CCToggleGroup.js +++ b/cocos2d/core/components/CCToggleGroup.js @@ -55,6 +55,11 @@ var ToggleGroup = cc.Class({ default: false }, + /** + * !#en Read only property, return the toggle items array reference managed by toggleGroup. + * !#zh 只读属性,返回 toggleGroup 管理的 toggle 数组引用 + * @property {Array} toggleItems + */ toggleItems: { get: function (){ return this._toggleItems;