cm-web-modules
Advanced tools
Comparing version 2.0.4 to 2.0.5
{ | ||
"name": "cm-web-modules", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Collection of clean and small ES6 modules for the web", | ||
@@ -5,0 +5,0 @@ "main": "src/LibraryManager.js", |
@@ -9,9 +9,16 @@ /** | ||
static debounce(func, timeout = 0) { | ||
let timer | ||
return (...args) => { | ||
clearTimeout(timer) | ||
timer = setTimeout(() => { | ||
func.apply(this, args) | ||
}, timeout) | ||
static debounce(callback, wait = 0, immediate = false) { | ||
let timeout | ||
return function executedFunction(...args) { | ||
if (immediate && !timeout) { | ||
callback(...args) | ||
timeout = true | ||
} else { | ||
const debounced = () => { | ||
clearTimeout(timeout) | ||
callback(...args) | ||
} | ||
clearTimeout(timeout) | ||
timeout = setTimeout(debounced, wait) | ||
} | ||
} | ||
@@ -18,0 +25,0 @@ } |
@@ -52,3 +52,3 @@ /** | ||
static isBrowserDarkMode() { | ||
return !!(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) | ||
return !!(window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) | ||
} | ||
@@ -58,8 +58,8 @@ | ||
return window.matchMedia && | ||
(window.matchMedia('(prefers-color-scheme: dark)').matches || | ||
window.matchMedia('(prefers-color-scheme: light)').matches) | ||
(window.matchMedia("(prefers-color-scheme: dark)").matches || | ||
window.matchMedia("(prefers-color-scheme: light)").matches) | ||
} | ||
static loadJs(src) { | ||
const element = document.createElement('script') | ||
const element = document.createElement("script") | ||
element.setAttribute("type", "text/javascript") | ||
@@ -83,7 +83,7 @@ element.setAttribute("src", src) | ||
static getCustomProperty(name, element = document.documentElement) { | ||
return getComputedStyle(element).getPropertyValue('--' + name).trim() | ||
return getComputedStyle(element).getPropertyValue("--" + name).trim() | ||
} | ||
static createElement(html) { | ||
const template = document.createElement('template') | ||
const template = document.createElement("template") | ||
template.innerHTML = html.trim() | ||
@@ -130,3 +130,3 @@ return template.content.firstChild | ||
if (links[i].hostname !== window.location.hostname && target !== "_self") { | ||
links[i].target = '_blank' | ||
links[i].target = "_blank" | ||
} | ||
@@ -133,0 +133,0 @@ } |
128379
2189