Skip to content

Instantly share code, notes, and snippets.

import { useState, useEffect } from 'react';
const useWindowSize = () => {
// IMPLEMENT
const [size, setSize] = useState({width: window.innerWidth, height: window.innerHeight});
useEffect(() => {
const eventResize = () => {
setSize({width: window.innerWidth, height: window.innerHeight});
}
window.addEventListener('resize', eventResize);
@0632347878
0632347878 / README.md
Created December 23, 2020 15:11 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
/**
* For accept the lazy loading to images you need just add
* [data-lazy-src] with a path on image.
*/
export default (window.onload = () => {
const images = document.querySelectorAll('[data-lazy-src]');
if ('IntersectionObserver' in window) {
let observer = new IntersectionObserver(
@0632347878
0632347878 / gist:e96525c56afa72735aa33692e6d55d1e
Created February 5, 2020 16:24
Scroll to loacation hash
RIGHT
if (window.location.hash) {
$('html, body').animate({
scrollTop: $(window.location.hash).offset().top - 50
}, 500);
}
WRONG
// let url = location.href;
@0632347878
0632347878 / gist:b2f967ab2b5ab1f13e2b8356bf83ea36
Created February 5, 2020 09:19
Polyfill for IE11 missing NodeList.forEach
if ('NodeList' in window && !NodeList.prototype.forEach) {
console.info('polyfill for IE11');
NodeList.prototype.forEach = function (callback, thisArg) {
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
window.location.href.split('/')[window.location.href.split('/').length - 1] !== ""
$('.sme-form__form').validate({
rules: {
phone: {
required: true,
regex : /\+38\(0(50|63|66|67|68|73|91|92|93|94|95|96|97|98|99)\)-\d{3}(-\d{2})(-\d{2})/
},
});
$.validator.addMethod(
"regex",
case 1
// console.log(value.slice(5, 7));
// if(value.slice(5, 7).includes('67'||'96'||'97'||'68'||'98'||'39'||'50'||'99'||'66'||'95'||'63'||'93'||'73')) {
// console.log('yyyyyyyyyyyyyyyyes');
// }
/_ ES6 _/
const isMomHappy = true;
// Промис
const willIGetNewPhone = new Promise(
(resolve, reject) => { // fat arrow
if (isMomHappy) {
const phone = {
brand: 'Samsung',
color: 'black'
/* ES5, using Bluebird */
var isMomHappy = false;
// Promise
var willIGetNewPhone = new Promise(
function (resolve, reject) {
if (isMomHappy) {
var phone = {
brand: 'Samsung',
color: 'black'