From 8f4a3e260622cd51dfa93b8dfd765f764c80fa6b 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/styles-controller.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'js/controllers/styles-controller.js') 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