mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-24 06:43:50 -04:00
Added polyfills for unfetch, URL, Object.entries and Element.scrollTo
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import "focus-visible"
|
||||
import {
|
||||
EMPTY,
|
||||
NEVER,
|
||||
@@ -78,6 +77,7 @@ import {
|
||||
patchScrollfix,
|
||||
patchScrolllock
|
||||
} from "./patches"
|
||||
import "./polyfills"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Application
|
||||
|
||||
@@ -117,8 +117,7 @@ export function mountPalette(
|
||||
|
||||
/* Set color palette */
|
||||
for (const [key, value] of Object.entries(palette.color))
|
||||
if (typeof value === "string")
|
||||
document.body.setAttribute(`data-md-color-${key}`, value)
|
||||
document.body.setAttribute(`data-md-color-${key}`, value)
|
||||
|
||||
/* Toggle visibility */
|
||||
for (let index = 0; index < inputs.length; index++) {
|
||||
|
||||
55
src/assets/javascripts/polyfills/index.ts
Normal file
55
src/assets/javascripts/polyfills/index.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import "focus-visible"
|
||||
import "unfetch/polyfill"
|
||||
import "url-polyfill"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Custom polyfills
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Polyfill for `Object.entries` */
|
||||
if (!Object.entries)
|
||||
Object.entries = function (obj: object) {
|
||||
const data: [string, string][] = []
|
||||
for (const key of Object.keys(obj))
|
||||
// @ts-expect-error - ignore property access warning
|
||||
data.push([key, obj[key]])
|
||||
|
||||
/* Return entries */
|
||||
return data
|
||||
}
|
||||
|
||||
/* Polyfill for `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!
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user