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 ec84212 core: loadCSS function, and fix some typo in loadJavascript
ec84212 is described below
commit ec842129fecb7494eb95c6b3262af7260b8c4d2e
Author: Carlos Rovira <[email protected]>
AuthorDate: Wed Jun 26 17:26:48 2019 +0200
core: loadCSS function, and fix some typo in loadJavascript
---
.../projects/Core/src/main/royale/CoreClasses.as | 1 +
.../utils/{js/loadJavascript.as => css/loadCSS.as} | 41 ++++++++++++----------
.../org/apache/royale/utils/js/loadJavascript.as | 39 ++++++++++----------
3 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as
b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index cdd9b25..e256aa6 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -277,6 +277,7 @@ internal class CoreClasses
import org.apache.royale.utils.object.defineProperty;
defineProperty;
import org.apache.royale.utils.object.defineSimpleProperty;
defineSimpleProperty;
import org.apache.royale.utils.js.loadJavascript;
loadJavascript;
+ import org.apache.royale.utils.css.loadCSS; loadCSS;
}
//Package Level Functions
import org.apache.royale.debugging.assert; assert;
diff --git
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/loadCSS.as
similarity index 57%
copy from
frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
copy to
frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/loadCSS.as
index 562c03e..951e347 100644
---
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/loadCSS.as
@@ -16,26 +16,29 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.utils.js
+package org.apache.royale.utils.css
{
- /**
- * Utility function to dynamically load Javascript in your application.
- * The callback will be called (with no arguments) when the javascript is
loaded.
- * @param url The url of the js file.
- * @param callback (optional) the function to be called when the code is
laoded.
- * @langversion 3.0
- * @productversion Royale 0.9.4
- * @royaleignorecoercion HTMLScriptElement
- */
- COMPILE::JS
- public function loadJavascript(url:String,callback:Function=null):void
- {
- var script:HTMLScriptElement = document.createElement('script') as
HTMLScriptElement;
- if (callback)
+ /**
+ * Utility function to dynamically load CSS in your application.
+ *
+ * @param url The url of the css file.
+ * @param callback (optional) the function to be called when the code
is loaded.
+ *
+ * @langversion 3.0
+ * @productversion Royale 0.9.6
+ * @royaleignorecoercion HTMLLinkElement
+ */
+ COMPILE::JS
+ public function loadCSS(url:String, callback:Function = null):void
{
- script.onload = callback;
+ var link:HTMLLinkElement = document.createElement('link') as
HTMLLinkElement;
+ link.setAttribute('rel', 'stylesheet');
+ link.setAttribute('type', 'text/css');
+ link.setAttribute('href', url);
+ if (callback)
+ {
+ link.onload = callback;
+ }
+ document.head.appendChild(link);
}
- script.src = url;
- document.head.appendChild(script);
- }
}
\ No newline at end of file
diff --git
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
index 562c03e..7ef51de 100644
---
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
@@ -18,24 +18,27 @@
////////////////////////////////////////////////////////////////////////////////
package org.apache.royale.utils.js
{
- /**
- * Utility function to dynamically load Javascript in your application.
- * The callback will be called (with no arguments) when the javascript is
loaded.
- * @param url The url of the js file.
- * @param callback (optional) the function to be called when the code is
laoded.
- * @langversion 3.0
- * @productversion Royale 0.9.4
- * @royaleignorecoercion HTMLScriptElement
- */
- COMPILE::JS
- public function loadJavascript(url:String,callback:Function=null):void
- {
- var script:HTMLScriptElement = document.createElement('script') as
HTMLScriptElement;
- if (callback)
+ /**
+ * Utility function to dynamically load Javascript in your application.
+ * The callback will be called (with no arguments) when the javascript
is loaded.
+ * @param url The url of the js file.
+ * @param callback (optional) the function to be called when the code
is loaded.
+ *
+ * @langversion 3.0
+ * @productversion Royale 0.9.4
+ * @royaleignorecoercion HTMLScriptElement
+ */
+ COMPILE::JS
+ public function loadJavascript(url:String, callback:Function =
null):void
{
- script.onload = callback;
+ var script:HTMLScriptElement = document.createElement('script')
as HTMLScriptElement;
+
+ if (callback)
+ {
+ script.onload = callback;
+ }
+
+ script.src = url;
+ document.head.appendChild(script);
}
- script.src = url;
- document.head.appendChild(script);
- }
}
\ No newline at end of file