diff options
author | Valerio Virgillito | 2012-02-13 15:53:06 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-13 15:53:06 -0800 |
commit | 30b23f8d0343c1af805d62894591001f19c6fb79 (patch) | |
tree | 79a88684406d3adf00350246a4da884b97fb0eac /js/controllers | |
parent | 0620e2f788861e824d6e49fa319da4d20b18a556 (diff) | |
parent | b2672478decd3ee3bfacf86b525551c997f9604d (diff) | |
download | ninja-30b23f8d0343c1af805d62894591001f19c6fb79.tar.gz |
Merge pull request #38 from ericguzman/StylesControllerUpdates
Styles controller updates
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/styles-controller.js | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 44e0e798..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, { | |||
128 | } else { | 128 | } else { |
129 | this._defaultStylesheet = sheets[lastIndex]; | 129 | this._defaultStylesheet = sheets[lastIndex]; |
130 | } | 130 | } |
131 | 131 | ||
132 | } | 132 | } |
133 | } | 133 | } |
134 | }, | 134 | }, |
@@ -179,14 +179,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
179 | this.styleSheetModified(stylesheet); | 179 | this.styleSheetModified(stylesheet); |
180 | 180 | ||
181 | rule = stylesheet.rules[index]; | 181 | rule = stylesheet.rules[index]; |
182 | 182 | ||
183 | ///// attach specificity to rule object | 183 | ///// attach specificity to rule object |
184 | // if rule is css keyframes, return rule and don't attach specificity | 184 | ///// if rule is css keyframes, return rule and don't attach specificity |
185 | if (rule instanceof WebKitCSSKeyframesRule) { | 185 | if (rule instanceof WebKitCSSKeyframesRule) { |
186 | return rule; | 186 | return rule; |
187 | } | 187 | } |
188 | rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); | 188 | rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); |
189 | 189 | ||
190 | ///// return the rule we just inserted | 190 | ///// return the rule we just inserted |
191 | return rule; | 191 | return rule; |
192 | } | 192 | } |
@@ -844,6 +844,61 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
844 | } | 844 | } |
845 | }, | 845 | }, |
846 | 846 | ||
847 | ///// Get Animation Rule With Name | ||
848 | ///// Returns the CSSKeyframesRule with given name | ||
849 | |||
850 | getAnimationRuleWithName : { | ||
851 | value: function(name, document) { | ||
852 | var doc = document || this._activeDocument._document, | ||
853 | animRules = this.getDocumentAnimationRules(doc), | ||
854 | rule, i; | ||
855 | |||
856 | for(i = 0; i < animRules.length; i++) { | ||
857 | rule = animRules[i]; | ||
858 | if(rule.name === name) { | ||
859 | return rule; | ||
860 | } | ||
861 | } | ||
862 | |||
863 | return; | ||
864 | } | ||
865 | }, | ||
866 | |||
867 | ///// Get Document Animation Rules | ||
868 | ///// Returns all CSSKeyframesRules in active document, or in | ||
869 | ///// optionally passed-in document | ||
870 | ///// If none are found, returns an empty array | ||
871 | |||
872 | getDocumentAnimationRules : { | ||
873 | value: function(document) { | ||
874 | var sheets = (document) ? document.styleSheets : this._activeDocument._document.styleSheets, | ||
875 | rules = []; | ||
876 | |||
877 | nj.toArray(sheets).forEach(function(sheet) { | ||
878 | rules = rules.concat(this.getStyleSheetAnimationRules(sheet)); | ||
879 | }, this); | ||
880 | |||
881 | return rules; | ||
882 | } | ||
883 | }, | ||
884 | |||
885 | ///// Get Style Sheet Animation Rules | ||
886 | ///// Returns all CSSKeyframesRules from the given stylesheet | ||
887 | ///// If none are found, returns an empty array | ||
888 | |||
889 | getStyleSheetAnimationRules : { | ||
890 | value: function(sheet) { | ||
891 | var rules = []; | ||
892 | |||
893 | if(sheet.rules) { | ||
894 | rules = rules.concat(nj.toArray(sheet.rules).filter(function(rule) { | ||
895 | return rule instanceof WebKitCSSKeyframesRule; | ||
896 | })); | ||
897 | } | ||
898 | |||
899 | return rules; | ||
900 | } | ||
901 | }, | ||
847 | 902 | ||
848 | ///// Delete style | 903 | ///// Delete style |
849 | ///// Removes the property from the style declaration/rule | 904 | ///// Removes the property from the style declaration/rule |
@@ -1049,6 +1104,21 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
1049 | } | 1104 | } |
1050 | }, | 1105 | }, |
1051 | 1106 | ||
1107 | ///// Get Element Animation Rule | ||
1108 | ///// Returns the CSSKeyframesRule applied to an element | ||
1109 | |||
1110 | getElementAnimationRule : { | ||
1111 | value: function(element) { | ||
1112 | var animationName = this.getElementStyle(element, '-webkit-animation-name'); | ||
1113 | |||
1114 | if(!animationName) { | ||
1115 | return null; | ||
1116 | } | ||
1117 | |||
1118 | return this.getAnimationRuleWithName(animationName); | ||
1119 | } | ||
1120 | }, | ||
1121 | |||
1052 | ///// Create Rule From Inline Style | 1122 | ///// Create Rule From Inline Style |
1053 | ///// Creates a rule for an inline style with a specified, or partially random selector. | 1123 | ///// Creates a rule for an inline style with a specified, or partially random selector. |
1054 | 1124 | ||