From a5ee11857f923d3e49b44c0a8c480e9d0b026d5b Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 22 Feb 2012 23:18:12 -0800 Subject: CSS Panel Update --- js/controllers/styles-controller.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 44ca50e1..aa5a4e7f 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -94,11 +94,18 @@ var stylesController = exports.StylesController = Montage.create(Component, { // 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); - - //debugger; + + this.userStyleSheets = nj.toArray(document._document.styleSheets).filter(function(sheet) { + return sheet !== this._stageStylesheet; + }, this); + + NJevent('styleSheetsReady', this); }, enumerable : false }, + userStyleSheets : { + value : null + }, _stageStylesheet : { value : null }, -- cgit v1.2.3 From 1433f2bdf2e5b8c5c18fed5e9c17fd983ab3606d Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 2 Mar 2012 10:55:51 -0800 Subject: CSS Panel - Updating components, created toolbar components, and small changes to styles controller --- js/controllers/styles-controller.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 33084169..d36c8cb9 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -190,6 +190,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// attach specificity to rule object ///// if rule is css keyframes, return rule and don't attach specificity if (rule instanceof WebKitCSSKeyframesRule) { + return rule; } rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); @@ -1184,6 +1185,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.styleSheetModified(sheet); + NJevent('newStyleSheet', sheet); + return sheet; } }, @@ -1243,11 +1246,16 @@ var stylesController = exports.StylesController = Montage.create(Component, { clearDirtyStyleSheets : { value: function(doc) { - if(!doc) { + this.dirtyStyleSheets.length = 0; + + if(doc) { this.dirtyStyleSheets = null; - this.dirtyStyleSheets = []; + this.dirtyStyleSheets = this.dirtyStyleSheets.filter(function(sheet) { + return sheet.document !== doc; + }); } + } }, -- cgit v1.2.3 From 9617e4d3870c9872dc1837a67a6f927fd2680476 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 1 May 2012 16:23:43 -0700 Subject: Styles Controller - Fix error when trying dispatch stylesheet change event --- js/controllers/styles-controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index f7c98023..3422427c 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -803,7 +803,9 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// method to apply/test the new value dec.setProperty(property, value, priority); - this.styleSheetModified(rule.parentStyleSheet); + if(rule.parentStyleSheet) { + this.styleSheetModified(rule.parentStyleSheet); + } ///// Return browser value for value we just set return dec.getPropertyValue(property); -- cgit v1.2.3 From a62f57cf6beee332ff60a48f5e26d0084b4a5432 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 7 May 2012 10:38:29 -0700 Subject: Style sheets - Add sheet action --- js/controllers/styles-controller.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 3422427c..dfe7c69a 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1252,6 +1252,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { doc.head.appendChild(sheetElement); sheet = this.getSheetFromElement(sheetElement, doc); + this.userStyleSheets.push(sheet); + this.styleSheetModified(sheet); NJevent('newStyleSheet', sheet); -- cgit v1.2.3 From 0cbfa32fa4e62be128b6478dcba0aa9db902f78b Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 9 May 2012 18:23:17 -0700 Subject: Styles Controller - Added fix for setting style on cached, multi-target rule. Added fix for setting style on cached, multi-target rule. Also added parameter to selector override to augment specificity of selector --- js/controllers/styles-controller.js | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index dfe7c69a..02c3dad9 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -217,10 +217,12 @@ var stylesController = exports.StylesController = Montage.create(Component, { } var selectorToOverride = getSelector.bind(this)(element, ruleToOverride), - overrideData, rule; + overrideData, rule, isRuleLocked; + + isRuleLocked = this.isSheetLocked(ruleToOverride.parentStyleSheet); ///// Get the overriding selector and className - overrideData = this.createOverrideSelector(selectorToOverride, element.nodeName); + overrideData = this.createOverrideSelector(selectorToOverride, element.nodeName, isRuleLocked); ///// Create new rule with selector and insert it after the rule we're overriding rule = this.addRule(overrideData.selector + ' { }', this.getRuleIndex(ruleToOverride)+1); @@ -234,7 +236,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, createOverrideSelector : { - value: function(selectorToOverride, classPrefix, className) { + value: function(selectorToOverride, classPrefix, increaseSpecificity, className) { var tokens = selectorToOverride.split(/\s/), newClass = className || this.generateClassName(classPrefix, true), lastToken, pseudoSplit, base, pseudo, newToken, newSelector; @@ -255,10 +257,19 @@ var stylesController = exports.StylesController = Montage.create(Component, { if(base.indexOf('#') !== -1) { newToken = base + '.' + newClass + pseudo; } else { - ///// Replace last class or attribute selector - ///// Get everything right before the last class or attribute selector - ///// to support compound selector values: (i.e. .firstClass.secondClass) - newToken = base.substring(0, Math.max(base.lastIndexOf('.'), base.lastIndexOf('['))); + if(increaseSpecificity) { + ///// Increases specificity by one class selector + ///// We'll do a direct append to the base class + ///// if we want to increase the specificity + newToken = base; + } else { + ///// Maintains original specificity + ///// Replace last class or attribute selector + ///// Get everything right before the last class or attribute selector + ///// to support compound selector values: (i.e. .firstClass.secondClass) + newToken = base.substring(0, Math.max(base.lastIndexOf('.'), base.lastIndexOf('['))); + } + ///// Append the generated class newToken += '.' + newClass + pseudo; } @@ -979,12 +990,13 @@ var stylesController = exports.StylesController = Montage.create(Component, { var doc = element.ownerDocument, useImportant = false, cache = this._getCachedRuleForProperty(element, property), - dominantRule, override, className, browserValue; + dominantRule, override, className, browserValue, cacheMatchesMany; if(cache) { ///// We've cached the rule for this property! //console.log('Styles Controller :: setElementStyle - We found the cached rule!'); dominantRule = cache; + cacheMatchesMany = this.matchesMultipleElements(dominantRule, doc); } else { ///// Use Dominant Rule logic to find the right place to add the style ///// Pass "true" to method to return an override object, which @@ -992,7 +1004,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); } - + ///// Did we find a dominant rule? if(!dominantRule) { ///// No. This means there was no rule with this property, and no @@ -1010,6 +1022,13 @@ var stylesController = exports.StylesController = Montage.create(Component, { useImportant = dominantRule.useImportant; dominantRule = override.rule; this.addClass(element, override.className); + } else if(cacheMatchesMany) { + ///// Only happens when the cached rule applies to multiple + ///// elements - we must create override + override = this.createOverrideRule(dominantRule, element); + useImportant = !!dominantRule.style.getPropertyPriority(property); + dominantRule = override.rule; + this.addClass(element, override.className); } @@ -1017,7 +1036,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { browserValue = this.setStyle(dominantRule, property, value, useImportant); ///// Only cache the dominant rule if the style value was valid, and not already cached - if(browserValue && !cache) { + if(browserValue && (!cache || cacheMatchesMany)) { this._setCachedRuleForProperty(element, property, dominantRule); } @@ -1280,6 +1299,12 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + isSheetLocked : { + value: function(sheet) { + return !!sheet.ownerNode.dataset['ninjaFileReadOnly']; + } + }, + ///// 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 5164c2415c8a0750c21299325bb1caa8a97fc5b5 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 16 May 2012 14:10:14 -0700 Subject: Styles Controller - Fix issue with clearing dirty stylesheet list --- js/controllers/styles-controller.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index cbc00676..60b2ca92 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1345,7 +1345,6 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.dirtyStyleSheets.length = 0; if(doc) { - this.dirtyStyleSheets = null; this.dirtyStyleSheets = this.dirtyStyleSheets.filter(function(sheet) { return sheet.document !== doc; }); -- cgit v1.2.3 From b5439f436cac405c4bbf7e01ead9cee5dbc71a73 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 16 May 2012 16:04:00 -0700 Subject: CSS Panel - Style sheets dirty flag added --- js/controllers/styles-controller.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 60b2ca92..22f29bd8 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1315,6 +1315,9 @@ var stylesController = exports.StylesController = Montage.create(Component, { return sheetObj.stylesheet === sheet; }); + ///// Dispatch modified event + NJevent('styleSheetModified', eventData); + ///// 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) { @@ -1348,6 +1351,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.dirtyStyleSheets = this.dirtyStyleSheets.filter(function(sheet) { return sheet.document !== doc; }); + } else { + this.dirtyStyleSheets = []; } -- cgit v1.2.3 From 4e43fe2c97833c0847a53484c9589697e64137dc Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Thu, 17 May 2012 16:05:26 -0700 Subject: Styles Controller - Null out active document --- js/controllers/styles-controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 22f29bd8..c8b9376e 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -83,6 +83,11 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// If the document is null set default stylesheets to null if(!document) { + this._activeDocument = null; + this._stageStylesheet = null; + this.defaultStylesheet = null; + this.userStyleSheets = []; + this.clearDirtyStyleSheets(); return false; } @@ -120,7 +125,10 @@ var stylesController = exports.StylesController = Montage.create(Component, { if(sheet) { this._defaultStylesheet = sheet; } else { - + if(sheet === null) { + this._defaultStylesheet = null; + return false; + } ///// Use the last stylesheet in the document as the default var sheets = this._activeDocument._document.styleSheets, -- cgit v1.2.3 From 197a7646e472fcea616764685c8d03c6063e66f5 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 18 May 2012 14:05:06 -0700 Subject: CSS Panel - Add support for deleting style sheets --- js/controllers/styles-controller.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index f6977a00..c5076771 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -821,7 +821,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// method to apply/test the new value dec.setProperty(property, value, priority); - if(rule.parentStyleSheet) { + if(rule.type !== 'inline' && rule.parentStyleSheet) { this.styleSheetModified(rule.parentStyleSheet); } @@ -1289,6 +1289,27 @@ var stylesController = exports.StylesController = Montage.create(Component, { return sheet; } }, + + ///// Remove Style sheet + ///// Removes style sheet from document + + removeStyleSheet : { + value: function(sheet) { + var sheetEl = sheet.ownerNode; + + if(sheetEl) { + sheetEl.disabled = true; + this.userStyleSheets.splice(this.userStyleSheets.indexOf(sheet), 1); + + ///// Mark for removal for i/o + sheetEl.setAttribute('data-ninja-remove', 'true'); + + NJevent('removeStyleSheet', sheet); + } + + + } + }, ///// Gets the stylesheet object associated with passed-in ///// element or element id, with option context (document) -- cgit v1.2.3 From 4553f48aa17024922569faea1f62e9251a0c0185 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 18 May 2012 14:35:09 -0700 Subject: Style sheets - Add support for removing default style sheet --- js/controllers/styles-controller.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index c5076771..00d67b89 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -173,13 +173,17 @@ var stylesController = exports.StylesController = Montage.create(Component, { addRule : { value : function(selector, declaration, stylesheet, index) { - //console.log("Add rule"); + stylesheet = stylesheet || this._defaultStylesheet; + + if(stylesheet === null) { + stylesheet = this.defaultStylesheet = this.createStylesheet(); + } + var rulesLength = this._defaultStylesheet.rules.length, argType = (typeof declaration), ruleText = selector, - stylesheet = stylesheet || this._defaultStylesheet, - property, rule; - + rule; + index = index || (argType === 'number') ? declaration : rulesLength; if(argType === 'string') { @@ -1295,12 +1299,18 @@ var stylesController = exports.StylesController = Montage.create(Component, { removeStyleSheet : { value: function(sheet) { - var sheetEl = sheet.ownerNode; + var sheetEl = sheet.ownerNode, sheetCount; if(sheetEl) { sheetEl.disabled = true; this.userStyleSheets.splice(this.userStyleSheets.indexOf(sheet), 1); + ///// Check to see if we're removing the default style sheet + if(sheet === this._defaultStylesheet) { + sheetCount = this.userStyleSheets.length; + this.defaultStylesheet = (sheetCount) ? this.userStyleSheets[sheetCount-1] : null; + } + ///// Mark for removal for i/o sheetEl.setAttribute('data-ninja-remove', 'true'); -- cgit v1.2.3 From deb312310c4e031da62afa6e2520c192ad6e4990 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 22 May 2012 15:58:02 -0700 Subject: CSS Panel - Merged Styles controller from DOM Architecture --- js/controllers/styles-controller.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'js/controllers/styles-controller.js') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 00d67b89..dcbe0eaf 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -128,21 +128,23 @@ var stylesController = exports.StylesController = Montage.create(Component, { this._defaultStylesheet = null; return false; } - ///// Use the last stylesheet in the document as the default - - var sheets = this._activeDocument._document.styleSheets, - lastIndex = sheets.length-1; - - ///// If the only sheet is the stage stylesheet, this will be true - ///// in which case, we want to create a stylesheet to hold the - ///// user's style rules - - if(sheets[lastIndex] === this._stageStyleSheet) { - this._defaultStylesheet = this.createStylesheet('nj-default'); - } else { - this._defaultStylesheet = sheets[lastIndex]; - } + //check that the document has a design view + else if(this._activeDocument.model && this._activeDocument.model.views && this._activeDocument.model.views.design){ + ///// Use the last stylesheet in the document as the default + var sheets = this._activeDocument._document.styleSheets, + lastIndex = sheets.length-1; + + ///// If the only sheet is the stage stylesheet, this will be true + ///// in which case, we want to create a stylesheet to hold the + ///// user's style rules + + if(sheets[lastIndex] === this._stageStyleSheet) { + this._defaultStylesheet = this.createStylesheet('nj-default'); + } else { + this._defaultStylesheet = sheets[lastIndex]; + } + } } } }, -- cgit v1.2.3