flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - add API for adding style rules via code
Date Tue, 25 Aug 2015 04:21:42 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop b1978ca47 -> 453099db9


add API for adding style rules via code


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

Branch: refs/heads/develop
Commit: 453099db9cb48ccbaa99348f2f57dd14f96736ec
Parents: b1978ca
Author: Alex Harui <aharui@apache.org>
Authored: Mon Aug 24 21:21:38 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Aug 24 21:21:38 2015 -0700

----------------------------------------------------------------------
 .../DataBindingExample_as/src/MyInitialView.as  | 39 ++++++++++----------
 .../as/src/org/apache/flex/core/IValuesImpl.as  | 14 +++++++
 .../org/apache/flex/core/SimpleCSSValuesImpl.as | 27 ++++++++++++++
 .../org/apache/flex/core/SimpleValuesImpl.as    | 15 ++++++++
 .../org/apache/flex/core/SimpleCSSValuesImpl.js | 35 ++++++++++++++++++
 5 files changed, 110 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/453099db/examples/flexjs/DataBindingExample_as/src/MyInitialView.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/DataBindingExample_as/src/MyInitialView.as b/examples/flexjs/DataBindingExample_as/src/MyInitialView.as
index 1c31b58..135cb61 100644
--- a/examples/flexjs/DataBindingExample_as/src/MyInitialView.as
+++ b/examples/flexjs/DataBindingExample_as/src/MyInitialView.as
@@ -58,30 +58,29 @@ public class MyInitialView extends ViewBase
         states = statesArray;
         */
         var vi:SimpleCSSValuesImpl = ValuesManager.valuesImpl as SimpleCSSValuesImpl;
-        var viv:Object = vi.values;
-        viv[".output"]= {
-            fontSize: 20
-        };
+        vi.addRule(".output", {
+            "font-size": 20
+        });
         
-        viv[".topContainer"] = {
-            padding: 10
-        };
+        vi.addRule(".topContainer", {
+            "padding": 10
+        });
         
-        viv[".leftSide"] = {
-            verticalAlign: "top",
-            marginRight: 10
-        }
+        vi.addRule(".leftSide", {
+            "vertical-align": "top",
+            "margin-right": 10
+        });
         
-        viv[".rightSide"] = {
-            verticalAlign: "top",
-            marginLeft: 10,
-            paddingLeft: 10
-        }
+        vi.addRule(".rightSide", {
+            "vertical-align": "top",
+            "margin-left": 10,
+            "padding-left": 10
+        });
         
-        viv[".quoteButton"] = {
-            marginTop: 10,
-            marginBottom: 10
-        }
+        vi.addRule(".quoteButton", {
+            "margin-top": 10,
+            "margin-bottom": 10
+        });
         
     }
     

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/453099db/frameworks/projects/Core/as/src/org/apache/flex/core/IValuesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/IValuesImpl.as b/frameworks/projects/Core/as/src/org/apache/flex/core/IValuesImpl.as
index 693e43e..a8c1f1a 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/IValuesImpl.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/IValuesImpl.as
@@ -119,5 +119,19 @@ package org.apache.flex.core
          *  @productversion FlexJS 0.0
          */
         function parseStyles(value:String):Object;
+        
+        /**
+         *  Add a style rule like a class selector.
+         *
+         *  @param ruleName The name of the rule like '.myClassSelector'.
+         *  @param values Name/value pairs.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function addRule(ruleName:String, values:Object):void;
+
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/453099db/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleCSSValuesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleCSSValuesImpl.as b/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleCSSValuesImpl.as
index 68d6882..17bd13a 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleCSSValuesImpl.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleCSSValuesImpl.as
@@ -547,6 +547,33 @@ package org.apache.flex.core
         }
         
         /**
+         *  @copy org.apache.flex.core.IValuesImpl#addRule()
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function addRule(ruleName:String, values:Object):void
+        {
+            var asValues:Object = {};
+            for (var valueName:String in values)
+            {
+                var v:* = values[valueName];
+                var c:int = valueName.indexOf("-");
+                while (c != -1)
+                {
+                    valueName = valueName.substr(0, c) +
+                        valueName.charAt(c + 1).toUpperCase() +
+                        valueName.substr(c + 2);
+                    c = valueName.indexOf("-");
+                }
+                asValues[valueName] = v;
+            }
+            this.values[ruleName] = asValues;
+        }
+        
+        /**
          *  A map of inheriting styles 
          *  
          *  @langversion 3.0

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/453099db/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleValuesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleValuesImpl.as b/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleValuesImpl.as
index 780a0e7..23eec41 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleValuesImpl.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/SimpleValuesImpl.as
@@ -163,5 +163,20 @@ package org.apache.flex.core
             return JSON.parse("{" + value + "}");
         }
 
+        /**
+         *  @copy org.apache.flex.core.IValuesImpl#addRule()
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function addRule(ruleName:String, values:Object):void
+        {
+            // ignore ruleName since all values are global
+            for (var p:String in values)
+                values[p] = values[p];
+        }
+        
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/453099db/frameworks/projects/Core/js/src/org/apache/flex/core/SimpleCSSValuesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/js/src/org/apache/flex/core/SimpleCSSValuesImpl.js b/frameworks/projects/Core/js/src/org/apache/flex/core/SimpleCSSValuesImpl.js
index b3a8bdf..6f5013a 100644
--- a/frameworks/projects/Core/js/src/org/apache/flex/core/SimpleCSSValuesImpl.js
+++ b/frameworks/projects/Core/js/src/org/apache/flex/core/SimpleCSSValuesImpl.js
@@ -261,6 +261,41 @@ org.apache.flex.core.SimpleCSSValuesImpl.prototype.parseStyles = function(styles
 
 
 /**
+ * @param {string} ruleName The name of the rule.
+ * @param {Object} values The styles object.
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.prototype.addRule = function(ruleName, values) {
+  var v;
+  var asValues = {};
+  for (var valueName in values) {
+    v = values[valueName];
+    var c = valueName.indexOf('-');
+    while (c != -1)
+    {
+      valueName = valueName.substr(0, c) +
+        valueName.charAt(c + 1).toUpperCase() +
+        valueName.substr(c + 2);
+      c = valueName.indexOf('-');
+    }
+    asValues[valueName] = v;
+  }
+  this.values[ruleName] = asValues;
+
+  var s = '{';
+  for (var p in values) {
+    v = values[p];
+    if (typeof(v) === 'number')
+      v = v.toString() + 'px';
+    s += p + ':' + v + ';';
+  }
+  s += '}';
+  s = ruleName + ' ' + s;
+  var sheet = document.styleSheets[0];
+  sheet.insertRule(s, 0);
+};
+
+
+/**
  * The styles that apply to each UI widget
  */
 org.apache.flex.core.SimpleCSSValuesImpl.perInstanceStyles = {


Mime
View raw message