diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index be6df3152a..cb36d22ede 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -626,3 +626,17 @@ cc.EditBox = module.exports = EditBox; * @param {Event.EventCustom} event * @param {EditBox} event.detail - The EditBox component. */ + +/** + * !#en if you don't need the EditBox and it isn't in any running Scene, you should + * call the destroy method on this component or the associated node explicitly. + * Otherwise, the created DOM element won't be removed from web page. + * !#zh + * 如果你不再使用 EditBox,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。 + * 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。 + * @example + * editbox.node.parent = null; // or editbox.node.removeFromParent(false); + * // when you don't need editbox anymore + * editbox.node.destroy(); + * @method destroy + */ diff --git a/cocos2d/core/components/CCVideoPlayer.js b/cocos2d/core/components/CCVideoPlayer.js index 2997f0c8a6..370c2791ab 100644 --- a/cocos2d/core/components/CCVideoPlayer.js +++ b/cocos2d/core/components/CCVideoPlayer.js @@ -347,6 +347,8 @@ var VideoPlayer = cc.Class({ /** * !#en Gets the duration of the video * !#zh 获取视频文件的播放总时长 + * @method getDuration + * @returns {Number} */ getDuration: function() { if(this._sgNode) { @@ -358,6 +360,8 @@ var VideoPlayer = cc.Class({ /** * !#en Determine whether video is playing or not. * !#zh 判断当前视频是否处于播放状态 + * @method isPlaying + * @returns {Boolean} */ isPlaying: function() { if(this._sgNode) { @@ -365,7 +369,6 @@ var VideoPlayer = cc.Class({ } return false; } - }); cc.VideoPlayer = module.exports = VideoPlayer; @@ -440,3 +443,17 @@ cc.VideoPlayer = module.exports = VideoPlayer; * @param {Event.EventCustom} event * @param {VideoPlayer} event.detail - The VideoPlayer component. */ + +/** + * !#en if you don't need the VideoPlayer and it isn't in any running Scene, you should + * call the destroy method on this component or the associated node explicitly. + * Otherwise, the created DOM element won't be removed from web page. + * !#zh + * 如果你不再使用 VideoPlayer,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。 + * 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。 + * @example + * videoplayer.node.parent = null; // or videoplayer.node.removeFromParent(false); + * // when you don't need videoplayer anymore + * videoplayer.node.destroy(); + * @method destroy + */ diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index 369d460399..03aed87c1f 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -152,7 +152,6 @@ var WebView = cc.Class({ cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.ERROR); this.node.emit('error', this); } - }); cc.WebView = module.exports = WebView; @@ -185,3 +184,17 @@ cc.WebView = module.exports = WebView; * @param {Event.EventCustom} event * @param {WebView} event.detail - The WebView component. */ + +/** + * !#en if you don't need the WebView and it isn't in any running Scene, you should + * call the destroy method on this component or the associated node explicitly. + * Otherwise, the created DOM element won't be removed from web page. + * !#zh + * 如果你不再使用 WebView,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。 + * 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。 + * @example + * webview.node.parent = null; // or webview.node.removeFromParent(false); + * // when you don't need webview anymore + * webview.node.destroy(); + * @method destroy + */ diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 45d551a4c0..263ec6da75 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -321,15 +321,9 @@ _ccsg.EditBox = _ccsg.Node.extend({ this._renderCmd.stayOnTop(this._alwaysOnTop); }, - onEnter: function () { - _ccsg.Node.prototype.onEnter.call(this); - //in case the EditBox being used after changing parent - this.createDomElementIfNeeded(); - }, - - onExit: function () { - _ccsg.Node.prototype.onExit.call(this); - this._renderCmd._removeDomFromGameContainer(); + cleanup: function () { + this._super(); + this._renderCmd.removeDom(); }, _onTouchBegan: function (touch) { @@ -675,7 +669,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; proto._createDomInput = function () { - this._removeDomFromGameContainer(); + this.removeDom(); var thisPointer = this; var tmpEdTxt = this._edTxt = document.createElement('input'); @@ -770,7 +764,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; }; proto._createDomTextArea = function () { - this._removeDomFromGameContainer(); + this.removeDom(); var thisPointer = this; var tmpEdTxt = this._edTxt = document.createElement('textarea'); @@ -980,7 +974,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; } if (cc.sys.isMobile && !this._editingMode) { - // Pre adaptation and + // Pre adaptation and this._beginEditingOnMobile(this._editBox); } this._editingMode = true; @@ -1177,7 +1171,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; cc.game.container.appendChild(this._edTxt); }; - proto._removeDomFromGameContainer = function () { + proto.removeDom = function () { var editBox = this._edTxt; if(editBox){ var hasChild = Utils.contains(cc.game.container, editBox); @@ -1197,7 +1191,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; this._textLabel = null; this._placeholderLabel = null; this._editingMode = false; - + this.__fullscreen = false; this.__autoResize = false; this.__rotateScreen = false; diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index 1e07de42f0..45e4b17a4c 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -146,13 +146,17 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ list.push(this); }, + cleanup: function () { + this._super(); + this._renderCmd.removeDom(); + }, + onExit: function () { _ccsg.Node.prototype.onExit.call(this); var list = _ccsg.VideoPlayer.elements; var index = list.indexOf(this); if(index !== -1) list.splice(index, 1); - this._renderCmd.removeDom(); }, setVisible: function ( visible ) { diff --git a/cocos2d/core/webview/CCSGWebView.js b/cocos2d/core/webview/CCSGWebView.js index 58b142c247..f80f2d3ce6 100644 --- a/cocos2d/core/webview/CCSGWebView.js +++ b/cocos2d/core/webview/CCSGWebView.js @@ -182,8 +182,8 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ this._renderCmd.updateSize(width, height); }, - onExit: function () { - _ccsg.Node.prototype.onExit.call(this); + cleanup: function () { + this._super(); this._renderCmd.removeDom(); },