-
-
Save Shoora/826840ee856c0c7212c89ddc9ac3999d to your computer and use it in GitHub Desktop.
This file contains 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 scrollTo(element) { | |
window.scroll({ | |
behavior: 'smooth', | |
left: 0, | |
top: element.getBoundingClientRect().top + document.documentElement.scrollTop - document.querySelector('header').offsetHeight + 20 | |
}) | |
} | |
https://github.com/RobinHerbots/Inputmask | |
$().inputmask('+7 (999) 999-99-99', {'clearIncomplete': true}); | |
window.addEventListener('load', ()=>{ | |
let phone = document.querySelector('input[name="formParams[phone]"]') | |
let email = document.querySelector('input[name="formParams[email]"]') | |
Inputmask('+9 (999) 999-99-99', { | |
clearIncomplete: true, | |
greedy: false | |
}).mask(phone); | |
Inputmask({ | |
alias: 'email', | |
clearIncomplete: true, | |
greedy: false | |
}).mask(email); | |
}) | |
//vanillajs coockie (in seconds) | |
document.cookie = `popupWheelShowned=true; max-age=${24 * 60 * 60}; path=/` | |
function getCookie (name) { | |
let value = `; ${document.cookie}`; | |
let parts = value.split(`; ${name}=`); | |
if (parts.length === 2) return parts.pop().split(';').shift(); | |
} | |
// check element in viewport | |
var isInViewport = function (elem) { | |
var bounding = elem.getBoundingClientRect() | |
return ( | |
bounding.top >= 0 && | |
bounding.left >= 0 && | |
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | |
bounding.right <= (window.innerWidth || document.documentElement.clientWidth) | |
) | |
} | |
// вставка яндекс-метрики, которая не портит показатели | |
( function () { | |
var loadedTLAnalytics = false, | |
timerId; | |
if ( navigator.userAgent.indexOf( 'YandexMetrika' ) > -1 ) { | |
loadTLAnalytics(); | |
} else { | |
window.addEventListener( 'scroll', loadTLAnalytics, {passive: true} ); | |
window.addEventListener( 'touchstart', loadTLAnalytics, {passive: true} ); | |
document.addEventListener( 'mouseenter', loadTLAnalytics, {passive: true} ); | |
document.addEventListener( 'click', loadTLAnalytics, {passive: true} ); | |
document.addEventListener( 'DOMContentLoaded', loadFallback, {passive: true} ); | |
} | |
function loadFallback() { | |
timerId = setTimeout( loadTLAnalytics, 5000 ); | |
} | |
function loadTLAnalytics( e ) { | |
if ( e && e.type ) { | |
console.log( e.type ); | |
} else { | |
console.log( 'DOMContentLoaded' ); | |
} | |
if ( loadedTLAnalytics ) { | |
return; | |
} | |
setTimeout( | |
function () { | |
var metricaId = 79578238;(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; | |
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) | |
(window, document, "script", "https://cdn.jsdelivr.net/npm/yandex-metrica-watch/tag.js", "ym"); | |
ym( metricaId, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true,triggerEvent:true }); | |
console.log("ym start"); | |
}, 100); | |
loadedTLAnalytics = true; | |
clearTimeout( timerId ); | |
window.removeEventListener( 'scroll', loadTLAnalytics, {passive: true} ); | |
window.removeEventListener( 'touchstart', loadTLAnalytics, {passive: true} ); | |
document.removeEventListener( 'mouseenter', loadTLAnalytics ); | |
document.removeEventListener( 'click', loadTLAnalytics ); | |
document.removeEventListener( 'DOMContentLoaded', loadFallback ); | |
} | |
} | |
)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment