flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [22/50] git commit: [flex-asjs] [refs/heads/develop] - Use CSSUtils.toNumber()
Date Mon, 03 Jul 2017 13:35:16 GMT
Use CSSUtils.toNumber()


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

Branch: refs/heads/develop
Commit: de093c81727680a9bb1521d9258cd90d0c0b40cd
Parents: 4f09e30
Author: Harbs <harbs@in-tools.com>
Authored: Thu Jun 22 12:50:26 2017 +0300
Committer: Harbs <harbs@in-tools.com>
Committed: Thu Jun 22 12:50:26 2017 +0300

----------------------------------------------------------------------
 .../org/apache/flex/core/ApplicationBase.as     | 13 ++++++---
 .../main/flex/org/apache/flex/core/UIBase.as    | 29 ++++++++++----------
 .../main/flex/org/apache/flex/utils/CSSUtils.as |  7 +++--
 3 files changed, 28 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/de093c81/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/ApplicationBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/ApplicationBase.as
b/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/ApplicationBase.as
index 8a54c91..da1aa16 100644
--- a/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/ApplicationBase.as
+++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/ApplicationBase.as
@@ -23,6 +23,11 @@ package org.apache.flex.core
         import flash.system.ApplicationDomain;
         import flash.utils.getQualifiedClassName;
     }
+    COMPILE::JS
+    {
+        import org.apache.flex.utils.CSSUtils;
+    }
+
         
     /**
      *  This is a platform-dependent base class
@@ -116,10 +121,10 @@ package org.apache.flex.core
         {
             var pixels:Number;
             var strpixels:String = element.style.width as String;
-            if (strpixels !== null && strpixels.indexOf('%') != -1)
+            if(strpixels == null)
                 pixels = NaN;
             else
-                pixels = parseFloat(strpixels);
+                pixels = CSSUtils.toNumber(strpixels);
             if (isNaN(pixels)) {
                 pixels = element.offsetWidth;
                 if (pixels === 0 && element.scrollWidth !== 0) {
@@ -154,10 +159,10 @@ package org.apache.flex.core
         {
             var pixels:Number;
             var strpixels:String = element.style.height as String;
-            if (strpixels !== null && strpixels.indexOf('%') != -1)
+            if(strpixels == null)
                 pixels = NaN;
             else
-                pixels = parseFloat(strpixels);
+                pixels = CSSUtils.toNumber(strpixels);
             if (isNaN(pixels)) {
                 pixels = element.offsetHeight;
                 if (pixels === 0 && element.scrollHeight !== 0) {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/de093c81/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/UIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/UIBase.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/UIBase.as
index 8d08465..07dffa5 100644
--- a/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/UIBase.as
+++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/core/UIBase.as
@@ -22,17 +22,20 @@ package org.apache.flex.core
     {
         import flash.display.DisplayObject;
         import flash.display.Sprite;
-        import flash.display.Stage;            
+        import flash.display.Stage;
+        import org.apache.flex.events.utils.MouseEventConverter;
     }
 	
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
 	import org.apache.flex.events.MouseEvent;
 	import org.apache.flex.events.ValueChangeEvent;
-	COMPILE::SWF {
-	    import org.apache.flex.events.utils.MouseEventConverter;
-	}
     import org.apache.flex.utils.StringUtil;
+
+    COMPILE::JS
+    {
+        import org.apache.flex.utils.CSSUtils;
+    }
 	
 	/**
 	 *  Set a different class for click events so that
@@ -368,13 +371,11 @@ package org.apache.flex.core
         public function get width():Number
         {
             var pixels:Number;
-            var strpixels:String = positioner.style.width as String;
-            if (strpixels !== null && strpixels.indexOf('%') != -1)
+            var strpixels:String = element.style.width as String;
+            if(strpixels == null)
                 pixels = NaN;
-            else if (strpixels === "")
-            	pixels = NaN;
             else
-                pixels = parseFloat(strpixels);
+                pixels = CSSUtils.toNumber(strpixels);
             if (isNaN(pixels)) {
                 pixels = positioner.offsetWidth;
                 if (pixels == 0 && positioner.scrollWidth != 0) {
@@ -462,13 +463,11 @@ package org.apache.flex.core
         public function get height():Number
         {
             var pixels:Number;
-            var strpixels:String = positioner.style.height as String;
-            if (strpixels !== null && strpixels.indexOf('%') !== -1)
+            var strpixels:String = element.style.height as String;
+            if(strpixels == null)
                 pixels = NaN;
-            else if (strpixels === "")
-            	pixels = NaN;
             else
-                pixels = parseFloat(strpixels);
+                pixels = CSSUtils.toNumber(strpixels);
             if (isNaN(pixels)) {
                 pixels = positioner.offsetHeight;
                 if (pixels == 0 && positioner.scrollHeight != 0) {
@@ -1316,7 +1315,7 @@ package org.apache.flex.core
 					if (value is String)
                     {
                         var s:String = String(value);
-                        if (s.indexOf("%") !== -1)
+                        if (s.indexOf("%") > -1)
         					_percentWidth = Number(s.substring(0, s.length - 1));
                         else
                         {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/de093c81/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSUtils.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSUtils.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSUtils.as
index 39dc818..0cce361 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSUtils.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSUtils.as
@@ -69,12 +69,15 @@ package org.apache.flex.utils
          */
         public static function toNumber(str:String, reference:Number = 0):Number
         {
+            //str must be non-null
+            if(str === "")
+                return NaN;
             var c:int = str.indexOf("px");
-            if (c !== -1)
+            if (c > -1)
                 return Number(str.substr(0, c));
             
             c = str.indexOf("%");
-            if (c !== -1)
+            if (c > -1)
                 return Number(str.substr(0, c)) * reference / 100;
             
             return Number(str);


Mime
View raw message