Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/jekyll/assets/js/crowdin-init.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
window.initCrowdIn('LizardByte-docs', null);
globalThis.initCrowdIn('LizardByte-docs', null);
1 change: 0 additions & 1 deletion examples/jekyll/assets/js/discord-init.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/sphinx/source/_static/js/crowdin.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
window.initCrowdIn('LizardByte-docs', 'sphinx')
globalThis.initCrowdIn('LizardByte-docs', 'sphinx')
4 changes: 2 additions & 2 deletions src/js/format-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function formatNumber(num, decimalPlaces = 1) {
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.formatNumber = formatNumber;
if (globalThis.window !== undefined) {
globalThis.formatNumber = formatNumber;
}

module.exports = formatNumber;
4 changes: 2 additions & 2 deletions src/js/levenshtein-distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function levenshteinDistance(a, b) {
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.levenshteinDistance = levenshteinDistance;
if (globalThis.window !== undefined) {
globalThis.levenshteinDistance = levenshteinDistance;
}

module.exports = levenshteinDistance;
4 changes: 2 additions & 2 deletions src/js/load-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function loadScript(url, callback) {
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.loadScript = loadScript;
if (globalThis.window !== undefined) {
globalThis.loadScript = loadScript;
}

module.exports = loadScript;
19 changes: 8 additions & 11 deletions src/js/ranking-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ function rankingSorter(firstKey, secondKey) {
return -1;
} else if (a[firstKey] < b[firstKey]) {
return 1;
}
else {
if (a[secondKey] > b[secondKey]) {
return 1;
} else if (a[secondKey] < b[secondKey]) {
return -1;
} else {
return 0;
}
} else if (a[secondKey] > b[secondKey]) {
return 1;
} else if (a[secondKey] < b[secondKey]) {
return -1;
} else {
return 0;
}
}
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.rankingSorter = rankingSorter;
if (globalThis.window !== undefined) {
globalThis.rankingSorter = rankingSorter;
}

module.exports = rankingSorter;
4 changes: 2 additions & 2 deletions src/js/sleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function sleep(ms) {
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.sleep = sleep;
if (globalThis.window !== undefined) {
globalThis.sleep = sleep;
}

module.exports = sleep;
4 changes: 2 additions & 2 deletions tests/crowdin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('initCrowdIn', () => {
afterEach(() => {
jest.clearAllMocks();
jest.useRealTimers();
delete global.window.proxyTranslator;
delete globalThis.window.proxyTranslator;
delete globalThis._crowdinMirrorInstalled;
});

Expand Down Expand Up @@ -84,7 +84,7 @@ describe('initCrowdIn', () => {
// Simulate script loading
jest.runAllTimers();

expect(window.proxyTranslator.init).toHaveBeenCalledWith(
expect(globalThis.proxyTranslator.init).toHaveBeenCalledWith(
expect.objectContaining({
baseUrl: "http://localhost",
distribution: "d6c830ba4b41106fefe5d391bw4",
Expand Down
2 changes: 1 addition & 1 deletion tests/sleep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('sleep function', () => {
})

beforeEach(() => {
jest.spyOn(global, 'setTimeout');
jest.spyOn(globalThis, 'setTimeout');
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');
const { codecovWebpackPlugin } = require("@codecov/webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

Expand Down
Loading