cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From za...@apache.org
Subject [1/2] git commit: Hold the information if L10n was ready before.
Date Fri, 12 Sep 2014 10:21:44 GMT
Repository: cordova-plugin-globalization
Updated Branches:
  refs/heads/master bb87e56af -> aa66116f8


Hold the information if L10n was ready before.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/01bb7222
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/01bb7222
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/01bb7222

Branch: refs/heads/master
Commit: 01bb7222203f45bb3bd2f2e4d268880b3c64ad68
Parents: bb87e56
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Fri Sep 12 12:16:32 2014 +0200
Committer: Piotr Zalewa <piotr@zalewa.info>
Committed: Fri Sep 12 12:16:32 2014 +0200

----------------------------------------------------------------------
 src/firefoxos/GlobalizationProxy.js | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/01bb7222/src/firefoxos/GlobalizationProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/GlobalizationProxy.js b/src/firefoxos/GlobalizationProxy.js
index dd8944e..910ef6b 100644
--- a/src/firefoxos/GlobalizationProxy.js
+++ b/src/firefoxos/GlobalizationProxy.js
@@ -24,12 +24,25 @@ var GlobalizationError = require('./GlobalizationError');
 var l10n_loaded = new Event('l10n_loaded');
 var l10n_ready = new Event('l10n_ready');
 
+var is_l10n_ready = false;
+
 document.addEventListener('l10n_loaded', function() {
+  console.log('DEBUG: L10n loaded');
   navigator.mozL10n.ready(function() {
+    console.log('DEBUG: L10n ready');
+    is_l10n_ready = true;
     document.dispatchEvent(l10n_ready);
   });
 });
 
+function callIfL10nReady(callback) {
+    if (is_l10n_ready) {
+        return callback();
+    }
+    document.addEventListener('l10n_ready', callback);
+}
+
+
 function loadFile(elementName, attributes, callback) {
     var e = document.createElement(elementName);
     for (var attrName in attributes) {
@@ -73,13 +86,13 @@ loadDependencies();
 function getPreferredLanguage(successCB, errorCB) {
     // WARNING: this isn't perfect - there is a difference between UI language
     // and preferred language, however it doesn't happen too often.
-    document.addEventListener('l10n_ready', function() {
+    callIfL10nReady(function() {
       successCB({value: navigator.mozL10n.language.code});
     });
 }
 
 function getLocaleName(successCB, errorCB) {
-    document.addEventListener('l10n_ready', function() {
+    callIfL10nReady(function() {
       successCB(navigator.mozL10n.language.code);
     });
 }
@@ -88,7 +101,7 @@ function dateToString(successCB, errorCB, params) {
     var date = new Date(params[0].date);
     var options = params[0].options;
 
-    document.addEventListener('l10n_ready', function() {
+    callIfL10nReady(function() {
       var f = new navigator.mozL10n.DateTimeFormat();
       successCB({'value': _getStringFromDate(f, date, options)});
     });
@@ -165,7 +178,7 @@ function getDatePattern(successCB, failureCB, options) {
 }
 
 function getDateNames(successCB, failureCB, params) {
-  document.addEventListener('l10n_ready', function() {
+  callIfL10nReady(function() {
     var version = 'long';
     var item = 'month';
     var first = 0;
@@ -208,7 +221,7 @@ function isDayLightSavingsTime(successCB, failureCB, params) {
 }
 
 function getFirstDayOfWeek(successCB, failureCB) {
-  document.addEventListener('l10n_ready', function() {
+  callIfL10nReady(function() {
     var firstDay = navigator.mozL10n.get('weekStartsOnMonday');
     successCB({'value': parseInt(firstDay)});
   });


Mime
View raw message