This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(func, ms) { | |
let timeout; | |
return () => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => { | |
func(); | |
}, ms); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const focusableEls = `a[href]:not(:disabled), input:not(:disabled):not([type="hidden"]), | |
select:not(:disabled), textarea:not(:disabled), button:not(:disabled), [contenteditable], | |
[tabindex]:not([tabindex="-1"])`; | |
const isTouchSupported = () => ('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch); | |
const getHtmlElement = (selector, ctx = document) => { | |
const node = typeof selector === 'string' ? ctx.querySelector(selector) : selector; | |
if (node instanceof HTMLElement) { | |
return node; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ua = window.navigator.userAgent.toLowerCase(); | |
const isIe = (/trident/gi).test(ua) || (/msie/gi).test(ua); | |
const goToTarget = function (target) { // фолбэк для ie11 | |
const y = target.offsetTop; | |
const moveTo = function () { | |
if (window.pageYOffset < y) { | |
window.scrollBy(0, 60); | |
setTimeout(moveTo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const COUNTRY_CODE = 7; | |
const onInputPhoneInput = ({target}) => { | |
const matrix = `+${COUNTRY_CODE} (___) ___-__-__`; | |
let counter = 0; | |
let val = target.value.replace(/\D/g, ''); | |
if (!val.length) { | |
val = `${COUNTRY_CODE}`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <div id="calendar"></div> | |
function createCalendar(elem, year, month) { | |
let mon = month - 1; // месяцы в JS идут от 0 до 11, а не от 1 до 12 | |
let d = new Date(year, mon); | |
let table = '<table><tr><th>пн</th><th>вт</th><th>ср</th><th>чт</th><th>пт</th><th>сб</th><th>вс</th></tr><tr>'; | |
// пробелы для первого ряда |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <progress id="elem" style="width: 5%;" onclick="anim.start()"></progress> | |
class Animation { | |
constructor({draw, duration}) { | |
this.draw = draw; | |
this.duration = duration; | |
} | |
animate(time) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for IE11 | |
const supportsTemplate = 'content' in document.createElement('template'); | |
// the function takes a template and returns a DOM element | |
const createElement = supportsTemplate | |
? function (html) { | |
const template = document.createElement('template'); | |
template.innerHTML = html; | |
return template.content.firstElementChild; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::after { | |
content: ''; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
border-top: none; | |
border-bottom: 15px solid red; | |
border-left: 7px solid transparent; | |
border-right: 7px solid transparent; |