mirror of
https://github.com/flarum/core.git
synced 2025-08-06 00:17:31 +02:00
Update for composer branch
This commit is contained in:
3
extensions/likes/js/.gitignore
vendored
3
extensions/likes/js/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
bower_components
|
||||
node_modules
|
||||
dist
|
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'likes': 'src/**/*.js'
|
||||
'flarum/likes': 'src/**/*.js'
|
||||
}
|
||||
});
|
||||
|
26
extensions/likes/js/admin/dist/extension.js
vendored
Normal file
26
extensions/likes/js/admin/dist/extension.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
System.register('flarum/likes/main', ['flarum/extend', 'flarum/app', 'flarum/components/PermissionGrid'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, app, PermissionGrid;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumComponentsPermissionGrid) {
|
||||
PermissionGrid = _flarumComponentsPermissionGrid['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-likes', function () {
|
||||
extend(PermissionGrid.prototype, 'replyItems', function (items) {
|
||||
items.add('likePosts', {
|
||||
icon: 'thumbs-o-up',
|
||||
label: 'Like posts',
|
||||
permission: 'discussion.likePosts'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
@@ -2,7 +2,7 @@ import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import PermissionGrid from 'flarum/components/PermissionGrid';
|
||||
|
||||
app.initializers.add('likes', () => {
|
||||
app.initializers.add('flarum-likes', () => {
|
||||
extend(PermissionGrid.prototype, 'replyItems', items => {
|
||||
items.add('likePosts', {
|
||||
icon: 'thumbs-o-up',
|
||||
|
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'likes': 'src/**/*.js'
|
||||
'flarum/likes': 'src/**/*.js'
|
||||
}
|
||||
});
|
||||
|
285
extensions/likes/js/forum/dist/extension.js
vendored
Normal file
285
extensions/likes/js/forum/dist/extension.js
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
System.register('flarum/likes/addLikeAction', ['flarum/extend', 'flarum/app', 'flarum/components/Button', 'flarum/components/CommentPost'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, app, Button, CommentPost;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumComponentsButton) {
|
||||
Button = _flarumComponentsButton['default'];
|
||||
}, function (_flarumComponentsCommentPost) {
|
||||
CommentPost = _flarumComponentsCommentPost['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
_export('default', function () {
|
||||
extend(CommentPost.prototype, 'actionItems', function (items) {
|
||||
var post = this.props.post;
|
||||
|
||||
if (post.isHidden() || !post.canLike()) return;
|
||||
|
||||
var isLiked = app.session.user && post.likes().some(function (user) {
|
||||
return user === app.session.user;
|
||||
});
|
||||
|
||||
items.add('like', Button.component({
|
||||
children: app.trans(isLiked ? 'flarum-likes.forum.unlike_action' : 'flarum-likes.forum.like_action'),
|
||||
className: 'Button Button--link',
|
||||
onclick: function onclick() {
|
||||
isLiked = !isLiked;
|
||||
|
||||
post.save({ isLiked: isLiked });
|
||||
|
||||
// We've saved the fact that we do or don't like the post, but in order
|
||||
// to provide instantaneous feedback to the user, we'll need to add or
|
||||
// remove the like from the relationship data manually.
|
||||
var data = post.data.relationships.likes.data;
|
||||
data.some(function (like, i) {
|
||||
if (like.id === app.session.user.id()) {
|
||||
data.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (isLiked) {
|
||||
data.unshift({ type: 'users', id: app.session.user.id() });
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/likes/addLikesList', ['flarum/extend', 'flarum/app', 'flarum/components/CommentPost', 'flarum/helpers/punctuateSeries', 'flarum/helpers/username', 'flarum/helpers/icon', 'flarum/likes/components/PostLikesModal'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, app, CommentPost, punctuateSeries, username, icon, PostLikesModal;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumComponentsCommentPost) {
|
||||
CommentPost = _flarumComponentsCommentPost['default'];
|
||||
}, function (_flarumHelpersPunctuateSeries) {
|
||||
punctuateSeries = _flarumHelpersPunctuateSeries['default'];
|
||||
}, function (_flarumHelpersUsername) {
|
||||
username = _flarumHelpersUsername['default'];
|
||||
}, function (_flarumHelpersIcon) {
|
||||
icon = _flarumHelpersIcon['default'];
|
||||
}, function (_flarumLikesComponentsPostLikesModal) {
|
||||
PostLikesModal = _flarumLikesComponentsPostLikesModal['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
_export('default', function () {
|
||||
extend(CommentPost.prototype, 'footerItems', function (items) {
|
||||
var post = this.props.post;
|
||||
var likes = post.likes();
|
||||
|
||||
if (likes && likes.length) {
|
||||
var limit = 3;
|
||||
|
||||
// Construct a list of names of users who have like this post. Make sure the
|
||||
// current user is first in the list, and cap a maximum of 3 names.
|
||||
var names = likes.sort(function (a) {
|
||||
return a === app.session.user ? -1 : 1;
|
||||
}).slice(0, limit).map(function (user) {
|
||||
return m(
|
||||
'a',
|
||||
{ href: app.route.user(user), config: m.route },
|
||||
user === app.session.user ? app.trans('flarum-likes.forum.you') : username(user)
|
||||
);
|
||||
});
|
||||
|
||||
// If there are more users that we've run out of room to display, add a "x
|
||||
// others" name to the end of the list. Clicking on it will display a modal
|
||||
// with a full list of names.
|
||||
if (likes.length > limit) {
|
||||
names.push(m(
|
||||
'a',
|
||||
{ href: '#', onclick: function (e) {
|
||||
e.preventDefault();
|
||||
app.modal.show(new PostLikesModal({ post: post }));
|
||||
} },
|
||||
app.trans('flarum-likes.forum.others', { count: likes.length - limit })
|
||||
));
|
||||
}
|
||||
|
||||
items.add('liked', m(
|
||||
'div',
|
||||
{ className: 'Post-likedBy' },
|
||||
icon('thumbs-o-up'),
|
||||
app.trans('flarum-likes.forum.post_liked_by' + (likes[0] === app.session.user ? '_self' : ''), {
|
||||
count: names.length,
|
||||
users: punctuateSeries(names)
|
||||
})
|
||||
));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/likes/main', ['flarum/extend', 'flarum/app', 'flarum/models/Post', 'flarum/Model', 'flarum/components/NotificationGrid', 'flarum/likes/addLikeAction', 'flarum/likes/addLikesList', 'flarum/likes/components/PostLikedNotification'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, app, Post, Model, NotificationGrid, addLikeAction, addLikesList, PostLikedNotification;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumModelsPost) {
|
||||
Post = _flarumModelsPost['default'];
|
||||
}, function (_flarumModel) {
|
||||
Model = _flarumModel['default'];
|
||||
}, function (_flarumComponentsNotificationGrid) {
|
||||
NotificationGrid = _flarumComponentsNotificationGrid['default'];
|
||||
}, function (_flarumLikesAddLikeAction) {
|
||||
addLikeAction = _flarumLikesAddLikeAction['default'];
|
||||
}, function (_flarumLikesAddLikesList) {
|
||||
addLikesList = _flarumLikesAddLikesList['default'];
|
||||
}, function (_flarumLikesComponentsPostLikedNotification) {
|
||||
PostLikedNotification = _flarumLikesComponentsPostLikedNotification['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-likes', function () {
|
||||
app.notificationComponents.postLiked = PostLikedNotification;
|
||||
|
||||
Post.prototype.canLike = Model.attribute('canLike');
|
||||
Post.prototype.likes = Model.hasMany('likes');
|
||||
|
||||
addLikeAction();
|
||||
addLikesList();
|
||||
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||
items.add('postLiked', {
|
||||
name: 'postLiked',
|
||||
icon: 'thumbs-o-up',
|
||||
label: app.trans('flarum-likes.forum.notify_post_liked')
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/likes/components/PostLikedNotification', ['flarum/components/Notification', 'flarum/helpers/username', 'flarum/helpers/punctuate'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var Notification, username, punctuate, PostLikedNotification;
|
||||
return {
|
||||
setters: [function (_flarumComponentsNotification) {
|
||||
Notification = _flarumComponentsNotification['default'];
|
||||
}, function (_flarumHelpersUsername) {
|
||||
username = _flarumHelpersUsername['default'];
|
||||
}, function (_flarumHelpersPunctuate) {
|
||||
punctuate = _flarumHelpersPunctuate['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
PostLikedNotification = (function (_Notification) {
|
||||
babelHelpers.inherits(PostLikedNotification, _Notification);
|
||||
|
||||
function PostLikedNotification() {
|
||||
babelHelpers.classCallCheck(this, PostLikedNotification);
|
||||
babelHelpers.get(Object.getPrototypeOf(PostLikedNotification.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(PostLikedNotification, [{
|
||||
key: 'icon',
|
||||
value: function icon() {
|
||||
return 'thumbs-o-up';
|
||||
}
|
||||
}, {
|
||||
key: 'href',
|
||||
value: function href() {
|
||||
return app.route.post(this.props.notification.subject());
|
||||
}
|
||||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
var notification = this.props.notification;
|
||||
var user = notification.sender();
|
||||
var auc = notification.additionalUnreadCount();
|
||||
|
||||
return app.trans('flarum-likes.forum.post_liked_notification', {
|
||||
user: user,
|
||||
username: auc ? punctuate([username(user), app.trans('flarum-likes.forum.others', { count: auc })]) : undefined
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'excerpt',
|
||||
value: function excerpt() {
|
||||
return this.props.notification.subject().contentPlain();
|
||||
}
|
||||
}]);
|
||||
return PostLikedNotification;
|
||||
})(Notification);
|
||||
|
||||
_export('default', PostLikedNotification);
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/likes/components/PostLikesModal', ['flarum/components/Modal', 'flarum/helpers/avatar', 'flarum/helpers/username'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var Modal, avatar, username, PostLikesModal;
|
||||
return {
|
||||
setters: [function (_flarumComponentsModal) {
|
||||
Modal = _flarumComponentsModal['default'];
|
||||
}, function (_flarumHelpersAvatar) {
|
||||
avatar = _flarumHelpersAvatar['default'];
|
||||
}, function (_flarumHelpersUsername) {
|
||||
username = _flarumHelpersUsername['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
PostLikesModal = (function (_Modal) {
|
||||
babelHelpers.inherits(PostLikesModal, _Modal);
|
||||
|
||||
function PostLikesModal() {
|
||||
babelHelpers.classCallCheck(this, PostLikesModal);
|
||||
babelHelpers.get(Object.getPrototypeOf(PostLikesModal.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(PostLikesModal, [{
|
||||
key: 'className',
|
||||
value: function className() {
|
||||
return 'PostLikesModal Modal--small';
|
||||
}
|
||||
}, {
|
||||
key: 'title',
|
||||
value: function title() {
|
||||
return app.trans('likes.post_likes_modal_title');
|
||||
}
|
||||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
return m(
|
||||
'div',
|
||||
{ className: 'Modal-body' },
|
||||
m(
|
||||
'ul',
|
||||
{ className: 'PostLikesModal-list' },
|
||||
this.props.post.likes().map(function (user) {
|
||||
return m(
|
||||
'li',
|
||||
null,
|
||||
m(
|
||||
'a',
|
||||
{ href: app.route.user(user), config: m.route },
|
||||
avatar(user),
|
||||
' ',
|
||||
' ',
|
||||
username(user)
|
||||
)
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}]);
|
||||
return PostLikesModal;
|
||||
})(Modal);
|
||||
|
||||
_export('default', PostLikesModal);
|
||||
}
|
||||
};
|
||||
});
|
@@ -13,7 +13,7 @@ export default function() {
|
||||
|
||||
items.add('like',
|
||||
Button.component({
|
||||
children: app.trans(isLiked ? 'likes.unlike_action' : 'likes.like_action'),
|
||||
children: app.trans(isLiked ? 'flarum-likes.forum.unlike_action' : 'flarum-likes.forum.like_action'),
|
||||
className: 'Button Button--link',
|
||||
onclick: () => {
|
||||
isLiked = !isLiked;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
import punctuate from 'flarum/helpers/punctuate';
|
||||
import punctuateSeries from 'flarum/helpers/punctuateSeries';
|
||||
import username from 'flarum/helpers/username';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
|
||||
import PostLikesModal from 'likes/components/PostLikesModal';
|
||||
import PostLikesModal from 'flarum/likes/components/PostLikesModal';
|
||||
|
||||
export default function() {
|
||||
extend(CommentPost.prototype, 'footerItems', function(items) {
|
||||
@@ -22,7 +22,7 @@ export default function() {
|
||||
.map(user => {
|
||||
return (
|
||||
<a href={app.route.user(user)} config={m.route}>
|
||||
{user === app.session.user ? app.trans('likes.you') : username(user)}
|
||||
{user === app.session.user ? app.trans('flarum-likes.forum.you') : username(user)}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
@@ -36,7 +36,7 @@ export default function() {
|
||||
e.preventDefault();
|
||||
app.modal.show(new PostLikesModal({post}));
|
||||
}}>
|
||||
{app.trans('likes.others', {count: likes.length - limit})}
|
||||
{app.trans('flarum-likes.forum.others', {count: likes.length - limit})}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -44,9 +44,9 @@ export default function() {
|
||||
items.add('liked', (
|
||||
<div className="Post-likedBy">
|
||||
{icon('thumbs-o-up')}
|
||||
{app.trans('likes.post_liked_by' + (likes[0] === app.session.user ? '_self' : ''), {
|
||||
{app.trans('flarum-likes.forum.post_liked_by' + (likes[0] === app.session.user ? '_self' : ''), {
|
||||
count: names.length,
|
||||
users: punctuate(names)
|
||||
users: punctuateSeries(names)
|
||||
})}
|
||||
</div>
|
||||
));
|
||||
|
@@ -16,11 +16,11 @@ export default class PostLikedNotification extends Notification {
|
||||
const user = notification.sender();
|
||||
const auc = notification.additionalUnreadCount();
|
||||
|
||||
return app.trans('likes.post_liked_notification', {
|
||||
return app.trans('flarum-likes.forum.post_liked_notification', {
|
||||
user,
|
||||
username: auc ? punctuate([
|
||||
username(user),
|
||||
app.trans('likes.others', {count: auc})
|
||||
app.trans('flarum-likes.forum.others', {count: auc})
|
||||
]) : undefined
|
||||
});
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ export default class PostLikesModal extends Modal {
|
||||
{this.props.post.likes().map(user => (
|
||||
<li>
|
||||
<a href={app.route.user(user)} config={m.route}>
|
||||
{avatar(user)}{' '}
|
||||
{avatar(user)} {' '}
|
||||
{username(user)}
|
||||
</a>
|
||||
</li>
|
||||
|
@@ -4,22 +4,24 @@ import Post from 'flarum/models/Post';
|
||||
import Model from 'flarum/Model';
|
||||
import NotificationGrid from 'flarum/components/NotificationGrid';
|
||||
|
||||
import addLikeAction from 'likes/addLikeAction';
|
||||
import addLikesList from 'likes/addLikesList';
|
||||
import PostLikedNotification from 'likes/components/PostLikedNotification';
|
||||
import addLikeAction from 'flarum/likes/addLikeAction';
|
||||
import addLikesList from 'flarum/likes/addLikesList';
|
||||
import PostLikedNotification from 'flarum/likes/components/PostLikedNotification';
|
||||
|
||||
app.notificationComponents.postLiked = PostLikedNotification;
|
||||
app.initializers.add('flarum-likes', () => {
|
||||
app.notificationComponents.postLiked = PostLikedNotification;
|
||||
|
||||
Post.prototype.canLike = Model.attribute('canLike');
|
||||
Post.prototype.likes = Model.hasMany('likes');
|
||||
Post.prototype.canLike = Model.attribute('canLike');
|
||||
Post.prototype.likes = Model.hasMany('likes');
|
||||
|
||||
addLikeAction();
|
||||
addLikesList();
|
||||
addLikeAction();
|
||||
addLikesList();
|
||||
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function(items) {
|
||||
items.add('postLiked', {
|
||||
name: 'postLiked',
|
||||
icon: 'thumbs-o-up',
|
||||
label: app.trans('likes.notify_post_liked')
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||
items.add('postLiked', {
|
||||
name: 'postLiked',
|
||||
icon: 'thumbs-o-up',
|
||||
label: app.trans('flarum-likes.forum.notify_post_liked')
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user