mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-24 06:43:50 -04:00
Merge branch 'master' into refactor/compatibility
This commit is contained in:
@@ -34,7 +34,8 @@ import {
|
||||
|
||||
import {
|
||||
getElement,
|
||||
getElements
|
||||
getElements,
|
||||
getOptionalElement
|
||||
} from "~/browser"
|
||||
import { renderAnnotation } from "~/templates"
|
||||
|
||||
@@ -118,8 +119,10 @@ export function mountAnnotationList(
|
||||
const annotations = new Map<number, HTMLElement>()
|
||||
for (const marker of findAnnotationMarkers(container)) {
|
||||
const [, id] = marker.textContent!.match(/\((\d+)\)/)!
|
||||
annotations.set(+id, renderAnnotation(+id))
|
||||
marker.replaceWith(annotations.get(+id)!)
|
||||
if (getOptionalElement(`li:nth-child(${id})`, el)) {
|
||||
annotations.set(+id, renderAnnotation(+id))
|
||||
marker.replaceWith(annotations.get(+id)!)
|
||||
}
|
||||
}
|
||||
|
||||
/* Keep list if there are no annotations to render */
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Polyfills
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Polyfill for `Object.entries` */
|
||||
/* Polyfill `Object.entries` */
|
||||
if (!Object.entries)
|
||||
Object.entries = function (obj: object) {
|
||||
const data: [string, string][] = []
|
||||
@@ -36,7 +36,7 @@ if (!Object.entries)
|
||||
return data
|
||||
}
|
||||
|
||||
/* Polyfill for `Object.values` */
|
||||
/* Polyfill `Object.values` */
|
||||
if (!Object.values)
|
||||
Object.values = function (obj: object) {
|
||||
const data: string[] = []
|
||||
@@ -48,16 +48,49 @@ if (!Object.values)
|
||||
return data
|
||||
}
|
||||
|
||||
/* Polyfill for `Element.scrollTo` */
|
||||
if (typeof Element !== "undefined" && !Element.prototype.scrollTo)
|
||||
Element.prototype.scrollTo = function (
|
||||
x?: ScrollToOptions | number, y?: number
|
||||
): void {
|
||||
if (typeof x === "object") {
|
||||
this.scrollLeft = x.left!
|
||||
this.scrollTop = x.top!
|
||||
} else {
|
||||
this.scrollLeft = x!
|
||||
this.scrollTop = y!
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Polyfills for `Element` */
|
||||
if (typeof Element !== "undefined") {
|
||||
|
||||
/* Polyfill `Element.scrollTo` */
|
||||
if (!Element.prototype.scrollTo)
|
||||
Element.prototype.scrollTo = function (
|
||||
x?: ScrollToOptions | number, y?: number
|
||||
): void {
|
||||
if (typeof x === "object") {
|
||||
this.scrollLeft = x.left!
|
||||
this.scrollTop = x.top!
|
||||
} else {
|
||||
this.scrollLeft = x!
|
||||
this.scrollTop = y!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Polyfill `Element.replaceWith` */
|
||||
if (!Element.prototype.replaceWith)
|
||||
Element.prototype.replaceWith = function (
|
||||
...nodes: Array<string | Node>
|
||||
): void {
|
||||
const parent = this.parentNode
|
||||
if (parent) {
|
||||
if (nodes.length === 0)
|
||||
parent.removeChild(this)
|
||||
|
||||
/* Replace children and create text nodes */
|
||||
for (let i = nodes.length - 1; i >= 0; i--) {
|
||||
let node = nodes[i]
|
||||
if (typeof node !== "object")
|
||||
node = document.createTextNode(node)
|
||||
else if (node.parentNode)
|
||||
node.parentNode.removeChild(node)
|
||||
|
||||
/* Replace child or insert before previous sibling */
|
||||
if (!i)
|
||||
parent.replaceChild(node, this)
|
||||
else
|
||||
parent.insertBefore(this.previousSibling!, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user