Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait until gReadyState == 'complete' before triggering firing onready #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ document.webL10n = (function(window, document, undefined) {

// load and parse all resources for the specified locale
function loadLocale(lang, callback) {
gReadyState = 'interactive';

// RFC 4646, section 2.1 states that language tags have to be treated as
// case-insensitive. Convert to lowercase for case-insensitive comparisons.
if (lang) {
Expand Down Expand Up @@ -339,9 +341,9 @@ document.webL10n = (function(window, document, undefined) {
} else {
consoleLog('no resource to load, early way out');
}
gReadyState = 'complete';
// early way out
fireL10nReadyEvent(lang);
gReadyState = 'complete';
return;
}

Expand All @@ -352,8 +354,8 @@ document.webL10n = (function(window, document, undefined) {
gResourceCount++;
if (gResourceCount >= langCount) {
callback();
fireL10nReadyEvent(lang);
gReadyState = 'complete';
fireL10nReadyEvent(lang);
}
};

Expand Down Expand Up @@ -994,8 +996,6 @@ document.webL10n = (function(window, document, undefined) {

// load the default locale on startup
function l10nStartup() {
gReadyState = 'interactive';

// most browsers expose the UI language as `navigator.language'
// but IE uses `navigator.userLanguage' instead
var userLocale = navigator.language || navigator.userLanguage;
Expand Down Expand Up @@ -1180,7 +1180,7 @@ document.webL10n = (function(window, document, undefined) {
ready: function(callback) {
if (!callback) {
return;
} else if (gReadyState == 'complete' || gReadyState == 'interactive') {
} else if (gReadyState == 'complete') {
window.setTimeout(function() {
callback();
});
Expand Down