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/styles-controller.js') 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 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/styles-controller.js') 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