From 5bc55e453802d82cc94490b4737b8a9b6c2e3fa5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 28 May 2016 09:44:44 +0930 Subject: [PATCH] Make Post component subclasses build on parent content Extensions may wish to add attributes/content to all posts, regardless of type, by extending methods on the Post component. Now the subclasses will not overwrite, but rather append to, these additions. --- framework/core/js/forum/dist/app.js | 37 ++++++++++--------- .../js/forum/src/components/CommentPost.js | 23 ++++++------ .../core/js/forum/src/components/EventPost.js | 12 +++--- .../core/js/forum/src/components/Post.js | 4 +- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index da2e30235..d4e9aef63 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -19593,7 +19593,7 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla }, { key: 'content', value: function content() { - return [m( + return babelHelpers.get(Object.getPrototypeOf(CommentPost.prototype), 'content', this).call(this).concat([m( 'header', { className: 'Post-header' }, m( @@ -19605,7 +19605,7 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla 'div', { className: 'Post-body' }, this.isEditing() ? m('div', { className: 'Post-preview', config: this.configPreview.bind(this) }) : m.trust(this.props.post.contentHtml()) - )]; + )]); } }, { key: 'config', @@ -19634,16 +19634,17 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla key: 'attrs', value: function attrs() { var post = this.props.post; + var attrs = babelHelpers.get(Object.getPrototypeOf(CommentPost.prototype), 'attrs', this).call(this); - return { - className: classList({ - 'CommentPost': true, - 'Post--hidden': post.isHidden(), - 'Post--edited': post.isEdited(), - 'revealContent': this.revealContent, - 'editing': this.isEditing() - }) - }; + attrs.className += ' ' + classList({ + 'CommentPost': true, + 'Post--hidden': post.isHidden(), + 'Post--edited': post.isEdited(), + 'revealContent': this.revealContent, + 'editing': this.isEditing() + }); + + return attrs; } }, { key: 'configPreview', @@ -21909,9 +21910,11 @@ System.register('flarum/components/EventPost', ['flarum/components/Post', 'flaru babelHelpers.createClass(EventPost, [{ key: 'attrs', value: function attrs() { - return { - className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post' - }; + var attrs = babelHelpers.get(Object.getPrototypeOf(EventPost.prototype), 'attrs', this).call(this); + + attrs.className += ' EventPost ' + ucfirst(this.props.post.contentType()) + 'Post'; + + return attrs; } }, { key: 'content', @@ -21927,11 +21930,11 @@ System.register('flarum/components/EventPost', ['flarum/components/Post', 'flaru ) : username }); - return [icon(this.icon(), { className: 'EventPost-icon' }), m( + return babelHelpers.get(Object.getPrototypeOf(EventPost.prototype), 'content', this).call(this).concat([icon(this.icon(), { className: 'EventPost-icon' }), m( 'div', { 'class': 'EventPost-info' }, this.description(data) - )]; + )]); } }, { key: 'icon', @@ -24317,7 +24320,7 @@ System.register('flarum/components/Post', ['flarum/Component', 'flarum/utils/Sub }, { key: 'content', value: function content() { - return ''; + return []; } }, { key: 'actionItems', diff --git a/framework/core/js/forum/src/components/CommentPost.js b/framework/core/js/forum/src/components/CommentPost.js index e0be874a7..8a6b72a7e 100644 --- a/framework/core/js/forum/src/components/CommentPost.js +++ b/framework/core/js/forum/src/components/CommentPost.js @@ -42,14 +42,14 @@ export default class CommentPost extends Post { } content() { - return [ + return super.content().concat([
,
{this.isEditing() ?
: m.trust(this.props.post.contentHtml())}
- ]; + ]); } config(isInitialized, context) { @@ -76,16 +76,17 @@ export default class CommentPost extends Post { attrs() { const post = this.props.post; + const attrs = super.attrs(); - return { - className: classList({ - 'CommentPost': true, - 'Post--hidden': post.isHidden(), - 'Post--edited': post.isEdited(), - 'revealContent': this.revealContent, - 'editing': this.isEditing() - }) - }; + attrs.className += ' '+classList({ + 'CommentPost': true, + 'Post--hidden': post.isHidden(), + 'Post--edited': post.isEdited(), + 'revealContent': this.revealContent, + 'editing': this.isEditing() + }); + + return attrs; } configPreview(element, isInitialized, context) { diff --git a/framework/core/js/forum/src/components/EventPost.js b/framework/core/js/forum/src/components/EventPost.js index 7cfcbbefd..ccc7b512e 100644 --- a/framework/core/js/forum/src/components/EventPost.js +++ b/framework/core/js/forum/src/components/EventPost.js @@ -16,9 +16,11 @@ import icon from 'flarum/helpers/icon'; */ export default class EventPost extends Post { attrs() { - return { - className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post' - }; + const attrs = super.attrs(); + + attrs.className += ' EventPost ' + ucfirst(this.props.post.contentType()) + 'Post'; + + return attrs; } content() { @@ -31,12 +33,12 @@ export default class EventPost extends Post { : username }); - return [ + return super.content().concat([ icon(this.icon(), {className: 'EventPost-icon'}),
{this.description(data)}
- ]; + ]); } /** diff --git a/framework/core/js/forum/src/components/Post.js b/framework/core/js/forum/src/components/Post.js index e760a5c71..5c514ac1b 100644 --- a/framework/core/js/forum/src/components/Post.js +++ b/framework/core/js/forum/src/components/Post.js @@ -92,10 +92,10 @@ export default class Post extends Component { /** * Get the post's content. * - * @return {Object} + * @return {Array} */ content() { - return ''; + return []; } /**