FIX: Support the plugin-api for decorators

This commit is contained in:
Robin Ward 2016-02-10 15:48:08 -05:00
parent bc1927dc1e
commit 5f65bf420c
3 changed files with 15 additions and 7 deletions

View File

@ -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);
}
};

View File

@ -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);
}

View File

@ -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];
}