FIX: Support the plugin-api for decorators
This commit is contained in:
parent
bc1927dc1e
commit
5f65bf420c
|
@ -1,11 +1,11 @@
|
||||||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
import { decorateCooked } from 'discourse/lib/plugin-api';
|
||||||
import HighlightSyntax from 'discourse/lib/highlight-syntax';
|
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||||
import Lightbox from 'discourse/lib/lightbox';
|
import lightbox from 'discourse/lib/lightbox';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "post-decorations",
|
name: "post-decorations",
|
||||||
initialize: function(container) {
|
initialize: function(container) {
|
||||||
decorateCooked(container, HighlightSyntax);
|
decorateCooked(container, highlightSyntax);
|
||||||
decorateCooked(container, Lightbox);
|
decorateCooked(container, lightbox);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { addDecorator } from 'discourse/widgets/post-cooked';
|
||||||
import ComposerEditor from 'discourse/components/composer-editor';
|
import ComposerEditor from 'discourse/components/composer-editor';
|
||||||
|
|
||||||
let _decorateId = 0;
|
let _decorateId = 0;
|
||||||
|
@ -8,9 +9,7 @@ function decorate(klass, evt, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decorateCooked(container, cb) {
|
export function decorateCooked(container, cb) {
|
||||||
const postView = container.lookupFactory('view:post');
|
addDecorator(cb);
|
||||||
decorate(postView, 'postViewInserted', cb);
|
|
||||||
decorate(postView, 'postViewUpdated', cb);
|
|
||||||
decorate(ComposerEditor, 'previewRefreshed', cb);
|
decorate(ComposerEditor, 'previewRefreshed', cb);
|
||||||
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
import { isValidLink } from 'discourse/lib/click-track';
|
import { isValidLink } from 'discourse/lib/click-track';
|
||||||
import { number } from 'discourse/lib/formatter';
|
import { number } from 'discourse/lib/formatter';
|
||||||
|
|
||||||
|
const _decorators = [];
|
||||||
|
|
||||||
|
// Don't call this directly: use `plugin-api/decorateCooked`
|
||||||
|
export function addDecorator(cb) {
|
||||||
|
_decorators.push(cb);
|
||||||
|
}
|
||||||
|
|
||||||
export default class PostCooked {
|
export default class PostCooked {
|
||||||
|
|
||||||
constructor(attrs) {
|
constructor(attrs) {
|
||||||
|
@ -21,6 +28,8 @@ export default class PostCooked {
|
||||||
this._showLinkCounts($html);
|
this._showLinkCounts($html);
|
||||||
this._fixImageSizes($html);
|
this._fixImageSizes($html);
|
||||||
this._applySearchHighlight($html);
|
this._applySearchHighlight($html);
|
||||||
|
|
||||||
|
_decorators.forEach(cb => cb($html));
|
||||||
return $html[0];
|
return $html[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue