From 40622aa97d31837254996b718b0a6feca2bcd0ce Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 8 Feb 2012 14:41:10 -0800 Subject: Styles Controller - added methods to get keyframe animation rules --- js/controllers/styles-controller.js | 44 +++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 011caec5..ff59c8f8 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -179,10 +179,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { this.styleSheetModified(stylesheet); rule = stylesheet.rules[index]; - + ///// 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); - + ///// return the rule we just inserted return rule; } @@ -840,6 +844,27 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Animation Rule With Name + ///// Returns the CSSKeyframesRule with given name + + getAnimationRuleWithName : { + value: function(name) { + var sheets = this._activeDocument._document.styleSheets, + rules, i, j, rule; + + for(i = 0; i < sheets.length; i++) { + rules = sheets[i].rules; + for(j = 0; j < rules.length; j++) { + rule = rules[j]; + if(rule instanceof WebKitCSSKeyframesRule && rule.name === name) { + return rule; + } + } + } + + return; + } + }, ///// Delete style ///// Removes the property from the style declaration/rule @@ -1045,6 +1070,21 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Element Animation Rule + ///// Returns the CSSKeyframesRule applied to an element + + getElementAnimationRule : { + value: function(element) { + var animationName = this.getElementStyle(element, '-webkit-animation-name'); + + if(!animationName) { + return null; + } + + return this.getAnimationRuleWithName(animationName); + } + }, + ///// Create Rule From Inline Style ///// Creates a rule for an inline style with a specified, or partially random selector. -- cgit v1.2.3 From a30d76ff641ce89686cf5fbd9f04ac9ab4e9c830 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 10 Feb 2012 17:21:28 -0800 Subject: initial color chip for the stage Signed-off-by: Valerio Virgillito --- js/controllers/elements/stage-controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/elements/stage-controller.js b/js/controllers/elements/stage-controller.js index b8170826..e9fc6bce 100644 --- a/js/controllers/elements/stage-controller.js +++ b/js/controllers/elements/stage-controller.js @@ -75,6 +75,8 @@ exports.StageController = Montage.create(ElementController, { getProperty: { value: function(el, p) { switch(p) { + case "background" : + return el.elementModel.stageBackground.style.getProperty(p); case "border": return el.elementModel.stageView.style.getProperty(p); case "height": @@ -92,7 +94,8 @@ exports.StageController = Montage.create(ElementController, { value: function(el, p, value) { switch(p) { case "background": - el.elementModel.body.style.setProperty(p, value); + console.log(value); + el.elementModel.stageBackground.style.setProperty(p, value); break; case "overflow": el.elementModel.viewPort.style.setProperty(p, value); -- cgit v1.2.3 From 0d7d6d4d98437a93f31ededa14ca6eb5382c9e58 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 13 Feb 2012 14:05:10 -0800 Subject: Cleaning up the stage background color chip. Signed-off-by: Valerio Virgillito --- js/controllers/elements/stage-controller.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/elements/stage-controller.js b/js/controllers/elements/stage-controller.js index e9fc6bce..af7c4858 100644 --- a/js/controllers/elements/stage-controller.js +++ b/js/controllers/elements/stage-controller.js @@ -94,7 +94,6 @@ exports.StageController = Montage.create(ElementController, { value: function(el, p, value) { switch(p) { case "background": - console.log(value); el.elementModel.stageBackground.style.setProperty(p, value); break; case "overflow": -- cgit v1.2.3 From a738121a921e4c721b280434952b415b9ab3b1a8 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 13 Feb 2012 15:18:55 -0800 Subject: Styles Controller - Separate css animation rule getters To add document- and sheet-specific getters. --- js/controllers/styles-controller.js | 58 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index ff59c8f8..44ca50e1 100644 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -128,7 +128,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { } else { this._defaultStylesheet = sheets[lastIndex]; } - + } } }, @@ -848,17 +848,15 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Returns the CSSKeyframesRule with given name getAnimationRuleWithName : { - value: function(name) { - var sheets = this._activeDocument._document.styleSheets, - rules, i, j, rule; - - for(i = 0; i < sheets.length; i++) { - rules = sheets[i].rules; - for(j = 0; j < rules.length; j++) { - rule = rules[j]; - if(rule instanceof WebKitCSSKeyframesRule && rule.name === name) { - return rule; - } + value: function(name, document) { + var doc = document || this._activeDocument._document, + animRules = this.getDocumentAnimationRules(doc), + rule, i; + + for(i = 0; i < animRules.length; i++) { + rule = animRules[i]; + if(rule.name === name) { + return rule; } } @@ -866,6 +864,42 @@ var stylesController = exports.StylesController = Montage.create(Component, { } }, + ///// Get Document Animation Rules + ///// Returns all CSSKeyframesRules in active document, or in + ///// optionally passed-in document + ///// If none are found, returns an empty array + + getDocumentAnimationRules : { + value: function(document) { + var sheets = (document) ? document.styleSheets : this._activeDocument._document.styleSheets, + rules = []; + + nj.toArray(sheets).forEach(function(sheet) { + rules = rules.concat(this.getStyleSheetAnimationRules(sheet)); + }, this); + + return rules; + } + }, + + ///// Get Style Sheet Animation Rules + ///// Returns all CSSKeyframesRules from the given stylesheet + ///// If none are found, returns an empty array + + getStyleSheetAnimationRules : { + value: function(sheet) { + var rules = []; + + if(sheet.rules) { + rules = rules.concat(nj.toArray(sheet.rules).filter(function(rule) { + return rule instanceof WebKitCSSKeyframesRule; + })); + } + + return rules; + } + }, + ///// Delete style ///// Removes the property from the style declaration/rule ///// Returns the rule -- cgit v1.2.3