Add audios picker & move track in smal player вниз

This commit is contained in:
lalka2018 2023-10-18 16:19:58 +03:00
parent c8e7da9c6d
commit ac165c528a
17 changed files with 324 additions and 74 deletions

View file

@ -59,6 +59,8 @@ final class Wall extends VKAPIRequestHandler
$attachments[] = $attachment->getApiStructure();
} else if ($attachment instanceof \openvk\Web\Models\Entities\Note) {
$attachments[] = $attachment->toVkApiStruct();
} else if ($attachment instanceof \openvk\Web\Models\Entities\Audio) {
$attachments[] = $attachment->toVkApiStruct($this->getUser());
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
$repostAttachments = [];
@ -234,6 +236,8 @@ final class Wall extends VKAPIRequestHandler
$attachments[] = $attachment->getApiStructure();
} else if ($attachment instanceof \openvk\Web\Models\Entities\Note) {
$attachments[] = $attachment->toVkApiStruct();
} else if ($attachment instanceof \openvk\Web\Models\Entities\Audio) {
$attachments[] = $attachment->toVkApiStruct($this->getUser());
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
$repostAttachments = [];
@ -571,6 +575,8 @@ final class Wall extends VKAPIRequestHandler
$attachments[] = $this->getApiPhoto($attachment);
} elseif($attachment instanceof \openvk\Web\Models\Entities\Note) {
$attachments[] = $attachment->toVkApiStruct();
} elseif($attachment instanceof \openvk\Web\Models\Entities\Audio) {
$attachments[] = $attachment->toVkApiStruct($this->getUser());
}
}
@ -637,6 +643,8 @@ final class Wall extends VKAPIRequestHandler
foreach($comment->getChildren() as $attachment) {
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
$attachments[] = $this->getApiPhoto($attachment);
} elseif($attachment instanceof \openvk\Web\Models\Entities\Audio) {
$attachments[] = $attachment->toVkApiStruct($this->getUser());
}
}
@ -728,6 +736,8 @@ final class Wall extends VKAPIRequestHandler
$attachmentType = "photo";
elseif(str_contains($attac, "video"))
$attachmentType = "video";
elseif(str_contains($attac, "audio"))
$attachmentType = "audio";
else
$this->fail(205, "Unknown attachment type");
@ -753,6 +763,12 @@ final class Wall extends VKAPIRequestHandler
if(!$attacc->getOwner()->getPrivacyPermission('videos.read', $this->getUser()))
$this->fail(11, "Access to video denied");
$comment->attach($attacc);
} elseif($attachmentType == "audio") {
$attacc = (new AudiosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
if(!$attacc || $attacc->isDeleted())
$this->fail(100, "Audio does not exist");
$comment->attach($attacc);
}
}

View file

@ -30,10 +30,10 @@ class Playlist extends MediaCollection
$this->importTable = DatabaseConnection::i()->getContext()->table("playlist_imports");
}
function getCoverURL(): ?string
function getCoverURL(string $size = "normal"): ?string
{
$photo = (new Photos)->get((int) $this->getRecord()->cover_photo_id);
return is_null($photo) ? "/assets/packages/static/openvk/img/song.jpg" : $photo->getURL();
return is_null($photo) ? "/assets/packages/static/openvk/img/song.jpg" : $photo->getURLBySizeId($size);
}
function getLength(): int

View file

@ -285,46 +285,23 @@ final class AudioPresenter extends OpenVKPresenter
$this->redirect("/playlist" . $owner . "_" . $playlist->getId());
} else {
$this->template->audios = iterator_to_array($this->audios->getByUser($this->user->identity));
$this->template->audios = iterator_to_array($this->audios->getByUser($this->user->identity, 1, 10));
}
}
function renderPlaylist(int $owner_id, int $virtual_id): void
{
$playlist = $this->audios->getPlaylistByOwnerAndVID($owner_id, $virtual_id);
$page = (int)($this->queryParam("p") ?? 1);
if (!$playlist || $playlist->isDeleted())
$this->notFound();
$this->template->playlist = $playlist;
$this->template->page = (int)($this->queryParam("p") ?? 0);
$this->template->audios = iterator_to_array($playlist->getAudios());
$this->template->page = $page;
$this->template->audios = iterator_to_array($playlist->fetch($page, 10));
$this->template->isBookmarked = $playlist->isBookmarkedBy($this->user->identity);
$this->template->isMy = $playlist->getOwner()->getId() === $this->user->id;
$this->template->canEdit = ($this->template->isMy || ($playlist->getOwner() instanceof Club && $playlist->getOwner()->canBeModifiedBy($this->user->identity)));
$this->template->edit = $this->queryParam("act") === "edit";
if ($this->template->edit) {
if (!$this->template->canEdit) {
$this->flashFail("err", tr("error"), tr("forbidden"));
}
$_ids = [];
$audios = iterator_to_array($playlist->getAudios());
foreach ($audios as $audio) {
$_ids[] = $audio->getId();
}
foreach ($this->audios->getByUser($this->user->identity) as $audio) {
if (!in_array($audio->getId(), $_ids)) {
$audios[] = $audio;
}
}
$this->template->audios = $audios;
} else {
$this->template->audios = iterator_to_array($playlist->getAudios());
}
/*if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (!$this->template->canEdit) {
@ -473,8 +450,8 @@ final class AudioPresenter extends OpenVKPresenter
switch($ctx_type) {
default:
case "entity_audios":
if($ctx_id > 0) {
$entity = (new Users)->get($ctx_id);
if($ctx_id >= 0) {
$entity = $ctx_id != 0 ? (new Users)->get($ctx_id) : $this->user->identity;
if(!$entity || !$entity->getPrivacyPermission("audios.read", $this->user->identity))
$this->flashFail("err", "Error", "Can't get queue", 80, true);
@ -505,13 +482,28 @@ final class AudioPresenter extends OpenVKPresenter
if (!$playlist || $playlist->isDeleted())
$this->flashFail("err", "Error", "Can't get queue", 80, true);
$audios = $playlist->getAudios($page, 10);
$audios = $playlist->fetch($page, 10);
$audiosCount = $playlist->size();
break;
case "search_context":
$stream = $this->audios->search($this->postParam("query"), 2);
$audios = $stream->page($page, 10);
$audiosCount = $stream->size();
break;
}
$pagesCount = ceil($audiosCount / $perPage);
# костылёк для получения плееров в пикере аудиозаписей
if((int)($this->postParam("returnPlayers")) === 1) {
$this->template->audios = $audios;
$this->template->page = $page;
$this->template->pagesCount = $pagesCount;
$this->template->count = $audiosCount;
return 0;
}
$audiosArr = [];
foreach($audios as $audio) {

View file

@ -2,7 +2,7 @@
namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\{Comment, Notifications\MentionNotification, Photo, Video, User, Topic, Post};
use openvk\Web\Models\Entities\Notifications\CommentNotification;
use openvk\Web\Models\Repositories\{Comments, Clubs, Videos, Photos};
use openvk\Web\Models\Repositories\{Comments, Clubs, Videos, Photos, Audios};
final class CommentPresenter extends OpenVKPresenter
{
@ -103,8 +103,27 @@ final class CommentPresenter extends OpenVKPresenter
}
}
}
$audios = [];
if(!empty($this->postParam("audios"))) {
$un = rtrim($this->postParam("audios"), ",");
$arr = explode(",", $un);
if(sizeof($arr) < 11) {
foreach($arr as $dat) {
$ids = explode("_", $dat);
$audio = (new Audios)->getByOwnerAndVID((int)$ids[0], (int)$ids[1]);
if(!$audio || $audio->isDeleted())
continue;
$audios[] = $audio;
}
}
}
if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) < 1)
if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) < 1 && sizeof($audios) < 1)
$this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_empty"));
try {
@ -126,6 +145,9 @@ final class CommentPresenter extends OpenVKPresenter
if(sizeof($videos) > 0)
foreach($videos as $vid)
$comment->attach($vid);
foreach($audios as $audio)
$comment->attach($audio);
if($entity->getOwner()->getId() !== $this->user->identity->getId())
if(($owner = $entity->getOwner()) instanceof User)

View file

@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Exceptions\TooMuchOptionsException;
use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User};
use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification};
use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos, Comments, Photos};
use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos, Comments, Photos, Audios};
use Chandler\Database\DatabaseConnection;
use Nette\InvalidStateException as ISE;
use Bhaktaraz\RSSGenerator\Item;
@ -311,8 +311,27 @@ final class WallPresenter extends OpenVKPresenter
}
}
}
$audios = [];
if(!empty($this->postParam("audios"))) {
$un = rtrim($this->postParam("audios"), ",");
$arr = explode(",", $un);
if(sizeof($arr) < 11) {
foreach($arr as $dat) {
$ids = explode("_", $dat);
$audio = (new Audios)->getByOwnerAndVID((int)$ids[0], (int)$ids[1]);
if(!$audio || $audio->isDeleted())
continue;
$audios[] = $audio;
}
}
}
if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) < 1 && !$poll && !$note)
if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) && sizeof($audios) < 1 && !$poll && !$note)
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big"));
try {
@ -341,6 +360,9 @@ final class WallPresenter extends OpenVKPresenter
if(!is_null($note))
$post->attach($note);
foreach($audios as $audio)
$post->attach($audio);
if($wall > 0 && $wall !== $this->user->identity->getId())
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();

View file

@ -16,7 +16,9 @@
<input type="hidden" name="bigplayer_context" data-type="playlist_context" data-entity="{$playlist->getId()}" data-page="{$page}">
<div class="playlistBlock">
<div class="playlistCover" style="float: left;">
<img src="{$playlist->getCoverURL()}">
<a href="{$playlist->getCoverURL()}" target="_blank">
<img src="{$playlist->getCoverURL('normal')}">
</a>
<div class="profile_links" style="width: 139px;">
<a id="profile_link" style="width: 98%;" n:if="$canEdit">{_edit_playlist}</a>
@ -30,7 +32,8 @@
<h4 style="border-bottom:unset;">{$playlist->getName()}</h4>
<div class="moreInfo">
<span>{tr("audios_count", $count)}</span><span>{_created_playlist}</span> {$playlist->getPublicationTime()}
<span>{tr("audios_count", $count)}</span>
<span>{_created_playlist}</span> {$playlist->getPublicationTime()}
<div style="margin-top: 11px;">
<span>{$playlist->getDescription()}</span>
@ -38,11 +41,21 @@
<hr style="color: #f7f7f7;">
</div>
</div>
<div class="audios" style="margin-top: 14px;">
<div class="audiosContainer infContainer" style="margin-top: 14px;">
{if $count < 1}
{_empty_playlist}
{else}
й йбй бй дй д яюдюяд ю бяб бля лбябл бялб я бля бляб ля я не сделал....
{else}
<div class="infObj" n:foreach="$audios as $audio">
{include "player.xml", audio => $audio}
</div>
{include "../components/paginator.xml", conf => (object) [
"page" => $page,
"count" => $count,
"amount" => sizeof($audios),
"perPage" => $perPage ?? OPENVK_DEFAULT_PER_PAGE,
"atBottom" => true,
]}
{/if}
</div>
</div>

View file

@ -0,0 +1,7 @@
<input type="hidden" name="count" value="{$count}">
<input type="hidden" name="pagesCount" value="{$pagesCount}">
<input type="hidden" name="page" value="{$page}">
{foreach $audios as $audio}
{include "player.xml", audio => $audio, hideButtons => true}
{/foreach}

View file

@ -1,10 +1,7 @@
{* На одной странице может оказаться несколько одинаковых аудиозаписей, и если запустить
одну, то начнут проигрываться все остальные. Поэтому тут мы добавляем рандомное число*}
{php $id = $audio->getId() . rand(0, 1000)}
{php $isWithdrawn = $audio->isWithdrawn()}
{php $editable = isset($thisUser) && $audio->canBeModifiedBy($thisUser)}
<div id="audioEmbed-{$id}" data-realid="{$audio->getId()}" data-genre="{$audio->getGenre()}" class="audioEmbed {if !$audio->isAvailable()}processed{/if} {if $isWithdrawn}withdrawn{/if}" onmouseenter="!this.classList.contains('inited') ? initPlayer({$id}, {$audio->getKeys()}, {$audio->getURL()}, {$audio->getLength()}) : void(0)">
<div id="audioEmbed-{$id}" data-realid="{$audio->getId()}" {if $hideButtons}data-prettyid="{$audio->getPrettyId()}" data-name="{$audio->getName()}"{/if} data-genre="{$audio->getGenre()}" class="audioEmbed {if !$audio->isAvailable()}processed{/if} {if $isWithdrawn}withdrawn{/if}" onmouseenter="!this.classList.contains('inited') ? initPlayer({$id}, {$audio->getKeys()}, {$audio->getURL()}, {$audio->getLength()}) : void(0)">
<audio class="audio" />
<div id="miniplayer" class="audioEntry" style="min-height: 37px;">
@ -24,17 +21,6 @@
fill="#828a99" fill-opacity=".7"/>
</svg>
</div>
<div class="track" style="margin-top: 3px">
<center class="claimed" style="width: 100%; padding: 4px; color: #45688E; font-weight: bold;" n:if="$isWithdrawn">
{_audio_embed_withdrawn}
</center>
<div class="selectableTrack" n:attr="style => $isWithdrawn ? 'display: none;' : ''">
<div>&nbsp;
<!-- actual track -->
</div>
</div>
</div>
</div>
<div class="volume" style="display: flex; flex-direction: column;width:14%;">
@ -42,18 +28,26 @@
<div class="buttons" style="margin-top: 8px;">
{php $hasAudio = isset($thisUser) && $audio->isInLibraryOf($thisUser)}
{if !$addToPlaylistButton}
{if !$hideButtons}
<div class="remove-icon musicIcon" data-id="{$audio->getId()}" n:if="isset($thisUser) && $hasAudio" ></div>
<div class="add-icon musicIcon" data-id="{$audio->getId()}" n:if="isset($thisUser) && !$hasAudio && !$isWithdrawn" ></div>
<div class="edit-icon musicIcon" data-lyrics="{$audio->getLyrics()}" data-title="{$audio->getTitle()}" data-performer="{$audio->getPerformer()}" data-explicit="{(int)$audio->isExplicit()}" data-searchable="{(int)!$audio->isUnlisted()}" n:if="isset($thisUser) && $editable && !$isWithdrawn" ></div>
<div class="report-icon musicIcon" data-id="{$audio->getId()}" n:if="isset($thisUser) && !$editable && !$isWithdrawn" ></div>
{else}
jrgnwighweif
{/if}
</div>
</div>
</div>
<div class="tracks">
<div class="track" style="margin-top: 3px;display:none">
<div class="selectableTrack" n:attr="style => $isWithdrawn ? 'display: none;' : ''">
<div>&nbsp;
<!-- actual track -->
</div>
</div>
</div>
</div>
<div class="lyrics" n:if="!empty($audio->getLyrics())">
{nl2br($audio->getLyrics())|noescape}
</div>

View file

@ -22,7 +22,7 @@
</div>
<div class="post-has-videos"></div>
<div class="post-has-audio"></div>
<div class="post-has-audios"></div>
<div n:if="$postOpts ?? true" class="post-opts">
{var $anonEnabled = OPENVK_ROOT_CONF['openvk']['preferences']['wall']['anonymousPosting']['enable']}
@ -63,6 +63,7 @@
</div>
<input type="hidden" name="photos" value="" />
<input type="hidden" name="videos" value="" />
<input type="hidden" name="audios" value="" />
<input type="hidden" name="poll" value="none" />
<input type="hidden" id="note" name="note" value="none" />
<input type="hidden" name="type" value="1" />
@ -86,14 +87,14 @@
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-vnd.rn-realmedia.png" />
{_video}
</a>
<a n:if="$notes ?? false" href="javascript:attachNote({$textAreaId})">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" />
{_note}
</a>
<a id="_audioAttachment">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/audio-ac3.png" />
{_audio}
</a>
<a n:if="$notes ?? false" href="javascript:attachNote({$textAreaId})">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" />
{_note}
</a>
<a n:if="$graffiti ?? false" href="javascript:initGraffiti({$textAreaId});">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/actions/draw-brush.png" />
{_graffiti}
@ -115,6 +116,7 @@
u("#post-buttons{$textAreaId} input[name='videos']")["nodes"].at(0).value = ""
u("#post-buttons{$textAreaId} input[name='photos']")["nodes"].at(0).value = ""
u("#post-buttons{$textAreaId} input[name='audios']")["nodes"].at(0).value = ""
</script>
{if $graffiti}

View file

@ -5,7 +5,7 @@
}
.musicIcon.pressed {
filter: brightness(0%);
filter: brightness(150%);
}
.bigPlayer {
@ -190,7 +190,7 @@
opacity: .7;
}
.audioEntry .status .track > .selectableTrack, .bigPlayer .selectableTrack {
.audioEmbed .track > .selectableTrack, .bigPlayer .selectableTrack {
margin-top: 3px;
width: calc(100% - 8px);
border-top: #707070 1px solid;
@ -199,7 +199,7 @@
user-select: none;
}
.audioEntry .status .track > div > div {
.audioEmbed .track > div > div {
height: 100%;
width: 0%;
background-color: #BFBFBF;
@ -275,6 +275,7 @@
}
.audioEntry .status {
overflow: hidden;
display: grid;
grid-template-columns: 1fr;
width: 85%;
@ -285,12 +286,12 @@
color: #4C4C4C;
}
.audioEntry .status .track {
.audioEmbed .track {
display: none;
padding: 4px 0;
}
#audioEmbed .audioEntry .status .track, .audioEntry.playing .status .track {
.audioEmbed .track, .audioEmbed.playing .track {
display: unset;
}
@ -308,7 +309,7 @@
width: 62px;
height: 20px;
position: absolute;
right: 46px;
right: 10%;
top: 2px;
}
@ -406,4 +407,39 @@
.playlistContainer .infObj:first-of-type {
margin-left: 0px;
}
.ovk-diag-body .searchBox {
background: #e6e6e6;
padding-top: 10px;
height: 35px;
padding-left: 10px;
padding-right: 10px;
}
.ovk-diag-body .searchBox input {
height: 24px;
}
.ovk-diag-body .audiosInsert {
height: 82%;
padding: 9px 5px 9px 9px;
overflow-y: auto;
}
.ovk-diag-body .attachAudio {
float: left;
width: 28%;
height: 26px;
padding-top: 11px;
text-align: center;
}
.ovk-diag-body .attachAudio span {
user-select: none;
}
.ovk-diag-body .attachAudio:hover {
background: rgb(236, 236, 236);
cursor: pointer;
}

View file

@ -1418,7 +1418,7 @@ body.scrolled .toTop:hover {
display: none;
}
.post-has-videos {
.post-has-videos, .post-has-audios {
margin-top: 11px;
margin-left: 3px;
color: #3c3c3c;
@ -1435,7 +1435,7 @@ body.scrolled .toTop:hover {
margin-left: 2px;
}
.post-has-video {
.post-has-video, .post-has-audio {
padding-bottom: 4px;
cursor: pointer;
}
@ -1444,6 +1444,10 @@ body.scrolled .toTop:hover {
text-decoration: underline;
}
.post-has-audio:hover span {
text-decoration: underline;
}
.post-has-video::before {
content: " ";
width: 14px;
@ -1457,6 +1461,19 @@ body.scrolled .toTop:hover {
margin-bottom: -1px;
}
.post-has-audio::before {
content: " ";
width: 14px;
height: 15px;
display: inline-block;
vertical-align: bottom;
background-image: url("/assets/packages/static/openvk/img/audio.png");
background-repeat: no-repeat;
margin: 3px;
margin-left: 2px;
margin-bottom: -1px;
}
.post-opts {
margin-top: 10px;
}

BIN
Web/static/img/audio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 994 B

View file

@ -484,7 +484,7 @@ class bigPlayer {
title: obj.name,
artist: obj.performer,
album: album == null ? "OpenVK Audios" : album.querySelector(".playlistInfo h4").innerHTML,
artwork: [{ src: album == null ? "/assets/packages/static/openvk/img/song.jpg" : album.querySelector(".playlistCover img") }],
artwork: [{ src: album == null ? "/assets/packages/static/openvk/img/song.jpg" : album.querySelector(".playlistCover img").src }],
});
}
}
@ -756,10 +756,135 @@ $(document).on("click", ".musicIcon.add-icon", (e) => {
})
$(document).on("click", "#_audioAttachment", (e) => {
let form = e.currentTarget.closest("form")
let body = `
я ещё не сделал
<div class="searchBox">
<input name="query" type="text" placeholder="${tr("header_search")}">
</div>
<div class="audiosInsert"></div>
`
MessageBox(tr("select_audio"), body, [tr("ok")], [Function.noop])
document.querySelector(".ovk-diag-body").style.padding = "0"
document.querySelector(".ovk-diag-cont").style.width = "580px"
document.querySelector(".ovk-diag-body").style.height = "335px"
async function insertAudios(page, query = "") {
document.querySelector(".audiosInsert").insertAdjacentHTML("beforeend", `<img id="loader" src="/assets/packages/static/openvk/img/loading_mini.gif">`)
$.ajax({
type: "POST",
url: "/audios/context",
data: {
context: query == "" ? "entity_audios" : "search_context",
hash: u("meta[name=csrf]").attr("value"),
page: page,
query: query == "" ? null : query,
context_entity: 0,
returnPlayers: 1,
},
success: (response) => {
let domparser = new DOMParser()
let result = domparser.parseFromString(response, "text/html")
let pagesCount = result.querySelector("input[name='pagesCount']").value
let count = Number(result.querySelector("input[name='count']").value)
if(count < 1) {
document.querySelector(".audiosInsert").innerHTML = tr("no_results")
return
}
result.querySelectorAll(".audioEmbed").forEach(el => {
let id = el.dataset.prettyid
let name = el.dataset.name
let isAttached = (form.querySelector("input[name='audios']").value.includes(`${id},`))
document.querySelector(".audiosInsert").insertAdjacentHTML("beforeend", `
<div style="display: table;width: 100%;clear: both;">
<div style="width: 72%;float: left;">${el.outerHTML}</div>
<div class="attachAudio" data-attachmentdata="${id}" data-name="${name}">
<span>${isAttached ? tr("detach_audio") : tr("attach_audio")}</span>
</div>
</div>
`)
})
u("#loader").remove()
if(page < pagesCount) {
document.querySelector(".audiosInsert").insertAdjacentHTML("beforeend", `
<div id="showMoreAudios" data-pagesCount="${pagesCount}" data-page="${page + 1}" style="width: 100%;text-align: center;background: #d5d5d5;height: 22px;padding-top: 9px;cursor:pointer;">
<span>more...</span>
</div>`)
}
}
})
}
insertAudios(1)
$(".audiosInsert").on("click", "#showMoreAudios", (e) => {
u(e.currentTarget).remove()
insertAudios(Number(e.currentTarget.dataset.page))
})
$(".searchBox input").on("change", async (e) => {
await new Promise(r => setTimeout(r, 1000));
if(e.currentTarget.value === document.querySelector(".searchBox input").value) {
document.querySelector(".audiosInsert").innerHTML = ""
insertAudios(1, e.currentTarget.value)
return;
} else {
console.info("skipping")
}
})
function insertAttachment(id) {
let audios = form.querySelector("input[name='audios']")
if(!audios.value.includes(id + ",")) {
if(audios.value.split(",").length > 10) {
NewNotification(tr("error"), tr("max_attached_audios"))
return false
}
form.querySelector("input[name='audios']").value += (id + ",")
console.info(id + " attached")
return true
} else {
form.querySelector("input[name='audios']").value = form.querySelector("input[name='audios']").value.replace(id + ",", "")
console.info(id + " detached")
return false
}
}
$(".audiosInsert").on("click", ".attachAudio", (ev) => {
if(!insertAttachment(ev.currentTarget.dataset.attachmentdata)) {
u(`.post-has-audios .post-has-audio[data-id='${ev.currentTarget.dataset.attachmentdata}']`).remove()
ev.currentTarget.querySelector("span").innerHTML = tr("attach_audio")
} else {
ev.currentTarget.querySelector("span").innerHTML = tr("detach_audio")
form.querySelector(".post-has-audios").insertAdjacentHTML("beforeend", `
<div class="post-has-audio" id="unattachAudio" data-id="${ev.currentTarget.dataset.attachmentdata}">
<span>${ovk_proc_strtr(escapeHtml(ev.currentTarget.dataset.name), 40)}</span>
</div>
`)
u(`#unattachAudio[data-id='${ev.currentTarget.dataset.attachmentdata}']`).on("click", (e) => {
let id = ev.currentTarget.dataset.attachmentdata
form.querySelector("input[name='audios']").value = form.querySelector("input[name='audios']").value.replace(id + ",", "")
console.info(id + " detached")
u(e.currentTarget).remove()
})
}
})
})
$(document).on("click", ".audioEmbed.processed", (e) => {

View file

@ -786,6 +786,8 @@
"unable_to_load_queue" = "Error when loading queue.";
"fully_delete_audio" = "Fully delete audio";
"attach_audio" = "Attach audio";
"detach_audio" = "Detach audio";
/* Notifications */

View file

@ -742,6 +742,8 @@
"unable_to_load_queue" = "Не удалось загрузить очередь.";
"fully_delete_audio" = "Полностью удалить аудиозапись";
"attach_audio" = "Прикрепить аудиозапись";
"detach_audio" = "Открепить аудиозапись";
/* Notifications */