mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:18:18 +08:00
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 HighlightSyntax from 'discourse/lib/highlight-syntax';
|
||||
import Lightbox from 'discourse/lib/lightbox';
|
||||
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||
import lightbox from 'discourse/lib/lightbox';
|
||||
|
||||
export default {
|
||||
name: "post-decorations",
|
||||
initialize: function(container) {
|
||||
decorateCooked(container, HighlightSyntax);
|
||||
decorateCooked(container, Lightbox);
|
||||
decorateCooked(container, highlightSyntax);
|
||||
decorateCooked(container, lightbox);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { addDecorator } from 'discourse/widgets/post-cooked';
|
||||
import ComposerEditor from 'discourse/components/composer-editor';
|
||||
|
||||
let _decorateId = 0;
|
||||
|
@ -8,9 +9,7 @@ function decorate(klass, evt, cb) {
|
|||
}
|
||||
|
||||
export function decorateCooked(container, cb) {
|
||||
const postView = container.lookupFactory('view:post');
|
||||
decorate(postView, 'postViewInserted', cb);
|
||||
decorate(postView, 'postViewUpdated', cb);
|
||||
addDecorator(cb);
|
||||
decorate(ComposerEditor, 'previewRefreshed', cb);
|
||||
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import { isValidLink } from 'discourse/lib/click-track';
|
||||
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 {
|
||||
|
||||
constructor(attrs) {
|
||||
|
@ -21,6 +28,8 @@ export default class PostCooked {
|
|||
this._showLinkCounts($html);
|
||||
this._fixImageSizes($html);
|
||||
this._applySearchHighlight($html);
|
||||
|
||||
_decorators.forEach(cb => cb($html));
|
||||
return $html[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user