From a402ae19732f7aeb53de27e3f25f72e9c42a453c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 16 Jul 2012 14:50:50 -0700 Subject: New: Added switching view functionality to document UI This now let's you switch between code and design views in all documents opened that support design view. Code view for these documents is currently unsupported, so this is just to hook up the UI to the new methods. Code view will be added next. --- js/controllers/document-controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 588481bb..5020e27d 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -68,7 +68,7 @@ exports.DocumentController = Montage.create(Component, { return; } - if(this._currentDocument) { + if(this._currentDocument && this._currentDocument.model.currentView) { this._currentDocument.model.currentView.hide(); } @@ -80,12 +80,12 @@ exports.DocumentController = Montage.create(Component, { } else if(this._currentDocument.currentView === "design") { document.getElementById("codeViewContainer").style.display = "none"; document.getElementById("iframeContainer").style.display = "block"; - this._currentDocument.model.currentView.show(); + if (this._currentDocument.model.currentView) this._currentDocument.model.currentView.show(); this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*'); } else { document.getElementById("iframeContainer").style.display = "none"; this._currentDocument.model.parentContainer.style["display"] = "block"; - this._currentDocument.model.currentView.show(); + if (this._currentDocument.model.currentView) this._currentDocument.model.currentView.show(); } } -- cgit v1.2.3 From d799a03a52fbf4eaad4e469fabbf84c9bf2cb41d Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 18 Jul 2012 12:26:08 -0700 Subject: parameterize the parentContainer for text document Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 5020e27d..ee7ca82c 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -356,7 +356,7 @@ exports.DocumentController = Montage.create(Component, { break; default: //Open in code view - Montage.create(TextDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'code'); + Montage.create(TextDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'code', document.getElementById("codeViewContainer")); break; } } -- cgit v1.2.3 From db4f235dc9fd6f2242dee481d2f377005cf23596 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 24 Jul 2012 16:56:52 -0700 Subject: adding a viewIdentifier to the model to enable design/code switch Todo: - Cleanup and remove listeners - Finish stage reload - Add remaining bindings. Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 18 ++++++++++++++++++ js/controllers/styles-controller.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index ee7ca82c..83c1f58c 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -80,6 +80,7 @@ exports.DocumentController = Montage.create(Component, { } else if(this._currentDocument.currentView === "design") { document.getElementById("codeViewContainer").style.display = "none"; document.getElementById("iframeContainer").style.display = "block"; + this._currentDocument.addPropertyChangeListener("model.currentViewIdentifier", this, false); if (this._currentDocument.model.currentView) this._currentDocument.model.currentView.show(); this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*'); } else { @@ -91,6 +92,23 @@ exports.DocumentController = Montage.create(Component, { } }, + handleChange: { + value: function(notification) { + if(notification.currentPropertyPath === "model.currentViewIdentifier") { + if(this.currentDocument.model.currentView.identifier === "design-code") { +// document.getElementById("iframeContainer").style.display = "none"; +// this._currentDocument.model.parentContainer.style["display"] = "block"; +// if (this._currentDocument.model.currentView) this._currentDocument.model.currentView.show(); + } else { + document.getElementById("codeViewContainer").style.display = "none"; + document.getElementById("iframeContainer").style.display = "block"; + if (this._currentDocument.model.currentView) this._currentDocument.model.currentView.show(); + this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*'); + } + } + } + }, + deserializedFromTemplate: { value: function() { //TODO: Add event naming consistency (save, fileOpen and newFile should be consistent, all file events should be executeFile[operation name]) this.eventManager.addEventListener("appLoaded", this, false); diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 21321f6d..0e1df1e9 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -99,6 +99,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// setting document via binding this._currentDocument = document; + this._currentDocument.addPropertyChangeListener("model.currentViewIdentifier", this, false); + ///// Stage stylesheet should always be found this._stageStylesheet = this.getSheetFromElement(this.CONST.STAGE_SHEET_ID); // Returns null if sheet not found (as in non-ninja projects) @@ -126,6 +128,38 @@ var stylesController = exports.StylesController = Montage.create(Component, { enumerable : false }, + handleChange: { + value: function(notification) { + if(notification.currentPropertyPath === "model.currentViewIdentifier") { + if(this.currentDocument.model.currentView.identifier === "design") { + ///// Stage stylesheet should always be found + this._stageStylesheet = this.getSheetFromElement(this.CONST.STAGE_SHEET_ID); + // Returns null if sheet not found (as in non-ninja projects) + // Setter will handle null case + this.defaultStylesheet = this.getSheetFromElement(this.CONST.DEFAULT_SHEET_ID); + + this.userStyleSheets = nj.toArray(this.currentDocument.model.views.design.document.styleSheets).filter(function(sheet) { + if(sheet === this._stageStylesheet) { return false; } + + var media = sheet.ownerNode.getAttribute('media'); + + ///// If the media attribute contains a query, we'll watch for changes in media + if(/\([0-9A-Za-z-: ]+\)/.test(media)) { + this.watchMedia(media); + } + + return true; + + }, this); + + this.initializeRootStyles(); + + NJevent('styleSheetsReady', this); + } + } + } + }, + _mediaList : { value: [] }, -- cgit v1.2.3 From e7509af2b2fad6ab23ea07e6e46e88a4ee0d03f1 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 25 Jul 2012 12:29:16 -0700 Subject: adding null check for currentDocument to prevent error Signed-off-by: Ananya Sen --- js/controllers/styles-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 0e1df1e9..e95c6614 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -131,7 +131,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { handleChange: { value: function(notification) { if(notification.currentPropertyPath === "model.currentViewIdentifier") { - if(this.currentDocument.model.currentView.identifier === "design") { + if(this.currentDocument && this.currentDocument.model.currentView.identifier === "design") { ///// Stage stylesheet should always be found this._stageStylesheet = this.getSheetFromElement(this.CONST.STAGE_SHEET_ID); // Returns null if sheet not found (as in non-ninja projects) -- cgit v1.2.3