You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2019/09/22 06:01:48 UTC
[royale-asjs] 03/09: Added a utils.getTimer emulation for
javascript,
similar to flash.utils.getTimer Covered more bases for the browser
variations in LocaleUtils
This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 1b4af03a477ff5be4d31fcc215ddc468d18c0e54
Author: greg-dove <gr...@gmail.com>
AuthorDate: Sun Sep 22 08:24:00 2019 +1200
Added a utils.getTimer emulation for javascript, similar to flash.utils.getTimer
Covered more bases for the browser variations in LocaleUtils
---
.../projects/Core/src/main/royale/CoreClasses.as | 1 +
.../royale/org/apache/royale/utils/EffectTimer.as | 4 +-
.../royale/org/apache/royale/utils/LocaleUtils.as | 6 ++-
.../royale/org/apache/royale/utils/getTimer.as | 44 ++++++++++++++++++++++
4 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index e256aa6..4e258c7 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -218,6 +218,7 @@ internal class CoreClasses
import org.apache.royale.utils.SolidBorderUtil; SolidBorderUtil;
import org.apache.royale.utils.HTMLLoader; HTMLLoader;
}
+ import org.apache.royale.utils.getTimer; getTimer;
import org.apache.royale.utils.BrowserUtils; BrowserUtils;
import org.apache.royale.utils.callLater; callLater;
import org.apache.royale.utils.getParentOrSelfByType; getParentOrSelfByType;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/EffectTimer.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/EffectTimer.as
index 7aefdc0..c156bb5 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/EffectTimer.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/EffectTimer.as
@@ -95,7 +95,7 @@ public class EffectTimer extends EventDispatcher implements IEffectTimer
COMPILE::SWF
{
timer.start();
- return getTimer();
+ return flash.utils.getTimer();
}
COMPILE::JS
{
@@ -126,7 +126,7 @@ public class EffectTimer extends EventDispatcher implements IEffectTimer
private function timerHandler(event:flash.events.TimerEvent):void
{
event.updateAfterEvent();
- dispatchEvent(new ValueEvent("update", getTimer()));
+ dispatchEvent(new ValueEvent("update", flash.utils.getTimer()));
}
COMPILE::JS
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/LocaleUtils.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/LocaleUtils.as
index 7538ac7..428da1a 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/LocaleUtils.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/LocaleUtils.as
@@ -59,7 +59,11 @@ package org.apache.royale.utils
{
if(!_localeName)
{
- _localeName = navigator.language;
+ if (navigator.languages && navigator.languages.length) {
+ _localeName = navigator.languages[0];
+ } else {
+ _localeName = navigator.language || navigator['userLanguage'] || navigator['browserLanguage'] || 'en';
+ }
}
return _localeName;
}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/getTimer.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/getTimer.as
new file mode 100644
index 0000000..21d8366
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/getTimer.as
@@ -0,0 +1,44 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ COMPILE::SWF
+ {
+ import flash.utils.getTimer;
+ }
+
+ COMPILE::JS{
+ import goog.global;
+ }
+
+ /**
+ * The number of milliseconds since the current script host environment was started.
+ * This is from the time of the current window load (Browser javascript), or process started (Node javascript) or the AVM started (SWF)
+ * @return an integer representing the number of milliseconds since start.
+ */
+ public function getTimer():int
+ {
+ COMPILE::SWF{
+ return flash.utils.getTimer();
+ }
+ COMPILE::JS{
+ return int(goog.global['performance'].now());
+ }
+ }
+}