Delete inline js for back button

https://github.com/forkbb/forkbb/issues/2
This commit is contained in:
Visman 2021-01-10 01:05:12 +07:00
parent 4aa2bc5971
commit d1572dd82e
5 changed files with 41 additions and 5 deletions

View file

@ -86,6 +86,10 @@ abstract class Page extends Model
*/
public function prepare(): void
{
$this->pageHeader('commonJS', 'script', [
'src' => $this->publicLink('/js/common.js'),
]);
$this->boardNavigation();
$this->iswevMessages();
}

View file

@ -161,8 +161,8 @@ class Email extends Page
'back' => [
'type' => 'btn',
'value' => __('Go back'),
'link' => $data['redirect'], // 'javascript:history.go(-1)',
'class' => 'f-opacity',
'link' => $data['redirect'],
'class' => 'f-opacity f-go-back',
],
],
];

View file

@ -149,8 +149,8 @@ class Report extends Page
'back' => [
'type' => 'btn',
'value' => __('Go back'),
'link' => 'javascript:history.go(-1)',
'class' => 'f-opacity',
'link' => $this->c->Router->link('ViewPost', ['id' => (int) $args['id']]),
'class' => 'f-opacity f-go-back',
],
],
];

View file

@ -1,6 +1,6 @@
@extends ('layouts/main')
@if ($p->back)
<div class="f-backlink">
<p><a href="{{ $p->fRootLink }}" onclick="window.history.back(); return false;">{!! __('Go back') !!}</a></p>
<p><a class="f-go-back" href="{{ $p->fRootLink }}">{!! __('Go back') !!}</a></p>
</div>
@endif

32
public/js/common.js Normal file
View file

@ -0,0 +1,32 @@
if (typeof ForkBB === "undefined" || !ForkBB) {
var ForkBB = {};
}
ForkBB.common = (function (doc, win) {
'use strict';
var selectorBack = ".f-go-back";
function initGoBack()
{
var backs = doc.querySelectorAll(selectorBack);
for (var i = 0; i < backs.length; i++) {
backs[i].addEventListener("click", function (event) {
win.history.back();
event.preventDefault();
return false;
});
}
}
return {
init : function () {
initGoBack();
},
};
}(document, window));
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", ForkBB.common.init, false);
}