mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
Add CDN constant & use jsDelivr in all places (#30)
* Add CDN file for twemoji version & assets base URL * Add /assets/ to the URL so it's not repeated as much * The previous MaxCDN URL didn't need /assets/ because it was specificly for twemoji * Remove export of CDN - shouldn't be part of this PR
This commit is contained in:
parent
acf0c51cb4
commit
0b1fe99ec5
|
@ -4,10 +4,11 @@ import emojiMap from 'simple-emoji-map';
|
||||||
import { extend } from 'flarum/extend';
|
import { extend } from 'flarum/extend';
|
||||||
import TextEditor from 'flarum/components/TextEditor';
|
import TextEditor from 'flarum/components/TextEditor';
|
||||||
import TextEditorButton from 'flarum/components/TextEditorButton';
|
import TextEditorButton from 'flarum/components/TextEditorButton';
|
||||||
import getEmojiIconCode from './helpers/getEmojiIconCode';
|
|
||||||
import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable';
|
import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable';
|
||||||
|
|
||||||
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
||||||
|
import getEmojiIconCode from './helpers/getEmojiIconCode';
|
||||||
|
import cdn from './cdn';
|
||||||
|
|
||||||
export default function addComposerAutocomplete() {
|
export default function addComposerAutocomplete() {
|
||||||
const emojiKeys = Object.keys(emojiMap);
|
const emojiKeys = Object.keys(emojiMap);
|
||||||
|
@ -76,7 +77,7 @@ export default function addComposerAutocomplete() {
|
||||||
onmouseenter={function() {
|
onmouseenter={function() {
|
||||||
dropdown.setIndex($(this).parent().index() - 1);
|
dropdown.setIndex($(this).parent().index() - 1);
|
||||||
}}>
|
}}>
|
||||||
<img alt={emoji} class="emoji" draggable="false" src={'//cdn.jsdelivr.net/gh/twitter/twemoji@13/assets/72x72/' + code + '.png'}/>
|
<img alt={emoji} class="emoji" draggable="false" src={`${cdn}72x72/${code}.png`}/>
|
||||||
{name}
|
{name}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
5
extensions/emoji/js/src/forum/cdn.js
Normal file
5
extensions/emoji/js/src/forum/cdn.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
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/`;
|
|
@ -5,12 +5,14 @@ import twemoji from 'twemoji';
|
||||||
import { override } from 'flarum/extend';
|
import { override } from 'flarum/extend';
|
||||||
import Post from 'flarum/models/Post';
|
import Post from 'flarum/models/Post';
|
||||||
|
|
||||||
|
import base from './cdn';
|
||||||
|
|
||||||
export default function renderEmoji() {
|
export default function renderEmoji() {
|
||||||
override(Post.prototype, 'contentHtml', function(original) {
|
override(Post.prototype, 'contentHtml', function(original) {
|
||||||
const contentHtml = original();
|
const contentHtml = original();
|
||||||
|
|
||||||
if (this.oldContentHtml !== contentHtml) {
|
if (this.oldContentHtml !== contentHtml) {
|
||||||
this.emojifiedContentHtml = twemoji.parse(contentHtml);
|
this.emojifiedContentHtml = twemoji.parse(contentHtml, { base });
|
||||||
this.oldContentHtml = contentHtml;
|
this.oldContentHtml = contentHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +22,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);
|
twemoji.parse(element, { base });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user