Skip to content

Commit 639dbac

Browse files
committed
Added support for auto-replacement of meta tags when using instant loading
1 parent 15538b0 commit 639dbac

File tree

16 files changed

+156
-91
lines changed

16 files changed

+156
-91
lines changed

material/overrides/assets/javascripts/custom.4eda089e.min.js renamed to material/overrides/assets/javascripts/custom.a4bbca43.min.js

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

material/overrides/assets/javascripts/custom.4eda089e.min.js.map renamed to material/overrides/assets/javascripts/custom.a4bbca43.min.js.map

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

material/overrides/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
{% endblock %}
2424
{% block scripts %}
2525
{{ super() }}
26-
<script src="{{ 'assets/javascripts/custom.4eda089e.min.js' | url }}"></script>
26+
<script src="{{ 'assets/javascripts/custom.a4bbca43.min.js' | url }}"></script>
2727
{% endblock %}

material/templates/assets/javascripts/bundle.5827baa9.min.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

material/templates/assets/javascripts/bundle.5827baa9.min.js.map

Lines changed: 0 additions & 8 deletions
This file was deleted.

material/templates/assets/javascripts/bundle.726fbb30.min.js

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

material/templates/assets/javascripts/bundle.726fbb30.min.js.map

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

material/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
</script>
251251
{% endblock %}
252252
{% block scripts %}
253-
<script src="{{ 'assets/javascripts/bundle.5827baa9.min.js' | url }}"></script>
253+
<script src="{{ 'assets/javascripts/bundle.726fbb30.min.js' | url }}"></script>
254254
{% for script in config.extra_javascript %}
255255
{{ script | script_tag }}
256256
{% endfor %}

src/templates/assets/javascripts/_/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type Flag =
3838
| "header.autohide" /* Hide header */
3939
| "navigation.expand" /* Automatic expansion */
4040
| "navigation.indexes" /* Section pages */
41-
| "navigation.instant" /* Instant loading */
41+
| "navigation.instant" /* Instant navigation */
4242
| "navigation.sections" /* Section navigation */
4343
| "navigation.tabs" /* Tabs navigation */
4444
| "navigation.tabs.sticky" /* Tabs navigation (sticky) */

src/templates/assets/javascripts/browser/location/_/index.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import { Subject } from "rxjs"
2424

25+
import { feature } from "~/_"
26+
import { h } from "~/utilities"
27+
2528
/* ----------------------------------------------------------------------------
2629
* Functions
2730
* ------------------------------------------------------------------------- */
@@ -43,10 +46,31 @@ export function getLocation(): URL {
4346
/**
4447
* Set location
4548
*
46-
* @param url - URL to change to
49+
* If instant navigation is enabled, this function creates a temporary anchor
50+
* element, sets the `href` attribute, appends it to the body, clicks it, and
51+
* then removes it again. The event will bubble up the DOM and trigger be
52+
* intercepted by the instant loading business logic.
53+
*
54+
* Note that we must append and remove the anchor element, or the event will
55+
* not bubble up the DOM, making it impossible to intercept it.
56+
*
57+
* @param url - URL to navigate to
58+
* @param navigate - Force navigation
4759
*/
48-
export function setLocation(url: URL | HTMLLinkElement): void {
49-
location.href = url.href
60+
export function setLocation(
61+
url: URL | HTMLLinkElement, navigate = false
62+
): void {
63+
if (feature("navigation.instant") && !navigate) {
64+
const el = h("a", { href: url.href })
65+
document.body.appendChild(el)
66+
el.click()
67+
el.remove()
68+
69+
// If we're not using instant navigation, and the page should not be reloaded
70+
// just instruct the browser to navigate to the given URL
71+
} else {
72+
location.href = url.href
73+
}
5074
}
5175

5276
/* ------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)