function createAudioElement(blob) {
var aud = document.getElementById("sound")
aud.controls = true
aud.src = blob
aud.type = 'audio/webm'
}
var recorder
var publicBlobObj
function start(callback) {
navigator
.mediaDevices
.getUserMedia({ audio: true })
.then(stream => {
const chunks = []
recorder = new MediaRecorder(stream)
recorder.ondataavailable = e => {
chunks.push(e.data)
if (recorder.state == 'inactive') {
publicBlobObj = new Blob(chunks, { type: 'audio/webm' })
createAudioElement(URL.createObjectURL(publicBlobObj))
if (callback) callback()
}
}
recorder.start()
})
.catch(console.error)
}
function stop() {
recorder.stop()
var xhr = new XMLHttpRequest()
var data = new FormData
data.append("sound", publicBlobObj)
xhr.open('POST', '/User/Sound', true)
xhr.send(data)
}
start(() => {
// вот тут уже и recorder и publicBlobObj имеют значение
})
var arr = [
{ price: 10, amount: 10 },
{ price: 12, amount: 12 },
{ price: 9, amount: 7 },
{ price: 17, amount: 8 },
{ price: 4, amount: 2 }
]
arr
.sort(function(a, b) {
return a.price - b.price
})
.reverse()
.map(function(item, i) {
item.index = i + 1
})
console.log(arr)
/*
[
{ price: 17, amount: 8, index: 1 },
{ price: 12, amount: 12, index: 2 },
{ price: 10, amount: 10, index: 3 },
{ price: 9, amount: 7, index: 4 },
{ price: 4, amount: 2, index: 5 }
]
*/
var data = {
a: {
b: {
c: {
d: {
e: "Hello World!"
}
}
}
}
}
function from(target, path) {
return path.split(".").reduce(function(data, key) {
return data && data[key]
}, target)
}
console.log(from(data, "a.b.c.d.e")) // "Hello World!"
console.log(from(data, "a.a.a.a.a")) // undefined
<?php
function my_modules() {
return '
<div class="evaluated-projects">
<div class="container">
<div class="section-simple-title-wrap wow fadeInUp text-center " data-wow-delay="0.4s " style="visibility: hidden; animation-delay: 0.4s; animation-name: none; ">
<h3 class="simple-title no-link ">Оцененные проекты</h3>
</div>
<div class="evaluated-projects__content oneperframe frame wow fadeIn" data-wow-delay="0.4s " style="visibility: hidden; animation-delay: 0.4s; animation-name: none; " id="oneperframe">
<ul class="frame-list">
' . the_excerpt() . '
<li class="frame-list__item">
<div class="evaluated-projects__item">
<div class="evaluated-projects__img">
<img src="potolki_new_files/img/sly-slide-1.jpg" alt="image">
</div>
<div class="evaluated-projects__description">
<div class="evaluated-projects__title"> ' . the_title() . ' </div>
<ul class="evaluated-projects__list">
<li>Полотно <span>3 600 ₽</span></li>
<li>Светильники с лампой под ключ <span>6 240 ₽</span></li>
<li>Углы <span>600 ₽</span></li>
<li>Установка люстры <span>1 000 ₽</span></li>
<li>Обвод трубы <span>300 ₽</span></li>
<li>Итого <span>12 040 ₽</span></li>
</ul>
<div class="buttons-block">
<a href="' . the_permalink() . '" class="btn button-orange">Подробнее</a>
<span class="button-review"><span>Прочитать отзыв</span></span>
</div>
</div>
<div class="review__item">
<div class="review__content">
<p>
' . get_post_meta(get_the_ID(), "reviews", true) . '
</p>
</div>
<div class="review__author">
<div class="review__author-img">
<img src="potolki_new_files/img/men.png" alt="people" />
</div>
<div class="review__author-name">Александр Петровский</div>
<div class="review__author-post">Генеральный директор компании Роснефть</div>
<div class="buttons-block">
<a href="" class="btn button-orange">Подробнее</a>
<span class="button-watch-project"><span>Смотреть проект</span></span>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
<div class="scrollbar">
<div class="handle">
<div class="mousearea"></div>
</div>
</div>
</div>
</div>
';
}
add_shortcode('reviews', 'my_modules');
const walk = data => {
if (!data) return;
for (let i = 0; i < data.length; i++) {
for (let l = 0; l < data.length; l++) {
if (data[l].left > data[i].left && data[l].right < data[i].right) {
data[i].children = data[i].children || []
data[i].children.push(data.splice(l, 1)[0])
l--
}
}
walk(data[i].children)
}
return data
}
const list = tree => {
let ul = document.createElement("ul")
for (let i = 0; i < tree.length; i++) {
let li = document.createElement("li")
li.textContent = tree[i].title
ul.appendChild(li)
if (tree[i].children) li.appendChild(list(tree[i].children))
}
return ul
}
let tree = walk(data)
console.log(tree)
let listNode = list(tree)
console.log(listNode)
{
foo: function() { console.log("такого метода нет") },
bar: function() { console.log("такого метода нет") },
baz: function() { console.log("такого метода нет") }
}
var obj = {
callMethod: function(name) {
if (typeof obj[name] === "function") {
obj[name].apply(null, [].slice.call(arguments, 1))
} else {
console.log("такого метода нет")
}
}
}