From 919a0d0ed35c24b1047281723ddde2ac98fc9a3e Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 15 May 2012 22:36:44 -0700 Subject: document close handler. initial working draft Signed-off-by: Valerio Virgillito --- .../layout/document-entry.reel/document-entry.js | 2 +- js/controllers/document-controller.js | 66 ++++++++++++++-------- js/document/document-html.js | 26 ++------- js/document/html-document.js | 39 ------------- js/document/models/base.js | 3 +- 5 files changed, 49 insertions(+), 87 deletions(-) (limited to 'js') 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, { handleClick: { value: function(event) { if(event._event.target.nodeName === "IMG") { - this.application.ninja.documentController.closeDocument(this._uuid); + this.application.ninja.documentController.closeFile(this.application.ninja.documentController._findDocumentByUUID(this._uuid)); } else { if(!this._document.isActive) { 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, value: false }, + _hackInitialStyles: { + value: true + }, + _activeDocument: { value: null }, _iframeCounter: { value: 1, enumerable: false }, _iframeHolder: { value: null, enumerable: false }, @@ -44,8 +48,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return this._activeDocument; }, set: function(doc) { - if(!!this._activeDocument){ this._activeDocument.isActive = false;} +// if(!!this._activeDocument){ this._activeDocument.isActive = false;} + this._activeDocument = doc; + if(!!this._activeDocument){ if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument.isActive = true; @@ -213,13 +219,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileClose:{ value: function(event) { if (this.activeDocument) { - this.activeDocument.closeDocument(); +// this.activeDocument.closeDocument(); + this.closeFile(this.activeDocument); } - /* -if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ - this.closeDocument(this.activeDocument.uuid); - } -*/ } }, //////////////////////////////////////////////////////////////////// @@ -448,7 +450,32 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ */ } - }, + }, + + closeFile: { + value: function(document) { + document.closeDocument(this, this.onCloseFile); + } + }, + + onCloseFile: { + value: function(doc) { + + this._documents.splice(this._documents.indexOf(doc), 1); + + this.activeDocument = null; + + this.application.ninja.stage.stageView.hideRulers(); + +// document.getElementById("iframeContainer").style.display="block"; + + this.application.ninja.stage.hideCanvas(true); + + + NJevent("closeDocument", doc.model.file.uri); + //TODO: Delete object here + } + }, closeDocument: { value: function(id) { @@ -468,15 +495,7 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} this._removeDocumentView(doc.container); }else if(this._documents.length === 0){ - if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ - this.activeDocument.pauseAndStopVideos(); - } - 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); + // See above }else{//closing inactive document tab - just clear DOM if(typeof doc.pauseAndStopVideos !== "undefined"){ doc.pauseAndStopVideos(); @@ -515,6 +534,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ this.application.ninja.stage.stageView.showCodeViewBar(false); this.application.ninja.stage.stageView.restoreAllPanels(); + + // Flag to stop stylesheet dirty event + this._hackInitialStyles = false; } }, @@ -552,12 +574,6 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ /** * VIEW Related Methods */ - // PUBLIC - ShowActiveDocument: { - value: function() { - this.activeDocument.iframe.style.opacity = 1.0; - } - }, // PRIVATE _findDocumentByUUID: { @@ -656,7 +672,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ handleStyleSheetDirty:{ value:function(){ -// this.activeDocument.model.needsSave = true; + if(!this._hackInitialStyles) { + this.activeDocument.model.needsSave = true; + } } }, 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 @@ -42,13 +42,6 @@ exports.HtmlDocument = Montage.create(Component, { // exclusionList: { value: ["HTML", "BODY"] //TODO: Update to correct list - }, - //////////////////////////////////////////////////////////////////// - // - uuid: { - get: function() { - return this._uuid; - } }, //////////////////////////////////////////////////////////////////// // @@ -133,21 +126,10 @@ exports.HtmlDocument = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // closeDocument: { - value: function () { - // - this.model.close(null, this.handleCloseDocument.bind(this)); - } - }, - //////////////////////////////////////////////////////////////////// - // - handleCloseDocument: { - value: function (success) { - //TODO: Add logic for handling success or failure - // - this.application.ninja.documentController._documents.splice(this.uuid, 1); - // - NJevent("closeDocument", this.model.file.uri); - //TODO: Delete object here + value: function (context, callback) { + var closed = this.model.close(null); + + callback.call(context, this); } }, //////////////////////////////////////////////////////////////////// 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 @@ -971,45 +971,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { this.application.ninja.undocontroller.redoQueue = this.redoStack.slice(0); - } - }, - //////////////////////////////////////////////////////////////////// - /** - *pause videos on switching or closing the document, so that the browser does not keep downloading the media data - */ - pauseVideos:{ - value:function(){ - var videosArr = this.documentRoot.getElementsByTagName("video"), i=0; - for(i=0;i