From 9e4ee2470726e3334eb47d904a6f4079d4ed7aef Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 6 Mar 2012 17:01:39 -0800 Subject: IKNINJA-1270: fixed browser crashing when you close a document while playing a video then wait for a while Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 9 ++++++++ js/controllers/selection-controller.js | 13 +++++++++++ js/document/html-document.js | 41 +++++++++++++++++++++++++++++++++- js/helper-classes/3D/draw-utils.js | 10 +++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index e29148c9..de080167 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -363,14 +363,23 @@ var DocumentController = exports.DocumentController = Montage.create(Component, nextDocumentIndex = closeDocumentIndex - 1; } this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); + doc.stopVideos(); this._removeDocumentView(doc.container); }else if(this._documents.length === 0){ + if(typeof this.activeDocument.pauseVideos !== "undefined"){ + this.activeDocument.pauseVideos(true); + } this.activeDocument = null; this._removeDocumentView(doc.container); this.application.ninja.stage.stageView.hideRulers(); document.getElementById("iframeContainer").style.display="block"; this.application.ninja.stage.hideCanvas(true); + }else{//closing inactive document tab - just clear DOM + if(typeof doc.pauseVideos !== "undefined"){ + doc.pauseVideos(true); + } + this._removeDocumentView(doc.container); } NJevent("closeDocument", doc.uri); diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 3f9d8514..49bf42b6 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -48,6 +48,7 @@ exports.SelectionController = Montage.create(Component, { this.eventManager.addEventListener("selectAll", this, false); this.eventManager.addEventListener("deleteSelection", this, false); this.eventManager.addEventListener("switchDocument", this, false); + this.eventManager.addEventListener("closeDocument", this, false); // defaultEventManager.addEventListener( "undo", this, false); // defaultEventManager.addEventListener( "redo", this, false); } @@ -105,6 +106,18 @@ exports.SelectionController = Montage.create(Component, { } }, + handleCloseDocument:{ + value: function() { + //clear selections if all documents are closed + if(this.application.ninja.documentController._documents.length === 0){ + this._selectedItems.length =0; + this.application.ninja.selectedElements.length =0; + this._isDocument = true; + NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); + } + } + }, + handleElementAdded: { value: function(event) { this.executeSelectElement(event.detail); diff --git a/js/document/html-document.js b/js/document/html-document.js index 80930af2..d90231e3 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -824,6 +824,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0); this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0); this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start + + //pause videos on switching or closing the document, so that the browser does not keep downloading the media data + this.pauseVideos(); } }, @@ -852,6 +855,42 @@ exports.HTMLDocument = Montage.create(TextDocument, { } - } + }, //////////////////////////////////////////////////////////////////// + /** + *pause videos on switching or closing the document, so that the browser does not keep downloading the media data + *removeSrc : boolean to remove the src if the video... set only in the close document flow + */ + pauseVideos:{ + value:function(removeSrc){ + console.log("$$$ pauseVideos"); + var videosArr = this.documentRoot.getElementsByTagName("video"), i=0; + for(i=0;i