Skip to content

Commit 7a1bd52

Browse files
committed
Fixed problem when usage navigation by modals
1 parent c5616b4 commit 7a1bd52

File tree

5 files changed

+60
-9
lines changed

5 files changed

+60
-9
lines changed

public/build/assets/app-B-hWsIbj.js renamed to public/build/assets/app-wv8uX38s.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"isEntry": true
1818
},
1919
"resources/js/app.js": {
20-
"file": "assets/app-B-hWsIbj.js",
20+
"file": "assets/app-wv8uX38s.js",
2121
"src": "resources/js/app.js",
2222
"isEntry": true,
2323
"css": [

resources/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ application.register('textarea-autogrow', TextareaAutogrow);
1515

1616
import './initializers/service-worker';
1717
import './initializers/yandex-metrika.js';
18+
import './initializers/modals.js';

resources/js/initializers/modals.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Modal } from 'bootstrap';
2+
3+
document.addEventListener('turbo:load', () => {
4+
document.querySelectorAll('.modal').forEach((modal) => {
5+
/**
6+
* Autofocus on modal.
7+
*/
8+
modal.addEventListener('shown.bs.modal', () => {
9+
if (modal.querySelector('[autofocus]') !== null) {
10+
modal.querySelector('[autofocus]').focus();
11+
}
12+
});
13+
14+
modal.addEventListener('hidden.bs.modal', () => {
15+
setTimeout(() => {
16+
document.activeElement?.blur();
17+
});
18+
});
19+
});
20+
});
21+
22+
document.addEventListener('turbo:before-cache', () => {
23+
// Check if the body has the 'modal-open' class
24+
if (document.body.classList.contains('modal-open')) {
25+
if (window.location.href.indexOf('begin') > -1) {
26+
return;
27+
}
28+
29+
// Find the currently visible modal
30+
const element = document.querySelector('.modal.show');
31+
32+
// Get or create the modal instance
33+
const modal = Modal.getOrCreateInstance(element);
34+
35+
// Remove the 'fade' class from the modal element
36+
element.classList.remove('fade');
37+
38+
// Disable animation for the modal backdrop
39+
modal._backdrop._config.isAnimated = false;
40+
41+
// Hide the modal
42+
modal.hide();
43+
44+
// Dispose the modal instance https://getbootstrap.com/docs/5.3/getting-started/javascript/#dispose-method
45+
// IT hack!
46+
modal.dispose();
47+
element.classList.add('fade');
48+
}
49+
});

resources/views/docs/docs.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline
125125
data-action="input->search-docs#search"
126126
name="text"
127127
autocomplete="false"
128+
autofocus
128129
data-search-docs-target="text"
129130
type="search"
130131
placeholder="Введите термин или фразу ..."

0 commit comments

Comments
 (0)