You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/05/24 05:37:18 UTC

[2/2] git commit: [flex-asjs] [refs/heads/release0.8.0] - get addRule to work for JS

get addRule to work for JS


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/7b26ee3d
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/7b26ee3d
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/7b26ee3d

Branch: refs/heads/release0.8.0
Commit: 7b26ee3dfc97e2968d6df20fbb5f69185468d821
Parents: 90eda31
Author: Alex Harui <ah...@apache.org>
Authored: Tue May 23 22:36:23 2017 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue May 23 22:37:13 2017 -0700

----------------------------------------------------------------------
 .../org/apache/flex/core/SimpleCSSValuesImpl.as | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7b26ee3d/frameworks/projects/Core/src/main/flex/org/apache/flex/core/SimpleCSSValuesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/SimpleCSSValuesImpl.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/SimpleCSSValuesImpl.as
index 4e1cd47..7965712 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/SimpleCSSValuesImpl.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/SimpleCSSValuesImpl.as
@@ -632,6 +632,10 @@ package org.apache.flex.core
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
+		 *
+		 *  @flexjsignorecoercion HTMLStyleElement
+		 *  @flexjsignorecoercion CSSStyleSheet
+		 *  @flexjsignorecoercion uint
          */
         public function addRule(ruleName:String, values:Object):void
         {
@@ -650,7 +654,40 @@ package org.apache.flex.core
                 asValues[valueName] = v;
             }
             this.values[ruleName] = asValues;
+			COMPILE::JS
+			{
+				if (!ss)
+				{
+					var styleElement:HTMLStyleElement = document.createElement('style') as HTMLStyleElement;
+					document.head.appendChild(styleElement);
+					ss = styleElement.sheet as CSSStyleSheet;
+				}
+				var cssString:String = ruleName + " {"
+				for (var p:String in values)
+				{
+					var value:Object = values[p];
+				    if (typeof(value) === 'function') continue;
+					cssString += p + ": ";
+					if (typeof(value) == 'number') {
+                    	if (colorStyles[p])
+                        	value = CSSUtils.attributeFromColor(value as uint);
+                    	else
+                        	value = value.toString() + 'px';
+                	}
+                	else if (p == 'backgroundImage') {
+                    	if (p.indexOf('url') !== 0)
+                        	value = 'url(' + value + ')';
+                	}
+					cssString += value + ";";
+					
+				}
+				cssString += "}";
+				ss.insertRule(cssString, ss.cssRules.length);
+			}
         }
+		
+		COMPILE::JS
+		private var ss:CSSStyleSheet;
         
         /**
          *  A map of inheriting styles