You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2020/07/18 09:43:46 UTC

[royale-asjs] branch develop updated: getClassStyle: add throwError

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new a9fd3b6  getClassStyle: add throwError
a9fd3b6 is described below

commit a9fd3b65f1b474dfd333b37d9f8c149b18e5418c
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Sat Jul 18 11:43:36 2020 +0200

    getClassStyle: add throwError
---
 .../org/apache/royale/utils/html/getClassStyle.as  | 50 +++++++++++++---------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getClassStyle.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getClassStyle.as
index 41bffb9..2d4aead 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getClassStyle.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getClassStyle.as
@@ -18,6 +18,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.royale.utils.html
 {
+	import org.apache.royale.debugging.throwError;
+
 	/**
 	 * Get an Object with all styles in a CSS className.
 	 * classname must match exactly the selector used in the CSS
@@ -30,28 +32,34 @@ package org.apache.royale.utils.html
 	COMPILE::JS
 	public function getClassStyle(className:String):Object
 	{
-		var cssText:String = "";
-		var classes:Array = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
-		for (var x:int = 0; x < classes.length; x++) {        
-			if (classes[x].selectorText == className) {
-				cssText += classes[x].cssText || classes[x].style.cssText;
-			}         
-		}
-		
-		// remove all text in css and left just the content between "{" "}"
-		var array:Array = cssText.match(/\{ (.*?)\}/);
-		// then split all styles
-		array = array[1].split("; ");
-		//remove latest since is empty
-		array.pop();
-		
-		//create the return object and split each style in property and value and insert in object
 		var o:Object = {};
-        for (x = 0; x < array.length; x++) {
-            var prop:Array = array[x].split(": ");
-            o[prop[0]] = prop[1];
-        }
-		
+		try
+		{
+			var cssText:String = "";
+			var classes:Array = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
+			for (var x:int = 0; x < classes.length; x++) {        
+				if (classes[x].selectorText == className) {
+					cssText += classes[x].cssText || classes[x].style.cssText;
+				}         
+			}
+			
+			// remove all text in css and left just the content between "{" "}"
+			var array:Array = cssText.match(/\{ (.*?)\}/);
+			// then split all styles
+			array = array[1].split("; ");
+			//remove latest since is empty
+			array.pop();
+			
+			//create the return object and split each style in property and value and insert in object
+			for (x = 0; x < array.length; x++) {
+				var prop:Array = array[x].split(": ");
+				o[prop[0]] = prop[1];
+			}
+		}
+		catch (error:Error)
+		{
+			trace("Due to CORS restrictions im Chrome when working offline you need to use: chrome --allow-file-access-from-files, or use other browser");
+		}
 		return o;
 	}
 }