From 5f65bf420c2f39e13c92545cdf036abf20479f1e Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 10 Feb 2016 15:48:08 -0500 Subject: [PATCH] FIX: Support the plugin-api for decorators --- .../discourse/initializers/post-decorations.js.es6 | 8 ++++---- app/assets/javascripts/discourse/lib/plugin-api.js.es6 | 5 ++--- .../javascripts/discourse/widgets/post-cooked.js.es6 | 9 +++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/post-decorations.js.es6 b/app/assets/javascripts/discourse/initializers/post-decorations.js.es6 index 5d82473b89a..26c9ec600c4 100644 --- a/app/assets/javascripts/discourse/initializers/post-decorations.js.es6 +++ b/app/assets/javascripts/discourse/initializers/post-decorations.js.es6 @@ -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); } }; diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index 8b51a87fadb..874a10527c0 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -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); } diff --git a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 index b4d0a7bde43..e018f650dac 100644 --- a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 @@ -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]; }