mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #1217 from zilongshanren/simplify-ui-component-event-register
Simplify ui component event register
This commit is contained in:
@@ -643,3 +643,13 @@ var Button = cc.Class({
|
||||
});
|
||||
|
||||
cc.Button = module.exports = Button;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event click
|
||||
* @param {Event} event
|
||||
* @param {Button} event.detail - The Button component.
|
||||
*/
|
||||
|
||||
@@ -500,18 +500,22 @@ var EditBox = cc.Class({
|
||||
|
||||
editBoxEditingDidBegan: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.editingDidBegan, this);
|
||||
this.node.emit('editing-did-began', this);
|
||||
},
|
||||
|
||||
editBoxEditingDidEnded: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.editingDidEnded, this);
|
||||
this.node.emit('editing-did-ended', this);
|
||||
},
|
||||
|
||||
editBoxTextChanged: function(editBox, text) {
|
||||
cc.Component.EventHandler.emitEvents(this.textChanged, text, this);
|
||||
this.node.emit('text-changed', this);
|
||||
},
|
||||
|
||||
editBoxEditingReturn: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.editingReturn, this);
|
||||
this.node.emit('editing-return', this);
|
||||
},
|
||||
|
||||
__preload: function() {
|
||||
@@ -582,3 +586,43 @@ if(CC_JSB) {
|
||||
}
|
||||
|
||||
cc.EditBox = module.exports = EditBox;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event editing-did-began
|
||||
* @param {Event} event
|
||||
* @param {EditBox} event.detail - The EditBox component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event editing-did-ended
|
||||
* @param {Event} event
|
||||
* @param {EditBox} event.detail - The EditBox component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event text-changed
|
||||
* @param {Event} event
|
||||
* @param {EditBox} event.detail - The EditBox component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event editing-return
|
||||
* @param {Event} event
|
||||
* @param {EditBox} event.detail - The EditBox component.
|
||||
*/
|
||||
|
||||
@@ -371,6 +371,7 @@ var PageView = cc.Class({
|
||||
if (this._lastPageIdx === this._curPageIdx) return;
|
||||
this._lastPageIdx = this._curPageIdx;
|
||||
cc.Component.EventHandler.emitEvents(this.pageEvents, this, EventType.PAGE_TURNING);
|
||||
this.node.emit('page-turning', this);
|
||||
},
|
||||
|
||||
// 是否超过自动滚动临界值
|
||||
@@ -451,3 +452,13 @@ var PageView = cc.Class({
|
||||
});
|
||||
|
||||
cc.PageView = module.exports = PageView;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event page-turning
|
||||
* @param {Event} event
|
||||
* @param {PageView} event.detail - The PageView component.
|
||||
*/
|
||||
|
||||
@@ -1441,3 +1441,113 @@ var ScrollView = cc.Class({
|
||||
});
|
||||
|
||||
cc.ScrollView = module.exports = ScrollView;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scroll-to-top
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scroll-to-bottom
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scroll-to-left
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scroll-to-right
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scrolling
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event bounce-bottom
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event bounce-top
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event bounce-left
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event bounce-right
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event scroll-ended
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event touch-up
|
||||
* @param {Event} event
|
||||
* @param {ScrollView} event.detail - The ScrollView component.
|
||||
*/
|
||||
|
||||
@@ -182,11 +182,12 @@ var Slider = cc.Class({
|
||||
|
||||
_handleSliderLogic: function (touch) {
|
||||
this._updateProgress(touch);
|
||||
this._emitSldeEvent();
|
||||
this._emitSlideEvent();
|
||||
},
|
||||
|
||||
_emitSldeEvent: function () {
|
||||
_emitSlideEvent: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.slideEvents, this);
|
||||
this.node.emit('slide', this);
|
||||
},
|
||||
|
||||
_updateProgress: function (touch) {
|
||||
@@ -219,3 +220,13 @@ var Slider = cc.Class({
|
||||
});
|
||||
|
||||
cc.Slider = module.exports = Slider;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event slider
|
||||
* @param {Event} event
|
||||
* @param {Slider} event.detail - The slider component.
|
||||
*/
|
||||
|
||||
@@ -168,7 +168,7 @@ var Toggle = cc.Class({
|
||||
},
|
||||
|
||||
_emitToggleEvents: function (event) {
|
||||
this.node.emit('toggle-event', this);
|
||||
this.node.emit('toggle', this);
|
||||
if(this.checkEvents) {
|
||||
cc.Component.EventHandler.emitEvents(this.checkEvents, event, this);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ var Toggle = cc.Class({
|
||||
}
|
||||
|
||||
this.isChecked = true;
|
||||
this.node.emit('toggle-event', this);
|
||||
this.node.emit('toggle', this);
|
||||
|
||||
if(this.toggleGroup) {
|
||||
this.toggleGroup.updateToggles(this);
|
||||
@@ -208,10 +208,20 @@ var Toggle = cc.Class({
|
||||
|
||||
this.isChecked = false;
|
||||
|
||||
this.node.emit('toggle-event', this);
|
||||
this.node.emit('toggle', this);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
cc.Toggle = module.exports = Toggle;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event toggle
|
||||
* @param {Event} event
|
||||
* @param {Toggle} event.detail - The Toggle component.
|
||||
*/
|
||||
|
||||
@@ -265,30 +265,37 @@ var VideoPlayer = cc.Class({
|
||||
|
||||
onReadyToPlay: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.READY_TO_PLAY);
|
||||
this.node.emit('ready-to-play', this);
|
||||
},
|
||||
|
||||
onMetaLoaded: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.META_LOADED);
|
||||
this.node.emit('meta-loaded', this);
|
||||
},
|
||||
|
||||
onClicked: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.CLICKED);
|
||||
this.node.emit('clicked', this);
|
||||
},
|
||||
|
||||
onPlaying: function(){
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.PLAYING);
|
||||
this.node.emit('playing', this);
|
||||
},
|
||||
|
||||
onPasued: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.PAUSED);
|
||||
this.node.emit('paused', this);
|
||||
},
|
||||
|
||||
onStopped: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.STOPPED);
|
||||
this.node.emit('stopped', this);
|
||||
},
|
||||
|
||||
onCompleted: function() {
|
||||
cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.COMPLETED);
|
||||
this.node.emit('completed', this);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -360,3 +367,74 @@ var VideoPlayer = cc.Class({
|
||||
});
|
||||
|
||||
cc.VideoPlayer = module.exports = VideoPlayer;
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event ready-to-play
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event meta-loaded
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event clicked
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event playing
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event paused
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event stopped
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event completed
|
||||
* @param {Event} event
|
||||
* @param {VideoPlayer} event.detail - The VideoPlayer component.
|
||||
*/
|
||||
|
||||
@@ -139,17 +139,49 @@ var WebView = cc.Class({
|
||||
|
||||
_onWebViewLoaded: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADED);
|
||||
this.node.emit('loaded', this);
|
||||
},
|
||||
|
||||
_onWebViewLoading: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADING);
|
||||
this.node.emit('loading', this);
|
||||
return true;
|
||||
},
|
||||
|
||||
_onWebViewLoadError: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.ERROR);
|
||||
this.node.emit('error', this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
cc.WebView = module.exports = WebView;
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event loaded
|
||||
* @param {Event} event
|
||||
* @param {WebView} event.detail - The WebView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event loading
|
||||
* @param {Event} event
|
||||
* @param {WebView} event.detail - The WebView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event error
|
||||
* @param {Event} event
|
||||
* @param {WebView} event.detail - The WebView component.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user