0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 09:50:28 +01:00
discourse-custom-wizard/assets/javascripts/wizard/components/wizard-field-composer-preview.js.es6
Faizaan Gagan ca10ae797a
FEATURE: new field type Composer Preview (#130)
* 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
2021-07-12 17:05:05 +05:30

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]);
},
});