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 getLocalStorageSize = function() { | |
var total = 0; | |
for (var x in localStorage) { | |
// Value is multiplied by 2 due to data being stored in `utf-16` format, which requires twice the space. | |
var amount = (localStorage[x].length * 2) / 1024 / 1024; | |
if (!isNaN(amount) && localStorage.hasOwnProperty(x)) { | |
total += amount; | |
} | |
} | |
return total.toFixed(2); |
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
// media query event handler | |
if (matchMedia) { | |
const mq = window.matchMedia("(min-width: 500px)"); | |
mq.addListener(WidthChange); | |
WidthChange(mq); | |
} | |
// media query change | |
function WidthChange(mq) { | |
if (mq.matches) { |
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 declOfNum(number, titles) { | |
cases = [2, 0, 1, 1, 1, 2]; | |
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
} | |
use: | |
declOfNum(count, ['найдена', 'найдено', 'найдены']); |
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 getSelectedText(){ | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection(); | |
}else if (document.getSelection) { | |
text = document.getSelection(); | |
}else if (document.selection) { | |
text = document.selection.createRange().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
const container = document.querySelector('.scroll-container'); | |
container.addEventListener('wheel', horizontalWheelScroll); | |
function horizontalWheelScroll (event) { | |
let modifier; | |
if (event.deltaMode === event.DOM_DELTA_PIXEL) { | |
modifier = 1; | |
// иные режимы возможны в Firefox | |
} else if (event.deltaMode === event.DOM_DELTA_LINE) { | |
modifier = parseInt(getComputedStyle(this).lineHeight); |
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 formatDigits(str) { | |
return str.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 '); | |
} |
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 sliceText(textNodes, symbols) { | |
textNodes.forEach(cur => { | |
const text = cur.innerText; | |
let sliced = text.slice(0,symbols); | |
if (sliced.length < text.length) { | |
sliced += '...'; | |
cur.innerText = sliced; | |
} | |
}); |
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 randomNumber(min, max) { | |
return min + Math.floor(Math.random() * (max + 1 - min)); | |
} |
NewerOlder