205 lines
4.9 KiB
JavaScript
205 lines
4.9 KiB
JavaScript
import Enact_$L from "@enact/i18n/$L";
|
|
|
|
import stringReSource from "../../resources/de/strings.json";
|
|
|
|
export const $L = (str) => {
|
|
let languageSetting = "system";
|
|
let language = "en";
|
|
|
|
if (
|
|
typeof window === "object" &&
|
|
window.store &&
|
|
window.store.getState().common &&
|
|
window.store.getState().common.localSettings
|
|
) {
|
|
languageSetting =
|
|
window.store.getState().common.localSettings.languageSetting;
|
|
}
|
|
|
|
if (
|
|
typeof window === "object" &&
|
|
window.PalmSystem &&
|
|
languageSetting === "system"
|
|
) {
|
|
return Enact_$L(str).replace(/{br}/g, "{br}");
|
|
} else if (typeof window === "object") {
|
|
language =
|
|
typeof window.navigator === "object"
|
|
? window.navigator.language || window.navigator.userLanguage
|
|
: "en-US";
|
|
|
|
if (languageSetting !== "system") {
|
|
language = languageSetting;
|
|
}
|
|
|
|
language = language.split("-")[0];
|
|
|
|
const resource = stringReSource[language] || stringReSource.en;
|
|
|
|
if (typeof str === "object") {
|
|
if (resource && resource[str.key]) {
|
|
return resource[str.key].replace(/{br}/g, "{br}");
|
|
} else {
|
|
return str.value;
|
|
}
|
|
} else if (resource && resource[str]) {
|
|
return resource[str].replace(/{br}/g, "{br}");
|
|
}
|
|
}
|
|
|
|
return str && str.replace(/{br}/g, "{br}");
|
|
};
|
|
|
|
export const createQueryString = (object) => {
|
|
const parts = [];
|
|
for (const key of Object.getOwnPropertyNames(object)) {
|
|
if (
|
|
object[key] !== null &&
|
|
object[key] !== undefined &&
|
|
object[key] !== ""
|
|
) {
|
|
parts.push(`${key}=${encodeURIComponent(object[key])}`);
|
|
}
|
|
}
|
|
return parts.join("&");
|
|
};
|
|
|
|
export const wait = (time) => {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve();
|
|
}, time);
|
|
});
|
|
};
|
|
|
|
export const scaleW = (value) => {
|
|
if (typeof window === "object") {
|
|
return value * (window.innerWidth / 1920);
|
|
}
|
|
return value;
|
|
};
|
|
|
|
export const scaleH = (value) => {
|
|
if (typeof window === "object") {
|
|
return value * (window.innerHeight / 1080);
|
|
}
|
|
return value;
|
|
};
|
|
|
|
//for test
|
|
|
|
let localLaunchParams = {
|
|
// contentTarget: "V3_8001_Tv_PD_2_20632899_0_766",
|
|
// contentTarget: "V3_8001_Tv_LS_1_USQVC20240418060000_0_766",
|
|
// contentTarget: "V3_8001_Tv_VS_1_65f43844407a5f3f4f22e65c_0_766",
|
|
// contentTarget: "V3_8001_Tv_TD_1_769_J395844_0_001",
|
|
// contentTarget: "V3_8001_Tv_HD_7_527_0",
|
|
// contentTarget: "V3_8001_Tv_HP_7_527_0",
|
|
// contentTarget: "V3_8001_Tv_WE_twin",
|
|
// contentTarget: "V3_8001_Tv_OS_1006_Home",
|
|
// contentTarget: "V3_8001_Tv_BS",
|
|
// contentTarget: "V3_8001_Tv_PS",
|
|
// contentTarget: "V3_8001_Tv_SC_1000_Fashion_Item",
|
|
// contentTarget: "V3_8001_Tv_FB_4",
|
|
};
|
|
|
|
export const getLaunchParams = () => {
|
|
let params = {};
|
|
|
|
if (
|
|
typeof window === "object" &&
|
|
window.PalmSystem &&
|
|
window.PalmSystem.launchParams
|
|
) {
|
|
try {
|
|
params = JSON.parse(window.PalmSystem.launchParams);
|
|
if (params["x-webos-app-container-launch"] === true) {
|
|
params = params.details;
|
|
}
|
|
} catch (e) {
|
|
params = {};
|
|
}
|
|
return params;
|
|
} else {
|
|
return localLaunchParams;
|
|
}
|
|
};
|
|
|
|
export const clearLaunchParams = () => {
|
|
console.log("common.clearLaunchParams");
|
|
if (
|
|
typeof window === "object" &&
|
|
window.PalmSystem &&
|
|
window.PalmSystem.launchParams
|
|
) {
|
|
window.PalmSystem.launchParams = "";
|
|
} else {
|
|
localLaunchParams = {};
|
|
}
|
|
};
|
|
|
|
export const readLocalStorage = (key, defaultValue) => {
|
|
const value = typeof window === "object" && window.localStorage.getItem(key);
|
|
if (!value && defaultValue !== undefined) {
|
|
return defaultValue;
|
|
}
|
|
return value === "undefined" ? null : JSON.parse(value);
|
|
};
|
|
|
|
export const writeLocalStorage = (key, value) => {
|
|
if (typeof window === "object") {
|
|
window.localStorage.setItem(key, JSON.stringify(value));
|
|
}
|
|
};
|
|
|
|
export const convertToTimeFormat = (timeString, isIncludeDate = false) => {
|
|
const date = new Date(timeString);
|
|
|
|
let options = { hour: "numeric", minute: "2-digit", hour12: true };
|
|
let pattern = " ";
|
|
|
|
if (isIncludeDate) {
|
|
options = {
|
|
...options,
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
hour: "2-digit",
|
|
};
|
|
pattern = ",";
|
|
}
|
|
|
|
return new Intl.DateTimeFormat("en-US", options)
|
|
.format(date)
|
|
.replace(pattern, "");
|
|
};
|
|
|
|
export const getTranslate3dValueByDirection = (
|
|
element,
|
|
isHorizontal = true
|
|
) => {
|
|
try {
|
|
const transformStyle = window.getComputedStyle(element).transform;
|
|
|
|
if (!transformStyle || transformStyle === "none") {
|
|
throw new Error("transfrom style not found");
|
|
}
|
|
|
|
const transformMatrix = transformStyle.match(/^matrix\((.+)\)$/);
|
|
|
|
let index, value;
|
|
|
|
if (transformMatrix) {
|
|
const matrixValues = transformMatrix[1].split(", ");
|
|
|
|
index = isHorizontal ? 4 : 5;
|
|
|
|
value = parseFloat(Math.abs(matrixValues[index]));
|
|
}
|
|
|
|
return value;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
}
|
|
};
|