const $menuItems = $('#menu a');
$('#submenu > ul').width(i => $menuItems.eq(i).width());
const min = 7;
const max = min + 21;
function update(value) {
value = Math.max(min, Math.min(max, value | 0));
$('#spinner2').val(value);
$('#slider2').slider('value', value);
const date = new Date();
date.setDate(date.getDate() + value);
$('#amount').val(date.toLocaleString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}));
}
$('#slider2').slider({
range: 'min',
min,
max,
step: 1,
slide: (e, ui) => update(ui.value),
});
$('#spinner2').spinner({
min,
max,
spin: (e, ui) => update(ui.value),
}).on('input', e => update(e.target.value)).trigger('input');
Мои текущие знания и умения:
const sort = {
number: (a, b) => a - b,
string: (a, b) => a.localeCompare(b),
};
function sortTable(table, colIndex) {
if (typeof table === 'string') {
table = document.querySelector(table);
}
const head = table.tHead.rows[0];
const compare = sort[head.cells[colIndex].dataset.type] ?? sort.string;
const value = row => row.cells[colIndex].innerText;
const tbody = table.tBodies[0];
tbody.append(...[...tbody.rows].sort((a, b) => compare(value(a), value(b))));
[...head.cells].forEach((n, i) => n.classList.toggle('sorted', i == colIndex));
}
.sorted {
background: #ccc;
}
.sorted::after {
content: " \2193";
}
// просто дёргаем сортировку
sortTable('#grid', 0);
sortTable(document.querySelector('table'), 1);
// или, сортируем по клику на заголовки столбцов
document.querySelectorAll('#grid th').forEach(function(n) {
n.addEventListener('click', this);
}, ({ target: t }) => sortTable(t.closest('table'), t.cellIndex));
А можно как-то присваивать свой класс?
computed: {
activeLink() {
return this.links.find(n => n.url === this.$route.path);
},
},
:class="{ active: activeLink === link }"
created() {
const interval = setInterval(this.method, 5 * 60 * 1000);
this.$on('hook:beforeDestroy', () => clearInterval(interval));
},
return new this.constructor();
This expression is not constructable. Type 'Function' has no construct signatures
const { constructor } = Object.getPrototypeOf(this);
return new constructor();
<div class="phone">8 (123) 111-22-33</div>
<div class="phone">8 (456) 444-55-66</div>
<div class="phone">8 (789) 777-88-99</div>
document.querySelectorAll('.phone').forEach(n => {
const phone = n.innerHTML;
n.innerHTML = phone.slice(0, -4) + '... - <span>показать</span>';
n.querySelector('span').addEventListener('click', () => n.innerHTML = phone);
});
function filter(val) {
if (!(val instanceof Object)) {
return val;
}
const filtered = Object
.entries(val)
.map(n => [ n[0], filter(n[1]) ])
.filter(n => n[1]);
return filtered.length
? val instanceof Array
? filtered.map(n => n[1])
: Object.fromEntries(filtered)
: null;
}
const validator = (value, maxSize) =>
!(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize);
if (validator(value, maxSize)) {
setTitle(value);
}
const validator = (defaultValue, value, maxSize) =>
(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize)
? defaultValue
: value;
setTitle(prevValue => validator(prevValue, value, maxSize));
methods: {
createAlphaIndex(num) {
const base = 26;
let str = '';
do {
const mod = num % base;
num = num / base | 0;
str = (mod ? String.fromCharCode('A'.charCodeAt(0) + mod - 1) : (--num, 'Z')) + str;
} while(num);
return str;
},
},
<div v-for="i in 1000">{{ createAlphaIndex(i) }}</div>
const elements = document.querySelectorAll('.price');
const output = document.querySelector('.min-sum');
output.textContent = Math.min(...Array.from(
elements,
n => parseFloat(n.textContent)
));
// или
output.innerText = Array.prototype.reduce.call(
elements,
(min, n) => (
n = +n.innerText.match(/[\d.]+/),
n < min ? n : min
),
Infinity
);
const elem = document.querySelector('#elem').nextElementSibling;
if (elem) {
const num = 1 + [...elem.parentNode.children].indexOf(elem);
elem.innerText = num + '. ' + elem.innerText;
}
const elem = document.querySelector('#elem + *');
if (elem) {
let num = 1;
for (let n = elem; n = n.previousElementSibling; num++) ;
elem.textContent = `${num}. ${elem.textContent}`;
}
const elems = document.querySelector('ul').children;
const index = -~Array.prototype.findIndex.call(elems, n => n.id === 'elem');
if (index) {
elems[index]?.insertAdjacentText('afterbegin', ''.concat(-~index, '. '));
}