From bc7ffffb2bac3bf09d17d855d32a5f0d154fab3b Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 17 Jul 2012 18:40:24 -0700 Subject: Styles Controller - Re-add dirty event. Add data- attribute to keep created stylesheets. --- js/controllers/styles-controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 89a389a4..8639bed1 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1405,7 +1405,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { rel : 'stylesheet', id : id || "", media : 'screen', - title : 'Temp' + title : 'Temp', + 'data-ninja-node' : 'true' }); doc.head.appendChild(sheetElement); @@ -1486,6 +1487,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// If the sheet doesn't already exist in the list of modified ///// sheets, dispatch dirty event and add the sheet to the list if(sheetSearch.length === 0) { + NJevent('styleSheetDirty', eventData); this.dirtyStyleSheets.push({ document : sheet.ownerNode.ownerDocument, stylesheet : sheet -- cgit v1.2.3 From 36be3f52a0eaf176213f4d46056e684e0a1b7653 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 18 Jul 2012 17:11:40 -0700 Subject: Style Sheets - Show dirty marker when editing media attribute --- js/controllers/styles-controller.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 8639bed1..87019cad 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1433,6 +1433,9 @@ var stylesController = exports.StylesController = Montage.create(Component, { sheetEl.disabled = true; this.userStyleSheets.splice(this.userStyleSheets.indexOf(sheet), 1); + ///// Make sure cached rules from this stylesheet are not used + this._clearCache(); + ///// Check to see if we're removing the default style sheet if(sheet === this._defaultStylesheet) { sheetCount = this.userStyleSheets.length; @@ -1470,6 +1473,18 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + setMediaAttribute : { + value: function(sheet, mediaString) { + if(sheet.media.mediaText === mediaString) { return false; } + + sheet.ownerNode.setAttribute('media', mediaString); + + this._clearCache(); + + this.styleSheetModified(sheet); + } + }, + ///// Style Sheet Modified ///// Method to call whenever a stylesheet change is made ///// Dispatches an event, and keeps list of dirty style sheets -- cgit v1.2.3 From 8fdf2fc8aefee68aec4c7b5891e0375f704cbf26 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 20 Jul 2012 11:23:39 -0700 Subject: CSS Panel - Fix updating when media changes, sheets are deleted. --- js/controllers/styles-controller.js | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 87019cad..703d61f4 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -106,7 +106,17 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.defaultStylesheet = this.getSheetFromElement(this.CONST.DEFAULT_SHEET_ID); this.userStyleSheets = nj.toArray(document.model.views.design.document.styleSheets).filter(function(sheet) { - return sheet !== this._stageStylesheet; + 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(); @@ -115,6 +125,33 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, enumerable : false }, + + _mediaList : { + value: [] + }, + + watchMedia : { + value: function(mediaQuery, doc) { + var _doc = doc || this._currentDocument.model.views.design.document; + + ///// Set a listener for media changes + _doc.defaultView.matchMedia(mediaQuery).addListener(function(e) { + this.handleMediaChange(e); + }.bind(this)); + } + }, + + handleMediaChange : { + value: function(query) { + this._clearCache(); + + NJevent('mediaChange', { + query: query, + source: "stylesController" + }); + } + }, + userStyleSheets : { value : null }, -- cgit v1.2.3 From 74d3af4650e549afe6cd6bf11ba0bcae89fca602 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 20 Jul 2012 16:31:35 -0700 Subject: CSS Panel - Remove data attribute to remove style tags from document. --- js/controllers/styles-controller.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 11d53ac0..21321f6d 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1516,6 +1516,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Mark for removal for i/o sheetEl.setAttribute('data-ninja-remove', 'true'); + sheetEl.removeAttribute('data-ninja-node'); NJevent('removeStyleSheet', sheet); } -- cgit v1.2.3