_embedded.items.forEach(function(item) {
item.custom_fields.forEach(function(field) {
console.log(field);
});
});
var random = new Random(5632732);
console.log(random.number(0, 10)) //> 3.280606995884774
console.log(random.number(0, 10)) //> 3.679312414266118
console.log(random.boolean(50)) //> true
console.log(random.boolean(50)) //> true
function Random(seed) {
this.seed = seed;
}
Random.prototype.number = function(min, max) {
this.seed++;
return min + (((this.seed * 9301 + 49297) % 233280) / 233280) * (max - min);
};
Random.prototype.boolean = function(rate) {
this.seed++;
return Math.sin(this.seed) <= rate / 100;
};
var request = new XMLHttpRequest();
request.open('GET', 'https://jsonplaceholder.typicode.com/users', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
console.log(data);
} else {
// error
}
};
request.send();
$('.menu-open').on('click', debounce(function(event) {
console.log(this);
}, 500));
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
}
}
$('.timer').timer({
date: '12/25/2018',
language: 'RU',
template: function(time) {
return `
<span>
Осталось
${time.hours.value} ${time.hours.text},
${time.minutes.value} ${time.minutes.text} и
<span v-if="${time.seconds.value > 5}">
${time.seconds.value} ${time.seconds.text}
</span>
<span v-else style="color:red;">
${time.seconds.value} ${time.seconds.text}
</span>
</span>
`;
}
});
$('button').on('click', function() {
$(this).prop('disabled', true);
setTimeout(function() {
$(this).prop('disabled', false);
}.bind(this), 1e3);
});
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
$('button').on('click', debounce(function() {
console.log(this);
}, 500));