mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
feat(emoji): allow the user to set the cdn address (#3908)
This commit is contained in:
@@ -11,6 +11,9 @@ use Flarum\Extend;
|
|||||||
use s9e\TextFormatter\Configurator;
|
use s9e\TextFormatter\Configurator;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
(new Extend\Frontend('admin'))
|
||||||
|
->js(__DIR__.'/js/dist/admin.js'),
|
||||||
|
|
||||||
(new Extend\Frontend('forum'))
|
(new Extend\Frontend('forum'))
|
||||||
->js(__DIR__.'/js/dist/forum.js')
|
->js(__DIR__.'/js/dist/forum.js')
|
||||||
->css(__DIR__.'/less/forum.less')
|
->css(__DIR__.'/less/forum.less')
|
||||||
@@ -30,4 +33,8 @@ return [
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
new Extend\Locales(__DIR__.'/locale'),
|
new Extend\Locales(__DIR__.'/locale'),
|
||||||
|
|
||||||
|
(new Extend\Settings)
|
||||||
|
->serializeToForum('flarum-emoji.cdn', 'flarum-emoji.cdn')
|
||||||
|
->default('flarum-emoji.cdn', 'https://cdn.jsdelivr.net/gh/twitter/twemoji@[version]/assets/'),
|
||||||
];
|
];
|
||||||
|
1
extensions/emoji/js/admin.js
Normal file
1
extensions/emoji/js/admin.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './src/admin';
|
13
extensions/emoji/js/src/admin/index.js
Normal file
13
extensions/emoji/js/src/admin/index.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import app from 'flarum/admin/app';
|
||||||
|
import { version } from '../common/cdn';
|
||||||
|
|
||||||
|
app.initializers.add('flarum-emoji', () => {
|
||||||
|
app.extensionData.for('flarum-emoji').registerSetting({
|
||||||
|
setting: 'flarum-emoji.cdn',
|
||||||
|
type: 'text',
|
||||||
|
label: app.translator.trans('flarum-emoji.admin.settings.cdn_label'),
|
||||||
|
help: app.translator.trans('flarum-emoji.admin.settings.cdn_help', {
|
||||||
|
version: version,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
7
extensions/emoji/js/src/common/cdn.js
Normal file
7
extensions/emoji/js/src/common/cdn.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import twemoji from 'twemoji';
|
||||||
|
|
||||||
|
export const version = /([0-9]+).[0-9]+.[0-9]+/g.exec(twemoji.base)[1];
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
return app.forum.attribute('flarum-emoji.cdn').replace('[version]', version);
|
||||||
|
}
|
@@ -6,7 +6,7 @@ import AutocompleteReader from 'flarum/common/utils/AutocompleteReader';
|
|||||||
|
|
||||||
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
||||||
import getEmojiIconCode from './helpers/getEmojiIconCode';
|
import getEmojiIconCode from './helpers/getEmojiIconCode';
|
||||||
import cdn from './cdn';
|
import cdn from '../common/cdn';
|
||||||
|
|
||||||
export default function addComposerAutocomplete() {
|
export default function addComposerAutocomplete() {
|
||||||
let emojiMap = null;
|
let emojiMap = null;
|
||||||
@@ -40,6 +40,7 @@ export default function addComposerAutocomplete() {
|
|||||||
|
|
||||||
extend('flarum/common/components/TextEditor', 'buildEditorParams', function (params) {
|
extend('flarum/common/components/TextEditor', 'buildEditorParams', function (params) {
|
||||||
const emojiKeys = Object.keys(emojiMap);
|
const emojiKeys = Object.keys(emojiMap);
|
||||||
|
const resolvedCdn = cdn();
|
||||||
|
|
||||||
const autocompleteReader = new AutocompleteReader(':');
|
const autocompleteReader = new AutocompleteReader(':');
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ export default function addComposerAutocomplete() {
|
|||||||
emojiDropdown.setIndex($(this).parent().index() - 1);
|
emojiDropdown.setIndex($(this).parent().index() - 1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img alt={emoji} className="emoji" draggable="false" loading="lazy" src={`${cdn}72x72/${code}.png`} title={name} />
|
<img alt={emoji} className="emoji" draggable="false" loading="lazy" src={`${resolvedCdn}72x72/${code}.png`} title={name} />
|
||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
import twemoji from 'twemoji';
|
|
||||||
|
|
||||||
export const version = /([0-9]+).[0-9]+.[0-9]+/g.exec(twemoji.base)[1];
|
|
||||||
|
|
||||||
export default `https://cdn.jsdelivr.net/gh/twitter/twemoji@${version}/assets/`;
|
|
@@ -3,14 +3,16 @@ import twemoji from 'twemoji';
|
|||||||
import { override } from 'flarum/common/extend';
|
import { override } from 'flarum/common/extend';
|
||||||
import Post from 'flarum/common/models/Post';
|
import Post from 'flarum/common/models/Post';
|
||||||
|
|
||||||
import base from './cdn';
|
import cdn from '../common/cdn';
|
||||||
|
|
||||||
const options = {
|
function options() {
|
||||||
base,
|
return {
|
||||||
attributes: () => ({
|
base: cdn(),
|
||||||
loading: 'lazy',
|
attributes: () => ({
|
||||||
}),
|
loading: 'lazy',
|
||||||
};
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an HTML string into a `<body>` node containing the HTML content.
|
* Parses an HTML string into a `<body>` node containing the HTML content.
|
||||||
@@ -40,7 +42,7 @@ export default function renderEmoji() {
|
|||||||
// element. This gets stripped below.
|
// element. This gets stripped below.
|
||||||
//
|
//
|
||||||
// See https://github.com/flarum/core/issues/2958
|
// See https://github.com/flarum/core/issues/2958
|
||||||
const emojifiedDom = twemoji.parse(parseHTML(contentHtml), options);
|
const emojifiedDom = twemoji.parse(parseHTML(contentHtml), options());
|
||||||
|
|
||||||
// Steal the HTML string inside the emojified DOM `<body>` tag.
|
// Steal the HTML string inside the emojified DOM `<body>` tag.
|
||||||
this.emojifiedContentHtml = emojifiedDom.innerHTML;
|
this.emojifiedContentHtml = emojifiedDom.innerHTML;
|
||||||
@@ -54,6 +56,6 @@ export default function renderEmoji() {
|
|||||||
override(s9e.TextFormatter, 'preview', (original, text, element) => {
|
override(s9e.TextFormatter, 'preview', (original, text, element) => {
|
||||||
original(text, element);
|
original(text, element);
|
||||||
|
|
||||||
twemoji.parse(element, options);
|
twemoji.parse(element, options());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,14 @@ flarum-emoji:
|
|||||||
# UNIQUE KEYS - The following keys are used in only one location each.
|
# UNIQUE KEYS - The following keys are used in only one location each.
|
||||||
##
|
##
|
||||||
|
|
||||||
|
# Translations in this namespace are used by the admin interface.
|
||||||
|
admin:
|
||||||
|
|
||||||
|
# These translations are used in the Settings page of the admin interface.
|
||||||
|
settings:
|
||||||
|
cdn_label: CDN mirror address
|
||||||
|
cdn_help: "e.g. https://cdn.jsdelivr.net/gh/twitter/twemoji@[version]/assets/, The current version is: {version}"
|
||||||
|
|
||||||
# Translations in this namespace are used by the forum user interface.
|
# Translations in this namespace are used by the forum user interface.
|
||||||
forum:
|
forum:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user