flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [20/31] git commit: [flex-asjs] [refs/heads/develop] - add per-instance style support
Date Tue, 09 Dec 2014 05:17:07 GMT
add per-instance style support


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

Branch: refs/heads/develop
Commit: 5a0b3b9bd48d6de0129ddd66421dd5b34b03cec7
Parents: 61e6822
Author: Alex Harui <aharui@apache.org>
Authored: Mon Dec 8 17:35:44 2014 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Dec 8 20:47:44 2014 -0800

----------------------------------------------------------------------
 .../org/apache/flex/core/SimpleCSSValuesImpl.js | 105 +++++++++++++++++--
 1 file changed, 97 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5a0b3b9b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
index f0ff6a4..8fa8079 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
@@ -33,6 +33,12 @@ org.apache.flex.core.SimpleCSSValuesImpl.GLOBAL_SELECTOR = 'global';
 
 
 /**
+ * @type {string}
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.UNIVERSAL_SELECTOR = '*';
+
+
+/**
  * Metadata
  *
  * @type {Object.<string, Array.<Object>>}
@@ -68,6 +74,22 @@ org.apache.flex.core.SimpleCSSValuesImpl.prototype.getValue =
   var cName;
   var selectorName;
 
+  if (typeof(thisObject.get_style) === 'function')
+  {
+    var style = thisObject.get_style();
+    if (style != null)
+    {
+      try {
+         value = style[valueName];
+      }
+      catch (e) {
+        value = undefined;
+      }
+      if (value !== undefined)
+        return value;
+    }
+  }
+
   if ('className' in thisObject)
   {
     cName = thisObject.className;
@@ -141,14 +163,12 @@ org.apache.flex.core.SimpleCSSValuesImpl.prototype.getValue =
     cName = thisObject.FLEXJS_CLASS_INFO.names[0].qName;
   }
   o = values[org.apache.flex.core.SimpleCSSValuesImpl.GLOBAL_SELECTOR];
-  if (o !== undefined)
-  {
-    value = o[valueName];
-    if (value !== undefined)
-      return value;
-  }
-  o = values['*'];
-  return o[valueName];
+  if (o)
+    return o[valueName];
+  o = values[org.apache.flex.core.SimpleCSSValuesImpl.UNIVERSAL_SELECTOR];
+  if (o)
+    return o[valueName];
+  return undefined;
 };
 
 
@@ -211,3 +231,72 @@ org.apache.flex.core.SimpleCSSValuesImpl.prototype.init = function(mainclass)
{
 
   this.values = values;
 };
+
+
+/**
+ * @param {string} styles The styles as HTML style syntax.
+ * @return {Object} The styles object.
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.prototype.parseStyles = function(styles) {
+  var obj = {};
+  var parts = styles.split(';');
+  var l = parts.length;
+  for (var i = 0; i < l; i++) {
+    var part = parts[i];
+    var pieces = part.split(':');
+    var value = pieces[1];
+    if (value == 'null')
+      obj[pieces[0]] = null;
+    else if (value == 'true')
+      obj[pieces[0]] = true;
+    else if (value == 'false')
+      obj[pieces[0]] = false;
+    else {
+      var n = Number(value);
+      if (isNaN(n))
+        obj[pieces[0]] = value;
+      else
+        obj[pieces[0]] = n;
+    }
+  }
+  return obj;
+};
+
+
+/**
+ * The styles that apply to each UI widget
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.perInstanceStyles =
+  ['backgroundColor',
+   'backgroundImage',
+   'color',
+   'fontFamily',
+   'fontWeight',
+   'fontSize',
+   'fontStyle'];
+
+
+/**
+ * @param {Object} thisObject The object to apply styles to;
+ * @param {Object} styles The styles.
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.prototype.applyStyles =
+    function(thisObject, styles) {
+  var styleList = org.apache.flex.core.SimpleCSSValuesImpl.perInstanceStyles;
+  var n = styleList.length;
+  for (var i = 0; i < n; i++) {
+    this.applyStyle(thisObject, styleList[i]);
+  }
+};
+
+
+/**
+ * @param {Object} thisObject The object to apply styles to;
+ * @param {string} style The style name.
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.prototype.applyStyle =
+    function(thisObject, style) {
+  var value = this.getValue(thisObject, style);
+  if (value !== undefined)
+    thisObject.element.style[style] = value;
+};
\ No newline at end of file


Mime
View raw message