aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-15 22:36:44 -0700
committerValerio Virgillito2012-05-15 22:36:44 -0700
commit919a0d0ed35c24b1047281723ddde2ac98fc9a3e (patch)
treea35ef0d07bf16a461543f4481a04f005ceacc160
parent94855a2c1074f67f158b94ca0d61c51ee46c51b5 (diff)
downloadninja-919a0d0ed35c24b1047281723ddde2ac98fc9a3e.tar.gz
document close handler. initial working draft
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
-rwxr-xr-xjs/components/layout/document-entry.reel/document-entry.js2
-rwxr-xr-xjs/controllers/document-controller.js66
-rwxr-xr-xjs/document/document-html.js26
-rwxr-xr-xjs/document/html-document.js39
-rwxr-xr-xjs/document/models/base.js3
5 files changed, 49 insertions, 87 deletions
diff --git a/js/components/layout/document-entry.reel/document-entry.js b/js/components/layout/document-entry.reel/document-entry.js
index 81a63c90..4d09a362 100755
--- a/js/components/layout/document-entry.reel/document-entry.js
+++ b/js/components/layout/document-entry.reel/document-entry.js
@@ -117,7 +117,7 @@ exports.DocumentEntry = Montage.create(Component, {
117 handleClick: { 117 handleClick: {
118 value: function(event) { 118 value: function(event) {
119 if(event._event.target.nodeName === "IMG") { 119 if(event._event.target.nodeName === "IMG") {
120 this.application.ninja.documentController.closeDocument(this._uuid); 120 this.application.ninja.documentController.closeFile(this.application.ninja.documentController._findDocumentByUUID(this._uuid));
121 } else { 121 } else {
122 if(!this._document.isActive) { 122 if(!this._document.isActive) {
123 this.application.ninja.stage.stageView.switchDocument(this.application.ninja.documentController._findDocumentByUUID(this._uuid)); 123 this.application.ninja.stage.stageView.switchDocument(this.application.ninja.documentController._findDocumentByUUID(this._uuid));
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 48ceb21b..51791a11 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -33,6 +33,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
33 value: false 33 value: false
34 }, 34 },
35 35
36 _hackInitialStyles: {
37 value: true
38 },
39
36 _activeDocument: { value: null }, 40 _activeDocument: { value: null },
37 _iframeCounter: { value: 1, enumerable: false }, 41 _iframeCounter: { value: 1, enumerable: false },
38 _iframeHolder: { value: null, enumerable: false }, 42 _iframeHolder: { value: null, enumerable: false },
@@ -44,8 +48,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
44 return this._activeDocument; 48 return this._activeDocument;
45 }, 49 },
46 set: function(doc) { 50 set: function(doc) {
47 if(!!this._activeDocument){ this._activeDocument.isActive = false;} 51// if(!!this._activeDocument){ this._activeDocument.isActive = false;}
52
48 this._activeDocument = doc; 53 this._activeDocument = doc;
54
49 if(!!this._activeDocument){ 55 if(!!this._activeDocument){
50 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 56 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
51 this._activeDocument.isActive = true; 57 this._activeDocument.isActive = true;
@@ -213,13 +219,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
213 handleExecuteFileClose:{ 219 handleExecuteFileClose:{
214 value: function(event) { 220 value: function(event) {
215 if (this.activeDocument) { 221 if (this.activeDocument) {
216 this.activeDocument.closeDocument(); 222// this.activeDocument.closeDocument();
223 this.closeFile(this.activeDocument);
217 } 224 }
218 /*
219if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
220 this.closeDocument(this.activeDocument.uuid);
221 }
222*/
223 } 225 }
224 }, 226 },
225 //////////////////////////////////////////////////////////////////// 227 ////////////////////////////////////////////////////////////////////
@@ -448,7 +450,32 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
448 */ 450 */
449 451
450 } 452 }
451 }, 453 },
454
455 closeFile: {
456 value: function(document) {
457 document.closeDocument(this, this.onCloseFile);
458 }
459 },
460
461 onCloseFile: {
462 value: function(doc) {
463
464 this._documents.splice(this._documents.indexOf(doc), 1);
465
466 this.activeDocument = null;
467
468 this.application.ninja.stage.stageView.hideRulers();
469
470// document.getElementById("iframeContainer").style.display="block";
471
472 this.application.ninja.stage.hideCanvas(true);
473
474
475 NJevent("closeDocument", doc.model.file.uri);
476 //TODO: Delete object here
477 }
478 },
452 479
453 closeDocument: { 480 closeDocument: {
454 value: function(id) { 481 value: function(id) {
@@ -468,15 +495,7 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
468 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} 495 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();}
469 this._removeDocumentView(doc.container); 496 this._removeDocumentView(doc.container);
470 }else if(this._documents.length === 0){ 497 }else if(this._documents.length === 0){
471 if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ 498 // See above
472 this.activeDocument.pauseAndStopVideos();
473 }
474 this.activeDocument = null;
475 this._removeDocumentView(doc.container);
476 this.application.ninja.stage.stageView.hideRulers();
477 document.getElementById("iframeContainer").style.display="block";
478
479 this.application.ninja.stage.hideCanvas(true);
480 }else{//closing inactive document tab - just clear DOM 499 }else{//closing inactive document tab - just clear DOM
481 if(typeof doc.pauseAndStopVideos !== "undefined"){ 500 if(typeof doc.pauseAndStopVideos !== "undefined"){
482 doc.pauseAndStopVideos(); 501 doc.pauseAndStopVideos();
@@ -515,6 +534,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
515 534
516 this.application.ninja.stage.stageView.showCodeViewBar(false); 535 this.application.ninja.stage.stageView.showCodeViewBar(false);
517 this.application.ninja.stage.stageView.restoreAllPanels(); 536 this.application.ninja.stage.stageView.restoreAllPanels();
537
538 // Flag to stop stylesheet dirty event
539 this._hackInitialStyles = false;
518 } 540 }
519 }, 541 },
520 542
@@ -552,12 +574,6 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
552 /** 574 /**
553 * VIEW Related Methods 575 * VIEW Related Methods
554 */ 576 */
555 // PUBLIC
556 ShowActiveDocument: {
557 value: function() {
558 this.activeDocument.iframe.style.opacity = 1.0;
559 }
560 },
561 577
562 // PRIVATE 578 // PRIVATE
563 _findDocumentByUUID: { 579 _findDocumentByUUID: {
@@ -656,7 +672,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
656 672
657 handleStyleSheetDirty:{ 673 handleStyleSheetDirty:{
658 value:function(){ 674 value:function(){
659// this.activeDocument.model.needsSave = true; 675 if(!this._hackInitialStyles) {
676 this.activeDocument.model.needsSave = true;
677 }
660 } 678 }
661 }, 679 },
662 680
diff --git a/js/document/document-html.js b/js/document/document-html.js
index 9bbea4c9..87c776d5 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -43,13 +43,6 @@ exports.HtmlDocument = Montage.create(Component, {
43 exclusionList: { 43 exclusionList: {
44 value: ["HTML", "BODY"] //TODO: Update to correct list 44 value: ["HTML", "BODY"] //TODO: Update to correct list
45 }, 45 },
46 ////////////////////////////////////////////////////////////////////
47 //
48 uuid: {
49 get: function() {
50 return this._uuid;
51 }
52 },
53 //////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////
54 // 47 //
55 inExclusion: { 48 inExclusion: {
@@ -133,21 +126,10 @@ exports.HtmlDocument = Montage.create(Component, {
133 //////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////
134 // 127 //
135 closeDocument: { 128 closeDocument: {
136 value: function () { 129 value: function (context, callback) {
137 // 130 var closed = this.model.close(null);
138 this.model.close(null, this.handleCloseDocument.bind(this)); 131
139 } 132 callback.call(context, this);
140 },
141 ////////////////////////////////////////////////////////////////////
142 //
143 handleCloseDocument: {
144 value: function (success) {
145 //TODO: Add logic for handling success or failure
146 //
147 this.application.ninja.documentController._documents.splice(this.uuid, 1);
148 //
149 NJevent("closeDocument", this.model.file.uri);
150 //TODO: Delete object here
151 } 133 }
152 }, 134 },
153 //////////////////////////////////////////////////////////////////// 135 ////////////////////////////////////////////////////////////////////
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 9d083dd8..6a84abdf 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -972,44 +972,5 @@ exports.HTMLDocument = Montage.create(TextDocument, {
972 972
973 973
974 } 974 }
975 },
976 ////////////////////////////////////////////////////////////////////
977 /**
978 *pause videos on switching or closing the document, so that the browser does not keep downloading the media data
979 */
980 pauseVideos:{
981 value:function(){
982 var videosArr = this.documentRoot.getElementsByTagName("video"), i=0;
983 for(i=0;i<videosArr.length;i++){
984 if(!v