ca10ae797a
* WIP * composer preview field working * remove redundant variable * fix linting issues * fix rubocop * remove unnecessary entry * consolidate preview generation code * add styles for onebox * add css for @ mentions * fixed eslint issues * FIX: ensure oneboxes load every time * remove unused import * fix prettier issues * removed unused code * remove unused imports * fixed prettier issue * improve css structure * add csrf header in all cases
49 Zeilen
1,2 KiB
JavaScript
49 Zeilen
1,2 KiB
JavaScript
import Component from "@ember/component";
|
|
import { loadOneboxes } from "discourse/lib/load-oneboxes";
|
|
import { schedule } from "@ember/runloop";
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
|
import { resolveAllShortUrls } from "pretty-text/upload-short-url";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { on } from "discourse-common/utils/decorators";
|
|
|
|
export default Component.extend({
|
|
@on("init")
|
|
updatePreview() {
|
|
if (this.isDestroyed) {
|
|
return;
|
|
}
|
|
|
|
schedule("afterRender", () => {
|
|
if (this._state !== "inDOM" || !this.element) {
|
|
return;
|
|
}
|
|
|
|
const $preview = $(this.element);
|
|
|
|
if ($preview.length === 0) {
|
|
return;
|
|
}
|
|
|
|
this.previewUpdated($preview);
|
|
});
|
|
},
|
|
|
|
previewUpdated($preview) {
|
|
// Paint oneboxes
|
|
const paintFunc = () => {
|
|
loadOneboxes(
|
|
$preview[0],
|
|
ajax,
|
|
null,
|
|
null,
|
|
this.siteSettings.max_oneboxes_per_post,
|
|
true // refresh on every load
|
|
);
|
|
};
|
|
|
|
discourseDebounce(this, paintFunc, 450);
|
|
|
|
// Short upload urls need resolution
|
|
resolveAllShortUrls(ajax, this.siteSettings, $preview[0]);
|
|
},
|
|
});
|