You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2018/09/17 11:47:45 UTC

[royale-asjs] branch develop updated: added loadJavascript function

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

harbs 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 1186bb7  added loadJavascript function
     new 80fbead  Merge branch 'develop' of https://github.com/apache/royale-asjs into develop
1186bb7 is described below

commit 1186bb76da96166c7dce54d222c27ad79935143b
Author: Harbs <ha...@in-tools.com>
AuthorDate: Mon Sep 17 14:47:25 2018 +0300

    added loadJavascript function
---
 .../projects/Core/src/main/royale/CoreClasses.as   |  1 +
 .../org/apache/royale/utils/js/loadJavascript.as   | 38 ++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index d3615cf..ee50b15 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -257,6 +257,7 @@ import org.apache.royale.events.ItemRemovedEvent; ItemRemovedEvent;
 		import org.apache.royale.utils.object.defineSimpleGetter; defineSimpleGetter;
 		import org.apache.royale.utils.object.defineProperty; defineProperty;
 		import org.apache.royale.utils.object.defineSimpleProperty; defineSimpleProperty;
+		import org.apache.royale.utils.js.loadJavascript; loadJavascript;
 	}
 	//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/js/loadJavascript.as
new file mode 100644
index 0000000..26b2d70
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/js/loadJavascript.as
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+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.5
+   * @royaleignorecoercion HTMLScriptElement
+   */
+  COMPILE::JS
+  public function loadJavascript(url:String,callback:Function=null)
+  {
+    var script:HTMLScriptElement = document.createElement('script') as HTMLScriptElement;
+    script.onload = callback;
+    script.src = url;
+    document.head.appendChild(script);
+  }
+}
\ No newline at end of file