You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by yi...@apache.org on 2020/05/18 13:40:07 UTC
[royale-asjs] branch develop updated: Static initializers loading
hljs in TDJ.
This is an automated email from the ASF dual-hosted git repository.
yishayw 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 99a8c83 Static initializers loading hljs in TDJ.
new 52d9416 Merge branch 'develop' of https://gitbox.apache.org/repos/asf/royale-asjs into develop
99a8c83 is described below
commit 99a8c8356573ff16b668f2d39a447355c673fee3
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Mon May 18 16:38:26 2020 +0300
Static initializers loading hljs in TDJ.
This solves a bug in the release build of TDJ were hljs was called
before it was loaded.
---
.../ExampleAndSourceCodeTabbedSectionContent.as | 6 +-
examples/jewel/TourDeJewel/src/main/royale/hljs.as | 12 ---
.../TourDeJewel/src/main/royale/hljsFacade.as | 91 ++++++++++++++++++++++
3 files changed, 92 insertions(+), 17 deletions(-)
diff --git a/examples/jewel/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as b/examples/jewel/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
index bafa4ab..582c7ca 100644
--- a/examples/jewel/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
+++ b/examples/jewel/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
@@ -136,11 +136,7 @@ package components
public function dataReadyHandler(event:Event):void
{
sourceCodeMXMLText.text = event.target.sourceCode;
-
- COMPILE::JS
- {
- hljs.highlightBlock(sourceCodeMXMLText.element);
- }
+ hljsFacade.highlightBlock(sourceCodeMXMLText);
}
/**
diff --git a/examples/jewel/TourDeJewel/src/main/royale/hljs.as b/examples/jewel/TourDeJewel/src/main/royale/hljs.as
index 92d4c98..7f192f0 100644
--- a/examples/jewel/TourDeJewel/src/main/royale/hljs.as
+++ b/examples/jewel/TourDeJewel/src/main/royale/hljs.as
@@ -24,18 +24,6 @@ package
COMPILE::JS
public class hljs
{
- /**
- * <inject_script>
- * var script = document.createElement("script");
- * script.setAttribute("src", "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js");
- * document.head.appendChild(script);
- * var link = document.createElement("link");
- * link.setAttribute("rel", "stylesheet");
- * link.setAttribute("type", "text/css");
- * link.setAttribute("href", "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-dark.min.css");
- * document.head.appendChild(link);
- * </inject_script>
- */
public function hljs(){}
public static function highlightBlock(block:Element):void {}
diff --git a/examples/jewel/TourDeJewel/src/main/royale/hljsFacade.as b/examples/jewel/TourDeJewel/src/main/royale/hljsFacade.as
new file mode 100644
index 0000000..3724e35
--- /dev/null
+++ b/examples/jewel/TourDeJewel/src/main/royale/hljsFacade.as
@@ -0,0 +1,91 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import org.apache.royale.utils.css.loadCSS;
+ import org.apache.royale.utils.js.loadJavascript;
+ import org.apache.royale.core.IRenderedObject;
+ public class hljsFacade
+ {
+ private static var jsId:String = getJs();
+ private static var cssId:String = getCss();
+ private static var jsLoaded:Boolean;
+ private static var cssLoaded:Boolean;
+ private static var objectsToHighlight:Array;
+
+ private static function getJs():String
+ {
+ loadJavascript("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", jsLoadedHandler);
+ return null;
+ }
+
+ private static function getCss():String
+ {
+ return loadCSS("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-dark.min.css", cssLoadedHandler);
+ }
+
+ private static function doDeferredHighLights():void
+ {
+ if (!objectsToHighlight)
+ {
+ return;
+ }
+ while (objectsToHighlight.length > 0)
+ {
+ highlightBlock(objectsToHighlight.shift() as IRenderedObject);
+ }
+ }
+
+ private static function jsLoadedHandler():void
+ {
+ jsLoaded = true;
+ if (cssLoaded)
+ {
+ doDeferredHighLights();
+ }
+ }
+
+ private static function cssLoadedHandler():void
+ {
+ cssLoaded = true;
+ if (jsLoaded)
+ {
+ doDeferredHighLights();
+ }
+ }
+
+ public static function highlightBlock(renderedObject:IRenderedObject):void
+ {
+ if (jsLoaded && cssLoaded)
+ {
+ COMPILE::JS
+ {
+ hljs.highlightBlock(renderedObject.element);
+ }
+ } else
+ {
+ if (!objectsToHighlight)
+ {
+ objectsToHighlight = [];
+ }
+ objectsToHighlight.push(renderedObject);
+ }
+ }
+ }
+}