Fix FAQ
This commit is contained in:
parent
8a96b526f1
commit
9bbb7712fe
3 changed files with 17 additions and 20 deletions
|
|
@ -15,13 +15,14 @@ function headerOffset() {
|
|||
return header.offsetHeight + (menuOpen ? 0 : FIXED_BUFFER);
|
||||
}
|
||||
|
||||
// On load: if the URL has a hash (e.g. /home#pt-services from another page),
|
||||
// re-scroll with the correct header offset instead of the browser's native jump.
|
||||
// On load: scroll to the anchor from either the URL hash or drupalSettings
|
||||
// (set by the server when rendering the home page at a clean URL like /services).
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
if (!window.location.hash) return;
|
||||
var target = document.querySelector(window.location.hash);
|
||||
var settings = window.drupalSettings && window.drupalSettings.riversidePt;
|
||||
var anchor = window.location.hash || (settings && settings.scrollTo);
|
||||
if (!anchor) return;
|
||||
var target = document.querySelector(anchor);
|
||||
if (!target) return;
|
||||
// Defer until layout is stable, then position correctly.
|
||||
requestAnimationFrame(function () {
|
||||
zenscroll.toY(Math.max(0, target.getBoundingClientRect().top + window.scrollY - headerOffset()), 0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -227,18 +227,6 @@ function _riverside_pt_build_navigation(): void {
|
|||
}
|
||||
}
|
||||
|
||||
foreach (['FAQ'] as $title) {
|
||||
if ($em->getStorage('node')->loadByProperties(['title' => $title, 'type' => 'page'])) {
|
||||
continue;
|
||||
}
|
||||
$node = Node::create(['type' => 'page', 'title' => $title, 'status' => 1]);
|
||||
$node->save();
|
||||
PathAlias::create([
|
||||
'path' => '/node/' . $node->id(),
|
||||
'alias' => '/' . strtolower($title),
|
||||
'langcode' => 'en',
|
||||
])->save();
|
||||
}
|
||||
|
||||
$defs = [
|
||||
['title' => 'Home', 'uri' => 'route:<front>', 'weight' => 0, 'class' => NULL],
|
||||
|
|
|
|||
|
|
@ -4,13 +4,21 @@ namespace Drupal\riverside_pt\Controller;
|
|||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class HomeController extends ControllerBase {
|
||||
|
||||
public function redirectToAnchor(Request $request): RedirectResponse {
|
||||
return new RedirectResponse($request->attributes->get('destination'), 301);
|
||||
// Renders the home page at a clean URL (e.g. /services, /book-appointment)
|
||||
// and injects the scroll target so the client scrolls to the right section
|
||||
// without a redirect — the URL stays exactly as requested.
|
||||
public function redirectToAnchor(Request $request): array {
|
||||
$build = $this->page();
|
||||
$destination = $request->attributes->get('destination', '');
|
||||
$hash = strstr($destination, '#');
|
||||
if ($hash !== FALSE) {
|
||||
$build['#attached']['drupalSettings']['riversidePt']['scrollTo'] = $hash;
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
||||
public function page(): array {
|
||||
|
|
|
|||
Loading…
Reference in a new issue