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 throttle(fn, delay) { | |
| let last; | |
| let timer; | |
| return () => { | |
| const now = +new Date; | |
| if (last && now < last + delay) { | |
| clearTimeout(timer); |
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
| .class { | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| } |
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
| let selected = [ | |
| { price: 20 }, | |
| { price: 45 }, | |
| { price: 67 }, | |
| { price: 1305 } | |
| ]; | |
| let reducers = { | |
| rubles : (state, item) => { return state.rubles += item.price }, | |
| dollars: (state, item) => { return state.dollars += item.price / 71.6024 }, |
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
| .form-control { | |
| &::placeholder { | |
| color: #ccc; | |
| opacity: 1; | |
| text-overflow: ellipsis !important; | |
| transition: opacity .3s ease-in-out; | |
| } | |
| &:focus::-webkit-input-placeholder {opacity: 0;} |
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 createElement(tag, props, ...children) { | |
| const element = document.createElement(tag); | |
| Object.keys(props).forEach(key => { | |
| if (key.startsWith('data-')) { | |
| element.setAttribute(key, props[key]); | |
| } else { | |
| element[key] = props[key]; | |
| } | |
| }); |
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
| var rus = "щ ш ч ц ю я ё ж ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g), | |
| eng = "shh sh ch cz yu ya yo zh `` y' e` a b v g d e z i j k l m n o p r s t u f x `".split(/ +/g); | |
| function translit(text) { | |
| var text = text.toLowerCase(); | |
| for(x = 0; x < rus.length; x++) { | |
| text = text.split(rus[x]).join(eng[x]); | |
| } | |
| return text; | |
| } |
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
| var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase(), | |
| otherCharacters = '-=~\"\'#$%&*^:<>?/!{(|)}.1234567890\, '; | |
| var shiftedAlphabet = alphabet.slice(3); | |
| shiftedAlphabet += alphabet.slice(0, 3); | |
| shiftedAlphabet += otherCharacters; | |
| alphabet += otherCharacters; | |
| var str = 'I am amazing'.toLowerCase(), | |
| out = ''; |
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
| $(document).ready(function(){ | |
| $("#menu").on("click","a", function (event) { | |
| //отменяем стандартную обработку нажатия по ссылке | |
| event.preventDefault(); | |
| //забираем идентификатор бока с атрибута href | |
| var id = $(this).attr('href'), | |
| //узнаем высоту от начала страницы до блока на который ссылается якорь | |
| top = $(id).offset().top; |
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
| input.addEventListener('input', function() { | |
| var _arrValue = []; | |
| var _value = this.value.replace(/\D/gi, ''); | |
| if(_value.length > 16) { | |
| _value = _value.substr(0,16) | |
| } | |
| for(let i = 0; i < _value.length; i+=4) { | |
| _arrValue.push(_value.substr(i, 4)); |
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
| let a = 'xxx-xxx-xxx xx'.replace(/x/g, (n=>s=>x=>s[n++])(0)('92795008123'.replace(/\D/g,''))); | |
| console.log(a); // 927-950-081 23 | |
| // видно, что (0)('92795008123'.replace(/\D/g,'') - это вызов функции типа нашей add(1)(2) | |
| // '92795008123'.replace(/\D/g,'' - тут просто замена не цифр (\D) на '', то есть оставление только цифр | |
| // вообще говоря имеет смысл только когда '92795008123' приходит из внешнего кода | |
| // перепишем (n=>s=>x=>s[n++]) на стандартные function: | |
| function repl(n) { // 1) n = 0 - индекс в строке s | |
| return function (s) { // 2) s = '92795008123' - форматируемая строка |