1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 22:20:21 +02:00

Update for beta 8

This commit is contained in:
Toby Zerner
2018-11-16 13:57:38 +10:30
parent 8d5d5a2dad
commit d748d8739d
19 changed files with 4883 additions and 593 deletions

View File

@@ -0,0 +1,10 @@
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export * from './src/forum';

View File

@@ -1,10 +0,0 @@
var gulp = require('flarum-gulp');
gulp({
files: [
'bower_components/iframe-resizer/js/iframeResizer.contentWindow.min.js'
],
modules: {
'flarum/embed': 'src/**/*.js'
}
});

View File

@@ -1,6 +0,0 @@
{
"name": "flarum-embed",
"devDependencies": {
"iframe-resizer": "^3.2.0"
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +0,0 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"flarum-gulp": "^0.2.0"
}
}

View File

@@ -1,51 +0,0 @@
import BaseDiscussionPage from 'flarum/components/DiscussionPage';
import LoadingIndicator from 'flarum/components/LoadingIndicator';
import listItems from 'flarum/helpers/listItems';
export default class DiscussionPage extends BaseDiscussionPage {
init() {
super.init();
this.bodyClass = null;
}
view() {
return (
<div className="DiscussionPage">
<div class="container">
<div className="DiscussionPage-discussion">
{this.discussion ? [
<nav className="DiscussionPage-nav--embed">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>,
<div className="DiscussionPage-stream">
{this.stream.render()}
</div>
] : (
<LoadingIndicator className="LoadingIndicator--block"/>
)}
</div>
</div>
</div>
);
}
sidebarItems() {
const items = super.sidebarItems();
items.remove('scrubber');
const count = this.discussion.repliesCount();
items.add('replies', <h3>
<a href={app.route.discussion(this.discussion).replace('/embed', '/d')} config={m.route}>
{count} comment{count == 1 ? '' : 's'}
</a>
</h3>, 100);
const props = items.get('controls').props;
props.className = props.className.replace('App-primaryControl', '');
return items;
}
}

View File

@@ -1,113 +0,0 @@
import { override, extend } from 'flarum/extend';
import app from 'flarum/app';
import Composer from 'flarum/components/Composer';
import PostStream from 'flarum/components/PostStream';
import ModalManager from 'flarum/components/ModalManager';
import AlertManager from 'flarum/components/AlertManager';
import PostMeta from 'flarum/components/PostMeta';
import mapRoutes from 'flarum/utils/mapRoutes';
import Pane from 'flarum/utils/Pane';
import Drawer from 'flarum/utils/Drawer';
import ScrollListener from 'flarum/utils/ScrollListener';
import DiscussionPage from 'flarum/embed/components/DiscussionPage';
app.initializers.replace('boot', () => {
m.route.mode = 'pathname';
override(m, 'route', function(original, root, arg1, arg2, vdom) {
if (arguments.length === 1) {
} else if (arguments.length === 4 && typeof arg1 === 'string') {
} else if (root.addEventListener || root.attachEvent) {
root.href = vdom.attrs.href.replace('/embed', '/d');
root.target = '_blank';
// TODO: If href leads to a post within this discussion that we have
// already loaded, then scroll to it?
return;
}
return original.apply(this, Array.prototype.slice.call(arguments, 1));
});
// Trim the /embed prefix off of post permalinks
override(PostMeta.prototype, 'getPermalink', (original, post) => {
return original(post).replace('/embed', '/d');
});
app.pageInfo = m.prop({});
const reposition = function() {
const info = app.pageInfo();
this.$().css('top', Math.max(0, info.scrollTop - info.offsetTop));
};
extend(ModalManager.prototype, 'show', reposition);
extend(Composer.prototype, 'show', reposition);
window.iFrameResizer = {
readyCallback: function() {
window.parentIFrame.getPageInfo(app.pageInfo);
}
};
extend(PostStream.prototype, 'goToNumber', function(promise, number) {
if (number === 'reply' && 'parentIFrame' in window && app.composer.isFullScreen()) {
const itemTop = this.$('.PostStream-item:last').offset().top;
window.parentIFrame.scrollToOffset(0, itemTop);
}
});
app.pane = new Pane(document.getElementById('app'));
app.drawer = new Drawer();
app.composer = m.mount(document.getElementById('composer'), Composer.component());
app.modal = m.mount(document.getElementById('modal'), ModalManager.component());
app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component());
app.viewingDiscussion = function(discussion) {
return this.current instanceof DiscussionPage && this.current.discussion === discussion;
};
delete app.routes['index.filter'];
app.routes['discussion'] = {path: '/embed/:id', component: DiscussionPage.component()};
app.routes['discussion.near'] = {path: '/embed/:id/:near', component: DiscussionPage.component()};
const basePath = app.forum.attribute('basePath');
m.route.mode = 'pathname';
m.route(
document.getElementById('content'),
basePath + '/',
mapRoutes(app.routes, basePath)
);
if (m.route.param('hideFirstPost')) {
extend(PostStream.prototype, 'view', vdom => {
if (vdom.children[0].attrs['data-number'] === 1) {
vdom.children.splice(0, 1);
}
});
}
// Add a class to the body which indicates that the page has been scrolled
// down.
new ScrollListener(top => {
const $app = $('#app');
const offset = $app.offset().top;
$app
.toggleClass('affix', top >= offset)
.toggleClass('scrolled', top > offset);
}).start();
// Initialize FastClick, which makes links and buttons much more responsive on
// touch devices.
$(() => {
FastClick.attach(document.body);
$('body').addClass('ontouchstart' in window ? 'touch' : 'no-touch');
});
app.booted = true;
});

4700
extensions/embed/js/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
{
"name": "@flarum/embed",
"version": "0.0.0",
"dependencies": {
"flarum-webpack-config": "^0.1.0-beta.8",
"iframe-resizer": "^3.6.0",
"webpack": "^4.0.0",
"webpack-cli": "^3.0.7"
},
"scripts": {
"build": "webpack --mode production --progress",
"watch": "webpack --mode development --watch"
}
}

View File

@@ -0,0 +1,93 @@
import 'iframe-resizer/js/iframeResizer.contentWindow.js';
import { override, extend } from 'flarum/extend';
import app from 'flarum/app';
import ForumApplication from 'flarum/ForumApplication';
import Composer from 'flarum/components/Composer';
import PostStream from 'flarum/components/PostStream';
import ModalManager from 'flarum/components/ModalManager';
import AlertManager from 'flarum/components/AlertManager';
import PostMeta from 'flarum/components/PostMeta';
import mapRoutes from 'flarum/utils/mapRoutes';
import Pane from 'flarum/utils/Pane';
import Drawer from 'flarum/utils/Drawer';
import ScrollListener from 'flarum/utils/ScrollListener';
import DiscussionPage from 'flarum/components/DiscussionPage';
extend(ForumApplication.prototype, 'mount', function() {
if (m.route.param('hideFirstPost')) {
extend(PostStream.prototype, 'view', vdom => {
if (vdom.children[0].attrs['data-number'] === 1) {
vdom.children.splice(0, 1);
}
});
}
});
m.route.mode = 'pathname';
override(m, 'route', function(original, root, arg1, arg2, vdom) {
if (arguments.length === 1) {
} else if (arguments.length === 4 && typeof arg1 === 'string') {
} else if (root.addEventListener || root.attachEvent) {
root.href = vdom.attrs.href.replace('/embed', '/d');
root.target = '_blank';
// TODO: If href leads to a post within this discussion that we have
// already loaded, then scroll to it?
return;
}
return original.apply(this, Array.prototype.slice.call(arguments, 1));
});
// Trim the /embed prefix off of post permalinks
override(PostMeta.prototype, 'getPermalink', (original, post) => {
return original(post).replace('/embed', '/d');
});
app.pageInfo = m.prop({});
const reposition = function() {
const info = app.pageInfo();
this.$().css('top', Math.max(0, info.scrollTop - info.offsetTop));
};
extend(ModalManager.prototype, 'show', reposition);
extend(Composer.prototype, 'show', reposition);
window.iFrameResizer = {
readyCallback: function() {
window.parentIFrame.getPageInfo(app.pageInfo);
}
};
extend(PostStream.prototype, 'goToNumber', function(promise, number) {
if (number === 'reply' && 'parentIFrame' in window && app.composer.isFullScreen()) {
const itemTop = this.$('.PostStream-item:last').offset().top;
window.parentIFrame.scrollToOffset(0, itemTop);
}
});
extend(DiscussionPage.prototype, 'sidebarItems', function(items) {
items.remove('scrubber');
const count = this.discussion.replyCount();
items.add('replies', <h3>
<a href={app.route.discussion(this.discussion).replace('/embed', '/d')} config={m.route}>
{count} comment{count == 1 ? '' : 's'}
</a>
</h3>, 100);
const props = items.get('controls').props;
props.className = props.className.replace('App-primaryControl', '');
});
delete app.routes['index.filter'];
app.routes['discussion'] = {path: '/embed/:id', component: DiscussionPage.component()};
app.routes['discussion.near'] = {path: '/embed/:id/:near', component: DiscussionPage.component()};

View File

@@ -0,0 +1,3 @@
const config = require('flarum-webpack-config');
module.exports = config();