diff options
author | Valerio Virgillito | 2012-03-08 13:39:11 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-03-08 13:39:11 -0800 |
commit | 5940b22e01de4fc36e5c5de5f3ed074f08fadb07 (patch) | |
tree | 72a5592ef65b3238b31f0e9954b2ad8d1778eeac | |
parent | 9b006acf1f6c2be5abc54f94a8bee7e684f106f9 (diff) | |
parent | 130cd6d4b99c9db344ec0ab44a54a59d11b31d2f (diff) | |
download | ninja-5940b22e01de4fc36e5c5de5f3ed074f08fadb07.tar.gz |
Merge pull request #104 from ananyasen/integration-candidate
IKNINJA-1270: fixed browser crashing when you close a document while playing a video
-rwxr-xr-x | js/controllers/document-controller.js | 9 | ||||
-rwxr-xr-x | js/document/html-document.js | 43 | ||||
-rwxr-xr-x | js/helper-classes/3D/draw-utils.js | 10 |
3 files changed, 61 insertions, 1 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 194496a6..a8056519 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -336,14 +336,23 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
336 | nextDocumentIndex = closeDocumentIndex - 1; | 336 | nextDocumentIndex = closeDocumentIndex - 1; |
337 | } | 337 | } |
338 | this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); | 338 | this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); |
339 | if(typeof this.activeDocument.stopVideos !== "undefined"){doc.stopVideos();} | ||
339 | this._removeDocumentView(doc.container); | 340 | this._removeDocumentView(doc.container); |
340 | }else if(this._documents.length === 0){ | 341 | }else if(this._documents.length === 0){ |
342 | if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ | ||
343 | this.activeDocument.pauseAndStopVideos(); | ||
344 | } | ||
341 | this.activeDocument = null; | 345 | this.activeDocument = null; |
342 | this._removeDocumentView(doc.container); | 346 | this._removeDocumentView(doc.container); |
343 | this.application.ninja.stage.stageView.hideRulers(); | 347 | this.application.ninja.stage.stageView.hideRulers(); |
344 | document.getElementById("iframeContainer").style.display="block"; | 348 | document.getElementById("iframeContainer").style.display="block"; |
345 | 349 | ||
346 | this.application.ninja.stage.hideCanvas(true); | 350 | this.application.ninja.stage.hideCanvas(true); |
351 | }else{//closing inactive document tab - just clear DOM | ||
352 | if(typeof doc.pauseAndStopVideos !== "undefined"){ | ||
353 | doc.pauseAndStopVideos(); | ||
354 | } | ||
355 | this._removeDocumentView(doc.container); | ||
347 | } | 356 | } |
348 | 357 | ||
349 | NJevent("closeDocument", doc.uri); | 358 | NJevent("closeDocument", doc.uri); |
diff --git a/js/document/html-document.js b/js/document/html-document.js index b9b68972..23b55e92 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -842,6 +842,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
842 | this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0); | 842 | this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0); |
843 | this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0); | 843 | this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0); |
844 | this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start | 844 | this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start |
845 | |||
846 | //pause videos on switching or closing the document, so that the browser does not keep downloading the media data | ||
847 | this.pauseVideos(); | ||
845 | } | 848 | } |
846 | }, | 849 | }, |
847 | 850 | ||
@@ -870,6 +873,44 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
870 | 873 | ||
871 | 874 | ||
872 | } | 875 | } |
873 | } | 876 | }, |
874 | //////////////////////////////////////////////////////////////////// | 877 | //////////////////////////////////////////////////////////////////// |
878 | /** | ||
879 | *pause videos on switching or closing the document, so that the browser does not keep downloading the media data | ||
880 | */ | ||
881 | pauseVideos:{ | ||
882 | value:function(){ | ||
883 | var videosArr = this.documentRoot.getElementsByTagName("video"), i=0; | ||
884 | for(i=0;i<videosArr.length;i++){ | ||
885 | if(!videosArr[i].paused){ | ||
886 | videosArr[i].pause(); | ||
887 | } | ||
888 | } | ||
889 | } | ||
890 | }, | ||
891 | |||
892 | /** | ||
893 | * remove the video src on closing the document, so that the browser does not keep downloading the media data, if the tag does not get garbage collected | ||
894 | *removeSrc : boolean to remove the src if the video... set only in the close document flow | ||
895 | */ | ||
896 | stopVideos:{ | ||
897 | value:function(){ | ||
898 | var videosArr = this.documentRoot.getElementsByTagName("video"), i=0; | ||
899 | for(i=0;i<videosArr.length;i++){ | ||
900 | videosArr[i].src = ""; | ||
901 | } | ||
902 | } | ||
903 | }, | ||
904 | pauseAndStopVideos:{ | ||
905 | value:function(){ | ||
906 | var videosArr = this.documentRoot.getElementsByTagName("video"), i=0; | ||
907 | for(i=0;i<videosArr.length;i++){ | ||
908 | if(!videosArr[i].paused){ | ||
909 | videosArr[i].pause(); | ||
910 | } | ||
911 | videosArr[i].src = ""; | ||
912 | } | ||
913 | } | ||
914 | } | ||
915 | //////////////////////////////////////////////////////////////////// | ||
875 | }); \ No newline at end of file | 916 | }); \ No newline at end of file |
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 02d946ae..63e7799a 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -112,6 +112,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
112 | this.eventManager.addEventListener("elementDeleted", this, false); | 112 | this.eventManager.addEventListener("elementDeleted", this, false); |
113 | this.eventManager.addEventListener("deleteSelection", this, false); | 113 | this.eventManager.addEventListener("deleteSelection", this, false); |
114 | this.eventManager.addEventListener("elementChange", this, false); | 114 | this.eventManager.addEventListener("elementChange", this, false); |
115 | this.eventManager.addEventListener("closeDocument", this, false); | ||
115 | } | 116 | } |
116 | }, | 117 | }, |
117 | 118 | ||
@@ -135,6 +136,15 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
135 | } | 136 | } |
136 | }, | 137 | }, |
137 | 138 | ||
139 | handleCloseDocument:{ | ||
140 | value: function() { | ||
141 | if(this.application.ninja.documentController._documents.length === 0){ | ||
142 | this._eltArray = []; | ||
143 | this._planesArray = []; | ||
144 | } | ||
145 | } | ||
146 | }, | ||
147 | |||
138 | handleElementAdded: { | 148 | handleElementAdded: { |
139 | value: function(event) { | 149 | value: function(event) { |
140 | this.addElement(event.detail); | 150 | this.addElement(event.detail); |