mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Initial commit
This commit is contained in:
4
extensions/sticky/js/.gitignore
vendored
Normal file
4
extensions/sticky/js/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
bower_components
|
||||
node_modules
|
||||
mithril.js
|
||||
dist
|
45
extensions/sticky/js/Gulpfile.js
Normal file
45
extensions/sticky/js/Gulpfile.js
Normal file
@@ -0,0 +1,45 @@
|
||||
var gulp = require('gulp');
|
||||
var livereload = require('gulp-livereload');
|
||||
var concat = require('gulp-concat');
|
||||
var argv = require('yargs').argv;
|
||||
var uglify = require('gulp-uglify');
|
||||
var gulpif = require('gulp-if');
|
||||
var babel = require('gulp-babel');
|
||||
var cached = require('gulp-cached');
|
||||
var remember = require('gulp-remember');
|
||||
var merge = require('merge-stream');
|
||||
var streamqueue = require('streamqueue');
|
||||
|
||||
var staticFiles = [
|
||||
'bootstrap.js'
|
||||
];
|
||||
var moduleFiles = [
|
||||
'src/**/*.js'
|
||||
];
|
||||
var modulePrefix = 'sticky';
|
||||
|
||||
gulp.task('default', function() {
|
||||
return streamqueue({objectMode: true},
|
||||
gulp.src(moduleFiles)
|
||||
.pipe(cached('scripts'))
|
||||
.pipe(babel({ modules: 'amd', moduleIds: true, moduleRoot: modulePrefix }))
|
||||
.pipe(remember('scripts')),
|
||||
gulp.src(staticFiles)
|
||||
.pipe(babel())
|
||||
)
|
||||
.pipe(concat('extension.js'))
|
||||
.pipe(gulpif(argv.production, uglify()))
|
||||
.pipe(gulp.dest('dist'))
|
||||
.pipe(livereload());
|
||||
});
|
||||
|
||||
gulp.task('watch', ['default'], function () {
|
||||
livereload.listen();
|
||||
var watcher = gulp.watch(moduleFiles.concat(staticFiles), ['default']);
|
||||
watcher.on('change', function (event) {
|
||||
if (event.type === 'deleted') {
|
||||
delete cached.caches.scripts[event.path];
|
||||
remember.forget('scripts', event.path);
|
||||
}
|
||||
});
|
||||
});
|
60
extensions/sticky/js/bootstrap.js
vendored
Normal file
60
extensions/sticky/js/bootstrap.js
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { extend } from 'flarum/extension-utils';
|
||||
import Model from 'flarum/model';
|
||||
import Discussion from 'flarum/models/discussion';
|
||||
import DiscussionPage from 'flarum/components/discussion-page';
|
||||
import Badge from 'flarum/components/badge';
|
||||
import ActionButton from 'flarum/components/action-button';
|
||||
import SettingsPage from 'flarum/components/settings-page';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
import app from 'flarum/app';
|
||||
|
||||
import PostDiscussionStickied from 'sticky/components/post-discussion-stickied';
|
||||
import NotificationDiscussionStickied from 'sticky/components/notification-discussion-stickied';
|
||||
|
||||
app.initializers.add('sticky', function() {
|
||||
|
||||
// Register components.
|
||||
app.postComponentRegistry['discussionStickied'] = PostDiscussionStickied;
|
||||
app.notificationComponentRegistry['discussionStickied'] = NotificationDiscussionStickied;
|
||||
|
||||
Discussion.prototype.isSticky = Model.prop('isSticky');
|
||||
|
||||
// Add a sticky badge to discussions.
|
||||
extend(Discussion.prototype, 'badges', function(badges) {
|
||||
if (this.isSticky()) {
|
||||
badges.add('sticky', Badge.component({
|
||||
label: 'Sticky',
|
||||
icon: 'thumb-tack',
|
||||
className: 'badge-sticky',
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
function toggleSticky() {
|
||||
this.save({isSticky: !this.isSticky()}).then(discussion => {
|
||||
if (app.current instanceof DiscussionPage) {
|
||||
app.current.stream().sync();
|
||||
}
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
|
||||
// Add a sticky control to discussions.
|
||||
extend(Discussion.prototype, 'controls', function(items) {
|
||||
if (this.canEdit()) {
|
||||
items.add('sticky', ActionButton.component({
|
||||
label: this.isSticky() ? 'Unsticky' : 'Sticky',
|
||||
icon: 'thumb-tack',
|
||||
onclick: toggleSticky.bind(this)
|
||||
}), {after: 'rename'});
|
||||
}
|
||||
});
|
||||
|
||||
// Add a notification preference.
|
||||
extend(SettingsPage.prototype, 'notificationTypes', function(items) {
|
||||
items.add('discussionStickied', {
|
||||
name: 'discussionStickied',
|
||||
label: [icon('thumb-tack'), ' Someone stickies a discussion I started']
|
||||
});
|
||||
});
|
||||
});
|
18
extensions/sticky/js/package.json
Normal file
18
extensions/sticky/js/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "flarum-sticky",
|
||||
"devDependencies": {
|
||||
"gulp": "^3.8.11",
|
||||
"gulp-babel": "^5.1.0",
|
||||
"gulp-cached": "^1.0.4",
|
||||
"gulp-concat": "^2.5.2",
|
||||
"gulp-if": "^1.2.5",
|
||||
"gulp-livereload": "^3.8.0",
|
||||
"gulp-remember": "^0.3.0",
|
||||
"gulp-uglify": "^1.2.0",
|
||||
"merge-stream": "^0.1.7",
|
||||
"yargs": "^3.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"streamqueue": "^0.1.3"
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
import Notification from 'flarum/components/notification';
|
||||
import username from 'flarum/helpers/username';
|
||||
|
||||
export default class NotificationDiscussionStickied extends Notification {
|
||||
view() {
|
||||
var notification = this.props.notification;
|
||||
var discussion = notification.subject();
|
||||
|
||||
return super.view({
|
||||
href: app.route('discussion.near', {
|
||||
id: discussion.id(),
|
||||
slug: discussion.slug(),
|
||||
near: notification.content().postNumber
|
||||
}),
|
||||
config: m.route,
|
||||
title: discussion.title(),
|
||||
icon: 'thumb-tack',
|
||||
content: ['Stickied by ', username(notification.sender())]
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
import PostActivity from 'flarum/components/post-activity';
|
||||
|
||||
export default class PostDiscussionStickied extends PostActivity {
|
||||
view() {
|
||||
var post = this.props.post;
|
||||
|
||||
return super.view('thumb-tack', [post.content().sticky ? 'stickied' : 'unstickied', ' the discussion.']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user