You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/09/23 06:09:10 UTC

[royale-asjs] 04/04: on JS, pre-load the CSS file

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

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

commit 6f3683413e4223516cf16f80078ea36ba2a6aa2b
Author: Alex Harui <ah...@apache.org>
AuthorDate: Sat Sep 22 23:08:44 2018 -0700

    on JS, pre-load the CSS file
---
 .../org/apache/royale/utils/UIModuleUtils.as       | 53 ++++++++++++++++------
 1 file changed, 38 insertions(+), 15 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
index 760f42d..12970a1 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
@@ -114,6 +114,9 @@ package org.apache.royale.utils
         COMPILE::JS
         private var jsDepsLoader:WrappedHTMLElement;
                 
+        COMPILE::JS
+        private var jsCSSLoader:HTMLLinkElement;
+        
 		/**
 		 * @private
 		 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
@@ -145,6 +148,10 @@ package org.apache.royale.utils
                     jsLoader.onload = loadHandler;
 					document.body.appendChild(jsLoader);
                 }
+                
+                jsCSSLoader = document.createElement('link') as HTMLLinkElement;
+                jsCSSLoader.onload = actuallyLoadModule;
+                document.head.appendChild(jsCSSLoader);
 			}
 		}
         
@@ -177,22 +184,38 @@ package org.apache.royale.utils
 					(host as DisplayObjectContainer).addChild(swfLoader);
 				}
 			}
-				
 			COMPILE::JS {
-                if (!goog.DEBUG)
-    	   			jsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + ".js" :
-                        moduleName + ".js");
-                else
-                {
-                    // js-debug module loading requires that the __deps.js file has been tweaked
-                    // so that the path to the module class is correct and that any
-                    // framework js files have been copied into the same tree structure as
-                    // the main apps framework js files
-                    window["goog"]["ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING"] = true;
-                    jsDepsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + "__deps.js" :
-                        moduleName + "__deps.js");
-                }
-			}
+                loadCSS(modulePath ? modulePath + "/" + moduleName + ".css" :
+                    moduleName + ".css");
+            }
+        }
+        
+        COMPILE::JS
+        protected function loadCSS(href:String):void
+        {
+            jsCSSLoader.id = href;
+            jsCSSLoader.rel = "stylesheet";
+            jsCSSLoader.type = "text/css";
+            jsCSSLoader.media = "all";
+            jsCSSLoader.href = href;
+        }
+        
+        COMPILE::JS
+        protected function actuallyLoadModule():void
+        {
+            if (!goog.DEBUG)
+	   			jsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + ".js" :
+                    moduleName + ".js");
+            else
+            {
+                // js-debug module loading requires that the __deps.js file has been tweaked
+                // so that the path to the module class is correct and that any
+                // framework js files have been copied into the same tree structure as
+                // the main apps framework js files
+                window["goog"]["ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING"] = true;
+                jsDepsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + "__deps.js" :
+                    moduleName + "__deps.js");
+            }
 		}
         
         private var moduleInstance:IUIBase;