1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Refactor the web app bootstrapping code

- All custom JS variables are now preloaded into the `app.data` object, rather than directly on the `app` object. This means that admin settings are available in `app.data.settings` rather than `app.settings`, etc.
- Cleaner route handler generation
- Renamed ConfigureClientView to ConfigureWebApp, though the former still exists and is deprecated
- Partial fix for #881 (strips ?nojs=1 from URL if possible, so that refreshing will attempt to load JS version again)
This commit is contained in:
Toby Zerner
2016-05-26 19:04:24 +09:30
parent 2525e3e7ad
commit 9bfb797fdc
49 changed files with 1575 additions and 1254 deletions

View File

@@ -8,8 +8,8 @@
<div id="header-navigation" class="Header-navigation"></div>
<div class="container">
<h1 class="Header-title">
<a href="{{ $forum->attributes->baseUrl }}">
{{ $forum->attributes->title }}
<a href="{{ array_get($forum, 'attributes.baseUrl') }}">
{{ array_get($forum, 'attributes.title') }}
</a>
</h1>
<div id="header-primary" class="Header-primary"></div>

View File

@@ -2,14 +2,13 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ $title }}</title>
<meta name="description" content="{{ $forum->attributes->description }}">
<meta name="description" content="{{ $description }}">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<meta name="theme-color" content="{{ $forum->attributes->themePrimaryColor }}">
<meta name="theme-color" content="{{ array_get($forum, 'attributes.themePrimaryColor') }}">
@foreach ($styles as $file)
<link rel="stylesheet" href="{{ $forum->attributes->baseUrl . str_replace(public_path(), '', $file) }}">
@foreach ($cssUrls as $url)
<link rel="stylesheet" href="{{ $url }}">
@endforeach
{!! $head !!}
@@ -21,36 +20,40 @@
<div id="modal"></div>
<div id="alerts"></div>
@if (! $noJs)
@if ($allowJs)
<script>
document.getElementById('flarum-loading').style.display = 'block';
</script>
@foreach ($scripts as $file)
<script src="{{ $forum->attributes->baseUrl . str_replace(public_path(), '', $file) }}"></script>
@foreach ($jsUrls as $url)
<script src="{{ $url }}"></script>
@endforeach
<script>
document.getElementById('flarum-loading').style.display = 'none';
@if (! $forum->attributes->debug)
@if (! $debug)
try {
@endif
var app = System.get('flarum/app').default;
var modules = {!! json_encode($modules) !!};
babelHelpers.extends(app, {!! json_encode($app) !!});
for (var i in modules) {
var module = System.get(modules[i]);
if (module.default) module.default(app);
}
@foreach ($bootstrappers as $bootstrapper)
System.get('{{ $bootstrapper }}');
@endforeach
app.boot();
@if (! $forum->attributes->debug)
app.boot({!! json_encode($payload) !!});
@if (! $debug)
} catch (e) {
var nojs = window.location.search ? '&nojs=1' : '?nojs=1';
window.location = window.location + nojs;
window.location += (window.location.search ? '&' : '?') + 'nojs=1';
throw e;
}
@endif
</script>
@else
<script>
window.history.replaceState(null, null, window.location.toString().replace(/([&?]nojs=1$|nojs=1&)/, ''));
</script>
@endif
{!! $foot !!}

View File

@@ -2,16 +2,22 @@
{{ $translator->trans('core.views.content.loading_text') }}
</div>
@if (! $noJs) <noscript> @endif
<div class="Alert">
<div class="container">
@if ($noJs)
{{ $translator->trans('core.views.content.load_error_message') }}
@else
{{ $translator->trans('core.views.content.javascript_disabled_message') }}
@endif
</div>
</div>
@if ($allowJs)
<noscript>
<div class="Alert">
<div class="container">
{{ $translator->trans('core.views.content.javascript_disabled_message') }}
</div>
</div>
{!! $content !!}
@if (! $noJs) </noscript> @endif
{!! $content !!}
</noscript>
@else
<div class="Alert Alert--error">
<div class="container">
{{ $translator->trans('core.views.content.load_error_message') }}
</div>
</div>
{!! $content !!}
@endif

View File

@@ -1,6 +1,6 @@
<?php
/**
* Forum Client Template
* Forum WebApp Template
*
* NOTE: You shouldn't edit this file directly. Your changes will be overwritten
* when you update Flarum. See flarum.org/docs/templates to learn how to
@@ -31,8 +31,8 @@
<div id="header-navigation" class="Header-navigation"></div>
<div class="container">
<h1 class="Header-title">
<a href="{{ $forum->attributes->baseUrl }}" id="home-link">
{{ $forum->attributes->title }}
<a href="{{ array_get($forum, 'attributes.baseUrl') }}" id="home-link">
{{ array_get($forum, 'attributes.title') }}
</a>
</h1>
<div id="header-primary" class="Header-primary"></div>