2020-02-21 00:20:39 +01:00
|
|
|
import google_blob_sheet from "emoji-datasource-google-blob/img/google/sheets-256/64.png";
|
|
|
|
import google_sheet from "emoji-datasource-google/img/google/sheets-256/64.png";
|
|
|
|
import twitter_sheet from "emoji-datasource-twitter/img/twitter/sheets-256/64.png";
|
|
|
|
|
2020-09-26 06:24:56 +02:00
|
|
|
import octopus_url from "../generated/emoji/images-google-64/1f419.png";
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2021-03-25 22:35:45 +01:00
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
import google_blob_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-blob-sprite.css";
|
|
|
|
import google_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-sprite.css";
|
|
|
|
import twitter_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/twitter-sprite.css";
|
|
|
|
|
2020-02-21 00:20:39 +01:00
|
|
|
const emojisets = new Map([
|
2020-07-16 22:40:18 +02:00
|
|
|
["google", {css: google_css, sheet: google_sheet}],
|
|
|
|
["google-blob", {css: google_blob_css, sheet: google_blob_sheet}],
|
|
|
|
["twitter", {css: twitter_css, sheet: twitter_sheet}],
|
2020-02-21 00:20:39 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
// For `text` emojiset we fallback to `google-blob` emojiset
|
|
|
|
// for displaying emojis in emoji picker and typeahead.
|
|
|
|
emojisets.set("text", emojisets.get("google-blob"));
|
|
|
|
|
|
|
|
let current_emojiset;
|
|
|
|
|
|
|
|
export async function select(name) {
|
|
|
|
const new_emojiset = emojisets.get(name);
|
|
|
|
if (new_emojiset === current_emojiset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
const sheet = new Image();
|
2020-10-07 11:47:20 +02:00
|
|
|
sheet.addEventListener("load", resolve);
|
|
|
|
sheet.addEventListener("error", reject);
|
2020-02-21 00:20:39 +01:00
|
|
|
sheet.src = new_emojiset.sheet;
|
|
|
|
});
|
|
|
|
if (current_emojiset) {
|
|
|
|
current_emojiset.css.unuse();
|
|
|
|
}
|
|
|
|
new_emojiset.css.use();
|
|
|
|
current_emojiset = new_emojiset;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initialize() {
|
2021-07-28 16:00:58 +02:00
|
|
|
select(user_settings.emojiset);
|
2020-02-21 00:20:39 +01:00
|
|
|
|
|
|
|
// Load the octopus image in the background, so that the browser
|
|
|
|
// will cache it for later use. Note that we hardcode the octopus
|
|
|
|
// emoji to the old Google one because it's better.
|
|
|
|
//
|
|
|
|
// TODO: We should probably just make this work just like the Zulip emoji.
|
|
|
|
const octopus_image = new Image();
|
2020-09-26 06:24:56 +02:00
|
|
|
octopus_image.src = octopus_url;
|
2020-02-21 00:20:39 +01:00
|
|
|
}
|