diff --git a/cocos2d/animation/playable.js b/cocos2d/animation/playable.js index 4c959a20bc..04b1be2f7a 100644 --- a/cocos2d/animation/playable.js +++ b/cocos2d/animation/playable.js @@ -108,8 +108,10 @@ prototype.stop = function () { * @method pause */ prototype.pause = function () { - this._isPaused = true; - this.onPause(); + if (this._isPlaying) { + this._isPaused = true; + this.onPause(); + } }; /** @@ -118,8 +120,10 @@ prototype.pause = function () { * @method resume */ prototype.resume = function () { - this._isPaused = false; - this.onResume(); + if (this._isPlaying) { + this._isPaused = false; + this.onResume(); + } }; /** diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index 61f71711ca..19414c0af2 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -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. + */ diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index dbf804fc31..902a3b90b3 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -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. + */ diff --git a/cocos2d/core/components/CCPageView.js b/cocos2d/core/components/CCPageView.js index 9c28120d10..d3af08a70f 100644 --- a/cocos2d/core/components/CCPageView.js +++ b/cocos2d/core/components/CCPageView.js @@ -116,16 +116,15 @@ var PageView = cc.Class({ }, /** - * !#en Change the AutoScroll stop epsilon value of PageView, change this value could adjust the PageView's - * event triggerring timing. - * !#zh 设置 PageView 页面自动滚动动画结束的阈值,修改此值可以调整 PageView 事件的发送时机。 - * @property {Number} autoScrollStopEpsilon + * !#en Change the PageTurning event timing of PageView. + * !#zh 设置 PageView PageTurning 事件的发送时机。 + * @property {Number} pageTurningEventTiming */ - autoScrollStopEpsilon: { + pageTurningEventTiming: { default: 0.1, type: cc.Float, range: [0, 1, 0.01], - tooltip: 'i18n:COMPONENT.pageview.autoScrollStopEpsilon' + tooltip: 'i18n:COMPONENT.pageview.pageTurningEventTiming' }, /** @@ -164,12 +163,20 @@ var PageView = cc.Class({ __preload: function () { this._super(); this.node.on('size-changed', this._updateAllPagesSize, this); - // add _dispatchPageTurningEvent for scrollEvents - var pageTurningEvent = new cc.Component.EventHandler(); - pageTurningEvent.target = this.node; - pageTurningEvent.component = "cc.PageView"; - pageTurningEvent.handler = "_dispatchPageTurningEvent"; - this.scrollEvents.push(pageTurningEvent); + }, + + onEnable: function () { + this._super(); + if(!CC_EDITOR) { + this.node.on('scroll-ended', this._dispatchPageTurningEvent, this); + } + }, + + onDisable: function () { + this._super(); + if(!CC_EDITOR) { + this.node.off('scroll-ended', this._dispatchPageTurningEvent, this); + } }, onLoad: function () { @@ -313,8 +320,8 @@ var PageView = cc.Class({ }, //override the method of ScrollView - getAutoScrollStopEpsilon: function () { - return this.autoScrollStopEpsilon; + getScrollEndedEventTiming: function () { + return this.pageTurningEventTiming; }, // 刷新页面视图 @@ -360,12 +367,11 @@ var PageView = cc.Class({ } }, - _dispatchPageTurningEvent: function (sender, event) { - if (event === cc.ScrollView.EventType.AUTOSCROLL_ENDED) { - if (this._lastPageIdx === this._curPageIdx) return; - this._lastPageIdx = this._curPageIdx; - cc.Component.EventHandler.emitEvents(this.pageEvents, this, EventType.PAGE_TURNING); - } + _dispatchPageTurningEvent: function () { + 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); }, // 是否超过自动滚动临界值 @@ -446,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. + */ diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index d19f4bbcd7..ecb288d7c1 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -38,6 +38,7 @@ var getTimeInMilliseconds = function() { return currentTime.getMilliseconds(); }; + /** * !#en Enum for ScrollView event type. * !#zh 滚动视图事件类型 @@ -112,6 +113,20 @@ var EventType = cc.Enum({ TOUCH_UP : 10 }); +var eventMap = { + 'scroll-to-top' : EventType.SCROLL_TO_TOP, + 'scroll-to-bottom': EventType.SCROLL_TO_BOTTOM, + 'scroll-to-left' : EventType.SCROLL_TO_LEFT, + 'scroll-to-right' : EventType.SCROLL_TO_RIGHT, + 'scrolling' : EventType.SCROLLING, + 'bounce-bottom' : EventType.BOUNCE_BOTTOM, + 'bounce-left' : EventType.BOUNCE_LEFT, + 'bounce-right' : EventType.BOUNCE_RIGHT, + 'bounce-top' : EventType.BOUNCE_TOP, + 'scroll-ended' : EventType.AUTOSCROLL_ENDED, + 'touch-up' : EventType.TOUCH_UP + +}; /** * !#en * Layout container for a view hierarchy that can be scrolled by the user, @@ -683,10 +698,10 @@ var ScrollView = cc.Class({ if(this.elastic) { var outOfBoundary = this._getHowMuchOutOfBoundary(); - if (outOfBoundary.y > 0) this._dispatchEvent(EventType.BOUNCE_TOP); - if (outOfBoundary.y < 0) this._dispatchEvent(EventType.BOUNCE_BOTTOM); - if (outOfBoundary.x > 0) this._dispatchEvent(EventType.BOUNCE_RIGHT); - if (outOfBoundary.x < 0) this._dispatchEvent(EventType.BOUNCE_LEFT); + if (outOfBoundary.y > 0) this._dispatchEvent('bounce-top'); + if (outOfBoundary.y < 0) this._dispatchEvent('bounce-bottom'); + if (outOfBoundary.x > 0) this._dispatchEvent('bounce-right'); + if (outOfBoundary.x < 0) this._dispatchEvent('bounce-left'); } }, @@ -905,7 +920,7 @@ var ScrollView = cc.Class({ if (this.content) { this._handleReleaseLogic(touch); } - this._dispatchEvent(EventType.TOUCH_UP); + this._dispatchEvent('touch-up'); if (this._touchMoved) { event.stopPropagation(); } @@ -954,26 +969,26 @@ var ScrollView = cc.Class({ var icBottomPos = this.content.y - this.content.anchorY * this.content.height; if (icBottomPos + realMove.y > this._bottomBoundary) { - scrollEventType = EventType.SCROLL_TO_BOTTOM; + scrollEventType = 'scroll-to-bottom'; } } else if (realMove.y < 0) { //down var icTopPos = this.content.y - this.content.anchorY * this.content.height + this.content.height; if(icTopPos + realMove.y <= this._topBoundary) { - scrollEventType = EventType.SCROLL_TO_TOP; + scrollEventType = 'scroll-to-top'; } } else if (realMove.x < 0) { //left var icRightPos = this.content.x - this.content.anchorX * this.content.width + this.content.width; if (icRightPos + realMove.x <= this._rightBoundary) { - scrollEventType = EventType.SCROLL_TO_RIGHT; + scrollEventType = 'scroll-to-right'; } } else if (realMove.x > 0) { //right var icLeftPos = this.content.x - this.content.anchorX * this.content.width; if (icLeftPos + realMove.x >= this._leftBoundary) { - scrollEventType = EventType.SCROLL_TO_LEFT; + scrollEventType = 'scroll-to-left'; } } @@ -981,7 +996,7 @@ var ScrollView = cc.Class({ if(realMove.x !== 0 || realMove.y !== 0) { - this._dispatchEvent(EventType.SCROLLING); + this._dispatchEvent('scrolling'); } if (scrollEventType !== -1) { @@ -1089,7 +1104,7 @@ var ScrollView = cc.Class({ return false; }, - getAutoScrollStopEpsilon: function () { + getScrollEndedEventTiming: function () { return EPSILON; }, @@ -1107,9 +1122,9 @@ var ScrollView = cc.Class({ var newPosition = cc.pAdd(this._autoScrollStartPosition, cc.pMult(this._autoScrollTargetDelta, percentage)); var reachedEnd = (percentage === 1); - var fireEvent = Math.abs(percentage - 1) <= this.getAutoScrollStopEpsilon(); + var fireEvent = Math.abs(percentage - 1) <= this.getScrollEndedEventTiming(); if(fireEvent && !this._isScrollEndedEventFired) { - this._dispatchEvent(EventType.AUTOSCROLL_ENDED); + this._dispatchEvent('scroll-ended'); this._isScrollEndedEventFired = true; } @@ -1131,7 +1146,7 @@ var ScrollView = cc.Class({ if (reachedEnd) { this._autoScrolling = false; if(!this._isScrollEndedEventFired) { - this._dispatchEvent(EventType.AUTOSCROLL_ENDED); + this._dispatchEvent('scroll-ended'); } } @@ -1346,7 +1361,8 @@ var ScrollView = cc.Class({ }, _dispatchEvent: function(event) { - cc.Component.EventHandler.emitEvents(this.scrollEvents, this, event); + cc.Component.EventHandler.emitEvents(this.scrollEvents, this, eventMap[event]); + this.node.emit(event, this); }, //component life cycle methods @@ -1425,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. + */ diff --git a/cocos2d/core/components/CCSlider.js b/cocos2d/core/components/CCSlider.js index 81cb459201..3715326841 100644 --- a/cocos2d/core/components/CCSlider.js +++ b/cocos2d/core/components/CCSlider.js @@ -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. + */ diff --git a/cocos2d/core/components/CCToggle.js b/cocos2d/core/components/CCToggle.js index 74e401b30e..307f3de557 100644 --- a/cocos2d/core/components/CCToggle.js +++ b/cocos2d/core/components/CCToggle.js @@ -101,11 +101,13 @@ var Toggle = cc.Class({ __preload: function () { this._super(); - this._registerToggleEvent(); }, onEnable: function () { this._super(); + if(!CC_EDITOR) { + this._registerToggleEvent(); + } if(this.toggleGroup) { this.toggleGroup.addToggle(this); } @@ -113,6 +115,9 @@ var Toggle = cc.Class({ onDisable: function () { this._super(); + if(!CC_EDITOR) { + this._unregisterToggleEvent(); + } if(this.toggleGroup) { this.toggleGroup.removeToggle(this); } @@ -138,12 +143,11 @@ var Toggle = cc.Class({ }, _registerToggleEvent: function () { - var event = new cc.Component.EventHandler(); - event.target = this.node; - event.component = 'cc.Toggle'; - event.handler = 'toggle'; - this.clickEvents = [event]; + this.node.on('click', this.toggle, this); + }, + _unregisterToggleEvent: function () { + this.node.off('click', this.toggle, this); }, toggle: function (event) { @@ -163,10 +167,10 @@ var Toggle = cc.Class({ } }, - _emitToggleEvents: function (event) { - this.node.emit('toggle-event', this); + _emitToggleEvents: function () { + this.node.emit('toggle', this); if(this.checkEvents) { - cc.Component.EventHandler.emitEvents(this.checkEvents, event, this); + cc.Component.EventHandler.emitEvents(this.checkEvents, this); } }, @@ -183,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); @@ -204,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. + */ diff --git a/cocos2d/core/components/CCVideoPlayer.js b/cocos2d/core/components/CCVideoPlayer.js index 52e83c431e..33730940ff 100644 --- a/cocos2d/core/components/CCVideoPlayer.js +++ b/cocos2d/core/components/CCVideoPlayer.js @@ -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. + */ diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index aa639de9a1..41b853c1ba 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -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. + */ diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 30756f9f0a..f22d5774cc 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -689,6 +689,8 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; } else { thisPointer.__fullscreen = false; } + this.__autoResize = cc.view.__resizeWithBrowserSize; + cc.view.resizeWithBrowserSize(false); scrollWindowUp(editBox); @@ -703,6 +705,9 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; if(thisPointer.__fullscreen) { cc.view.enableAutoFullScreen(true); } + if (this.__autoResize) { + cc.view.resizeWithBrowserSize(true); + } window.scrollY = 0; if (editBox._delegate && editBox._delegate.editBoxEditingDidEnded) { editBox._delegate.editBoxEditingDidEnded(editBox); diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index f15ed636b8..df9d7252c2 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -191,13 +191,13 @@ JS.mixin(CCLoader.prototype, { completeCallback.call(self, errors, items); } completeCallback = null; - items.destroy(); if (CC_EDITOR) { - for (var i = 0; i < resources.length; i++) { - self.removeItem(resources[i].id || resources[i]); + for (var id in self._cache) { + self.removeItem(id); } } + items.destroy(); }); }); }, @@ -416,7 +416,7 @@ JS.mixin(CCLoader.prototype, { */ getRes: function (url) { var item = this._cache[url]; - if (item.alias) { + if (item && item.alias) { item = this._cache[item.alias]; } if (!item) { @@ -435,13 +435,13 @@ JS.mixin(CCLoader.prototype, { }, /** - * Release the cache of resource by url. + * Release the cache of resource by id which is usually the url. * * @method release - * @param {String} url + * @param {String} id */ - release: function (url) { - this.removeItem(url); + release: function (id) { + this.removeItem(id); }, /** diff --git a/cocos2d/core/platform/callbacks-invoker.js b/cocos2d/core/platform/callbacks-invoker.js index 843cb46314..b6790eed77 100644 --- a/cocos2d/core/platform/callbacks-invoker.js +++ b/cocos2d/core/platform/callbacks-invoker.js @@ -108,13 +108,27 @@ CallbacksHandler.prototype.add = function (key, callback, target) { * @return {Boolean} */ CallbacksHandler.prototype.has = function (key, callback, target) { + if (this._toRemoveAll === key) { + return false; + } var list = this._callbackTable[key], callbackTarget, index; if (!list) { return false; } // callback not given, but key found - if (!callback) - return true; + if (!callback) { + if (this._toRemove[key]) { + for (index = 0; index < list.length; index++) { + if (list[index] !== REMOVE_PLACEHOLDER) { + return true; + } + } + return false; + } + else { + return list.length > 0; + } + } // wrong callback type, can't found anything else if (typeof callback !== 'function') return false;