From 890961e63d436f907280f1efa6c2b1f5891aa141 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:20:25 +0300 Subject: [PATCH] changes to photo viewer + photo/video pages layout --- Web/Models/Entities/Report.php | 9 +- Web/Presenters/InternalAPIPresenter.php | 6 +- Web/Presenters/PhotosPresenter.php | 23 ++ Web/Presenters/templates/Audio/player.xml | 4 +- Web/Presenters/templates/Photos/Photo.xml | 107 +++--- Web/Presenters/templates/Videos/View.xml | 181 ++++++----- .../templates/components/attachment.xml | 2 +- Web/routes.yml | 2 + Web/static/css/audios.css | 1 + Web/static/css/main.css | 132 +++++++- Web/static/img/left_arr.png | Bin 1583 -> 0 bytes Web/static/img/right_arr.png | Bin 1577 -> 0 bytes Web/static/js/al_api.js | 2 +- Web/static/js/al_wall.js | 304 +++++++++++------- Web/static/js/messagebox.js | 18 +- Web/static/js/openvk.cls.js | 2 +- 16 files changed, 505 insertions(+), 288 deletions(-) delete mode 100644 Web/static/img/left_arr.png delete mode 100644 Web/static/img/right_arr.png diff --git a/Web/Models/Entities/Report.php b/Web/Models/Entities/Report.php index 1b36678c..33bf84f7 100644 --- a/Web/Models/Entities/Report.php +++ b/Web/Models/Entities/Report.php @@ -134,8 +134,13 @@ class Report extends RowModel function getContentName(): string { - if (method_exists($this->getContentObject(), "getCanonicalName")) - return $this->getContentObject()->getCanonicalName(); + $content_object = $this->getContentObject(); + if(!$content_object) { + return 'unknown'; + } + + if (method_exists($content_object, "getCanonicalName")) + return $content_object->getCanonicalName(); return $this->getContentType() . " #" . $this->getContentId(); } diff --git a/Web/Presenters/InternalAPIPresenter.php b/Web/Presenters/InternalAPIPresenter.php index dca5db04..901d8d0b 100644 --- a/Web/Presenters/InternalAPIPresenter.php +++ b/Web/Presenters/InternalAPIPresenter.php @@ -121,9 +121,9 @@ final class InternalAPIPresenter extends OpenVKPresenter { if($attachment instanceof \openvk\Web\Models\Entities\Photo) { - $response[] = [ - "url" => $attachment->getURLBySizeId('normal'), - "id" => $attachment->getPrettyId() + $response[$attachment->getPrettyId()] = [ + "url" => $attachment->getURLBySizeId('large'), + "id" => $attachment->getPrettyId(), ]; } } diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 1bcd50da..cec426b8 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -176,6 +176,7 @@ final class PhotosPresenter extends OpenVKPresenter $this->template->cCount = $photo->getCommentsCount(); $this->template->cPage = (int) ($this->queryParam("p") ?? 1); $this->template->comments = iterator_to_array($photo->getComments($this->template->cPage)); + $this->template->owner = $photo->getOwner(); } function renderAbsolutePhoto($id): void @@ -355,4 +356,26 @@ final class PhotosPresenter extends OpenVKPresenter $this->flash("succ", tr("photo_is_deleted"), tr("photo_is_deleted_desc")); $this->redirect($redirect); } + + function renderLike(int $wall, int $post_id): void + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + $this->assertNoCSRF(); + + $photo = $this->photos->getByOwnerAndVID($wall, $post_id); + if(!$photo || $photo->isDeleted() || !$photo->canBeViewedBy($this->user->identity)) $this->notFound(); + + if(!is_null($this->user)) { + $photo->toggleLike($this->user->identity); + } + + if($_SERVER["REQUEST_METHOD"] === "POST") { + $this->returnJson([ + 'success' => true, + ]); + } + + $this->redirect("$_SERVER[HTTP_REFERER]"); + } } diff --git a/Web/Presenters/templates/Audio/player.xml b/Web/Presenters/templates/Audio/player.xml index d94341d2..24fe4723 100644 --- a/Web/Presenters/templates/Audio/player.xml +++ b/Web/Presenters/templates/Audio/player.xml @@ -11,11 +11,11 @@
-
+
- {$audio->getPerformer()} + {$audio->getPerformer()} {$audio->getTitle()} diff --git a/Web/Presenters/templates/Photos/Photo.xml b/Web/Presenters/templates/Photos/Photo.xml index e3ecaf9c..8f857581 100644 --- a/Web/Presenters/templates/Photos/Photo.xml +++ b/Web/Presenters/templates/Photos/Photo.xml @@ -4,76 +4,69 @@ {block header} {ifset $album} - - {$album->getOwner()->getCanonicalName()} + {var $album_owner = $album->getOwner()} + + {$album_owner->getCanonicalName()} - {if ($album->getOwner() instanceof openvk\Web\Models\Entities\Club)} - » {_albums} + {if ($album_owner instanceof openvk\Web\Models\Entities\Club)} + » {_albums} {else} - » {_albums} + » {_albums} {/if} » {$album->getName()} {else} - {$photo->getOwner()->getCanonicalName()} + {$owner->getCanonicalName()} {/ifset} » {_photo} {/block} {block content} -
- -
- -
- -
-
- {include "../components/comments.xml", comments => $comments, count => $cCount, page => $cPage, model => "photos", parent => $photo, custom_id => 999} +
+
+
-
-
-

{_information}

- {_info_description}: - {$photo->getDescription() ?? "(" . tr("none") . ")"}
- {_info_uploaded_by}: - {$photo->getOwner()->getFullName()}
- {_info_upload_date}: - {$photo->getPublicationTime()} + +
+
+

{$photo->getDescription()}

+
+ {_info_upload_date}: {$photo->getPublicationTime()} + {if isset($thisUser)} + | + {var $liked = $photo->hasLikeFrom($thisUser)} + {var $likesCount = $photo->getLikesCount()} + + {/if} +
-
-

{_actions}

- {if isset($thisUser) && $thisUser->getId() != $photo->getOwner()->getId()} - {var canReport = true} - {/if} - - {_"open_original"} - {_report} - +
+ +
+
+ {include "../components/comments.xml", comments => $comments, count => $cCount, page => $cPage, model => "photos", parent => $photo, custom_id => 999} +
+ +
{/block} diff --git a/Web/Presenters/templates/Videos/View.xml b/Web/Presenters/templates/Videos/View.xml index cdaaba11..c215cc92 100644 --- a/Web/Presenters/templates/Videos/View.xml +++ b/Web/Presenters/templates/Videos/View.xml @@ -11,91 +11,108 @@ {/block} {block content} -
- {if $video->getType() === 0} -
- -
- {else} - {var $driver = $video->getVideoDriver()} - {if !$driver} - {_unknown_video} - {else} - {$driver->getEmbed()|noescape} - {/if} - {/if} -
- -
- -
-
- {include "../components/comments.xml", - comments => $comments, - count => $cCount, - page => $cPage, - model => "videos", - parent => $video} -
-
-
-

{_information}

- {_info_name}: - {$video->getName()}
- {_info_description}: - {$video->getDescription() ?? "(" . tr("none") . ")"}
- {_info_uploaded_by}: - {$user->getFullName()}
- {_info_upload_date}: - {$video->getPublicationTime()} -
-
-
-
-

{_actions}

- - {_edit} - - - {_delete} - +
+
+ {if $video->getType() === 0} +
+
- - {_watch_in_window} - -
- - {if isset($thisUser)} - {if $thisUser->getId() != $video->getOwner()->getId()} - {var canReport = true} + {else} + {var $driver = $video->getVideoDriver()} + {if !$driver} + {_unknown_video} + {else} + {$driver->getEmbed()|noescape} {/if} {/if} - - {_report} - -
+ +
+
+

{$video->getName()}

+

{$video->getDescription()}

+
+ {_info_upload_date}: {$video->getPublicationTime()} + {if isset($thisUser)} + | + {var $liked = $video->hasLikeFrom($thisUser)} + {var $likesCount = $video->getLikesCount()} + + {/if} +
+
+ +
+ +
+
+ {include "../components/comments.xml", + comments => $comments, + count => $cCount, + page => $cPage, + model => "videos", + parent => $video} +
+
+ + + +
+ {$user->getCanonicalName()} +
+
+ + + + {if isset($thisUser)} + {if $thisUser->getId() != $video->getOwner()->getId()} + {var canReport = true} + {/if} + {/if} + + {_report} + + +
+
+
+ +
{/block} diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index fb59a27c..54a224a5 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -1,7 +1,7 @@ {if $attachment instanceof \openvk\Web\Models\Entities\Photo} {if !$attachment->isDeleted()} {var $link = "/photo" . ($attachment->isAnonymous() ? ("s/" . base_convert((string) $attachment->getId(), 10, 32)) : $attachment->getPrettyId())} - + {$attachment->getDescription()} {else} diff --git a/Web/routes.yml b/Web/routes.yml index c1941d92..97064d4c 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -171,6 +171,8 @@ routes: handler: "Photos->uploadPhoto" - url: "/photo{num}_{num}" handler: "Photos->photo" + - url: "/photo{num}_{num}/like" + handler: "Photos->like" - url: "/photos/thumbnails/{num}_{text}.jpeg" handler: "Photos->thumbnail" - url: "/photos/{text}" diff --git a/Web/static/css/audios.css b/Web/static/css/audios.css index a834b773..dae9020b 100644 --- a/Web/static/css/audios.css +++ b/Web/static/css/audios.css @@ -783,6 +783,7 @@ .addToPlaylist { width: 22%; + float: left; } #_addAudioAdditional { diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 3725ee70..93ef4eb4 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -13,7 +13,7 @@ body { word-wrap: break-word; } -body, .ovk-fullscreen-dimmer { +body, .ovk-fullscreen-dimmer, .ovk-photo-view-dimmer { scrollbar-gutter: stable both-edges; } @@ -1574,6 +1574,15 @@ body.scrolled .toTop:hover { float: right; } +.like_wrap.tidy { + float: none; + display: inline-block; +} + +.like_wrap.tidy .post-like-button { + display: flex; +} + .heart { background: url('/assets/packages/static/openvk/img/like.gif') no-repeat 1px 0; height: 10px; @@ -1583,12 +1592,22 @@ body.scrolled .toTop:hover { opacity: 0.4; } +.like_wrap.tidy .heart { + float: none; + display: inline-block; +} + .likeCnt { font-size: 10px; margin-right: 3px; float: left; } +.like_wrap.tidy .likeCnt { + float: none; + display: inline; +} + .heart:hover { opacity: 1 !important; } @@ -2439,6 +2458,7 @@ a.poll-retract-vote { justify-content: center; align-items: center; position: relative; + min-height: 63px; } .post-horizontal .upload-item .play-button, .compact_video .play-button { @@ -2551,21 +2571,33 @@ a.poll-retract-vote { position: relative; z-index: 999; background: #fff; - width: 610px; - padding: 20px; + min-width: 600px; + width: fit-content; + padding: 25px; padding-top: 15px; padding-bottom: 10px; box-shadow: 0px 0px 3px 1px #222; - margin: 15px auto 0 auto; + margin: 10px auto 0 auto; } -.ovk-photo-details { - overflow: auto; +.ovk-photo-view .photo_viewer_wrapper { + position: relative; + height: 80vh; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} + +.ovk-photo-view #ovk-photo-img { + max-width: 100%; + max-height: 80vh; + user-select: none; } .photo_com_title { font-weight: bold; - padding-bottom: 20px; + padding-bottom: 16px; } .photo_com_title div { @@ -2577,7 +2609,6 @@ a.poll-retract-vote { left: 0; width: 35%; height: 100%; - max-height: 60vh; position: absolute; cursor: pointer; } @@ -2586,11 +2617,25 @@ a.poll-retract-vote { right: 0; width: 35%; height: 100%; - max-height: 60vh; position: absolute; cursor: pointer; } +.ovk-photo-view .media-page-wrapper-details { + display: flex; + gap: 10px; +} + +.ovk-photo-view .media-page-wrapper-comments { + overflow-y: auto; + overflow-x: hidden; + min-height: 300px; +} + +.ovk-photo-view .ovk-photo-details { + margin-top: 10px; +} + .client_app > img { top: 3px; position: relative; @@ -3535,3 +3580,72 @@ hr { color: white; } +.media-page-wrapper .photo-page-wrapper-photo { + margin-bottom: 8pt; + text-align: center; +} + +.media-page-wrapper .video-page-wrapper-video { + text-align: center; +} + +.media-page-wrapper .photo-page-wrapper-photo img { + max-width: 85%; + max-height: 60vh; +} + +.media-page-wrapper-details { + width: 100%; + min-height: 100px; + display: flex; + justify-content: space-between; + gap: 10px; +} + +.media-page-wrapper-comments { + min-height: 100px; + width: 68%; + margin-left: 3px; +} + +.media-page-wrapper-actions { + min-height: 100px; + width: 30%; + margin-left: 1px; +} + +.media-page-wrapper-description p { + margin: 0px; +} + +.media-page-wrapper-description .upload_time { + color: gray; + display: inline-flex; + align-items: center; + height: 16px; +} + +.media-page-author-block { + display: flex; + align-items: center; + gap: 7px; + margin-bottom: 5px; +} + +.media-page-author-block img { + width: 30px; +} + +.media-page-author-block .media-page-author-block-name { + display: flex; + flex-direction: column; + justify-content: center; +} + +.media-page-author-block .media-page-author-block-name b { + font-weight: bold; +} + +.media-page-author-block .media-page-author-block-name span { + text-transform: lowercase; +} diff --git a/Web/static/img/left_arr.png b/Web/static/img/left_arr.png deleted file mode 100644 index 6be3f80a86b4602fa703feffd81146ecdd811a85..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1583 zcmbtU2~!dX6s9(}%hF11No%Gn2h;#-5|Dmg08x+Cq=Bp>c)~pafJe;D%jb*?eB%{=YytqV z_4#*SBa5%T2mly$zDG?us33O|y*~>X#y~sYxysHT60}bigW?XI0!w-G}FC%?( z?j8QcWefz`cfKd8qg1w_n=B~PerYRMY`yc3N!k7Sy67HsA|f$y)Y?$$zuPAd@ksja zMzOdrWR6|9b2SB)H1XsRxehw&tF;L@!iT>m>W3Ak1nd9}3u%-uf&Zog$0&-qh=G8( zd0RR!Hs2d;i5oSsa8gGuFOrJIcMmnypeh=>c?@nVkt$P|66Z}JA2dhxnOYLWd-|N@ zDRL$G0AGH+bM-RSANl~!o|4A)_;)U`32nw#8QKjHg|)MqId03Aq1O#@(ut&#lKpm& zvy^MT!7Mi_mdBM3f+4BEu`3EH=#<|Pp+V_7i3)?>33nLH2Zui_%;BE6tbe93-H9E@ z%F#SUv6I`3A3f2M&8>5zoz;k>Pm}$)v6D-(*&61rk@_igA zVy!R?XiSj z?z@=oz9&X```tm;SNC*W)Tri7Rze1}H!+y944zyG5Kgv8D~AaiDRk?}RxhEANmJMu z{#H47$UH2?{S<~Z3|Dc#ZqGdtrGKe-fy?3YrWzx%Br=XNu#Y3Z<`80N{^mKQEd%?T zVepu6dP4F;%lc#u@X)H!yfT7)yz;u5PIPSEzc1;<}SGR{}~ z%Kdz!rxJEGUtpVlKfk9;fL!#RdV8DgC7AjnM1#Xrd@C%(ll_pPj79%ou7D4c zz^AN(3<-Oy-Q#t6e_iyzBu33Tn%|gdK$oi&Kv;M-Z2gyAN;ki@ci(2CPZQ6vGA$V= zncF08qU?8wMDRcuGtV_|@z7u@&=>Bce;P_;rQ$5gd}IBqz|8}UH%@%`)NOCeGr^R# zu1jxI0*S0*fg26TncO(xw6M4R&5vxZ3jO^l|6l78H|QYEGArp|Hf8;HF&H$+N8}Zi F@h=A0<0k+B diff --git a/Web/static/img/right_arr.png b/Web/static/img/right_arr.png deleted file mode 100644 index ed4c4708f63bd5e719908a7a416ef80c41c7b711..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1577 zcmb7EX;6~~5Dm6~3Q=s~v)qDJt^hS4a*7BMIZP1264ZEc1!GXT!Xb2+CIS&?K*0$4 zT4ErCAR-cuM94Up5;+awP!W*GnV=ZLQOePN{_mge%+BtcH#=|l{n(r!v@d+8!A=+q z2KPJZ6AV=s7)U zJdB4c#B1s9BALzsFUOEfWy1M0G;1R6LmNCWO^dahF7w^zi-IQig3rHbJWLGh&kiGPp8^p5Ayv2K> z%J+8u*DR9jvJt_mFOe8ks2)8*nNDqYhbte7M!;#VHB#SNF3X2z2d~7x3c6p6mUB{{ z7Vf))N%hi)dN5ZOOylgL*|OS ztF|aqZECg26h0e+a2iTD9qY!?>#YUt$|&;N;Ls~OKjJ7p;+sM6MX`=U0>&1$O>KizmEUl`(shpe$tH)&?NAwrSaJ zW5y&umrs#SqAi{@z8R6~#9?)>yP)aT!Esxz@plcXJ;UAQc+YD9T|1OqSET)FwDwqA>nZ0G8e(s$(`W?lXEZ_e_&r5TmE1G^f>`qw=d zhZ@=BBz3{jNKI-WrG~gaV*$VYFe8&C)h2Te%%f10AExpVXag<(*yvIjt)$(WT{1m>m5SObvx%c8gFk6 zS&+nklo2H#uVNFHpV!QNy=D@hy&uu==we0V$xnb!Z@}#jr;b!``PlOj$cV%u=XF(Z z-qM15A2arH(1@QT+$pvwprMOkBK>evQu)3lTt4ZL`MX$mrp5e+nUy#-$K`yq!=T(^bzaVg`KCa#5K6 z!6Qg`r6wr3RoWBwWxJ-Z61RvnUCsi_p-B8J@Ip-YR$15?+QSl6%NiLq+0~Hrc6sey zjb=~*I``;L0G9Qhpd6RR1(ul4j1Hi3Px)ufu1pi5-!$ka>1rSv`ARf~=X)aj`^*L7 y&R|_DnKI9+ImF;5Oq3xk|Mz$NkAd>y;w^Ri-;4zMn~w^<@_s0^PwnwbS^ok?!rS}+ diff --git a/Web/static/js/al_api.js b/Web/static/js/al_api.js index eb613dc1..d5791ed0 100644 --- a/Web/static/js/al_api.js +++ b/Web/static/js/al_api.js @@ -49,7 +49,7 @@ window.OVKAPI = new class { if(json_response.response) { return json_response.response } else { - throw new Exception(json_response.error_msg) + throw new Error(json_response.error_msg) } } } diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index ee5bda47..d2cd417f 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -85,175 +85,207 @@ u(document).on("input", "textarea", function(e) { // textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px"; }); -function OpenMiniature(e, photo, post, photo_id, type = "post") { +async function OpenMiniature(e, photo, post, photo_id, type = "post") { /* костыли но смешные однако */ e.preventDefault(); - if(u(".ovk-photo-view").length > 0) u(".ovk-photo-view-dimmer").remove(); - // Значения для переключения фоток + const albums_per_page = 20 let json; + let offset = type == 'album' ? (Number((new URL(location.href)).searchParams.get('p') ?? 1) - 1) * albums_per_page : 0 + let shown_offset = 0 let imagesCount = 0; - let imagesIndex = 0; + let currentImageid = '0_0'; - let tempDetailsSection = []; - - let dialog = u( - `
-
-
- + const photo_viewer = new CMessageBox({ + title: '', + custom_template: u(` +
+
+
+ + + + +
+
+
+
+ +
+ -
-
-
- -
-
- -
-
-
`); - u("body").addClass("dimmed").append(dialog); - document.querySelector("html").style.overflowY = "hidden" - - let button = u("#ovk-photo-close"); +
`) + }) - button.on("click", function(e) { - let __closeDialog = () => { - u("body").removeClass("dimmed"); - u(".ovk-photo-view-dimmer").remove(); - document.querySelector("html").style.overflowY = "scroll" - }; - - __closeDialog(); + photo_viewer.getNode().find("#ovk-photo-close").on("click", function(e) { + photo_viewer.close() }); - function __reloadTitleBar() { - u("#photo_com_title_photos").last().innerHTML = imagesCount > 1 ? tr("photo_x_from_y", imagesIndex, imagesCount) : tr("photo"); + function __getIndex(photo_id = null) { + return Object.keys(json.body).findIndex(item => item == (photo_id ?? currentImageid)) + 1 } - function __loadDetails(photo_id, index) { - if(tempDetailsSection[index] == null) { - u(".ovk-photo-details").last().innerHTML = ''; - ky("/photo" + photo_id, { - hooks: { - afterResponse: [ - async (_request, _options, response) => { - let parser = new DOMParser(); - let body = parser.parseFromString(await response.text(), "text/html"); + function __getByIndex(id) { + const ids = Object.keys(json.body) + const _id = ids[id - 1] - let element = u(body.getElementsByClassName("ovk-photo-details")).last(); + return json.body[_id] + } - tempDetailsSection[index] = element.innerHTML; + function __reloadTitleBar() { + photo_viewer.getNode().find("#photo_com_title_photos").last().innerHTML = imagesCount > 1 ? tr("photo_x_from_y", shown_offset, imagesCount) : tr("photo"); + } - if(index == imagesIndex) { - u(".ovk-photo-details").last().innerHTML = element.innerHTML ?? ''; - } + async function __loadDetails(photo_id) { + if(json.body[photo_id].cached == null) { + photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = ''; + const photo_url = `/photo${photo_id}` + const photo_page = await fetch(photo_url) + const photo_text = await photo_page.text() + const parser = new DOMParser + const body = parser.parseFromString(photo_text, "text/html") + const details = body.querySelector('.ovk-photo-details') + json.body[photo_id].cached = details.innerHTML ?? '' + if(photo_id == currentImageid) { + photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = details.innerHTML ?? ''; + } - document.querySelectorAll(".ovk-photo-details .bsdn").forEach(bsdnInitElement) - document.querySelectorAll(".ovk-photo-details script").forEach(scr => { - // stolen from #953 - let newScr = document.createElement('script') - - if(scr.src) { - newScr.src = scr.src - } else { - newScr.textContent = scr.textContent - } - - document.querySelector(".ovk-photo-details").appendChild(newScr); - }) - } - ] - } - }); + photo_viewer.getNode().find(".ovk-photo-details .bsdn").nodes.forEach(bsdnInitElement) } else { - u(".ovk-photo-details").last().innerHTML = tempDetailsSection[index]; + photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = json.body[photo_id].cached } } - function __slidePhoto(direction) { + async function __slidePhoto(direction) { /* direction = 1 - right direction = 0 - left */ if(json == undefined) { console.log("Да подожди ты. Куда торопишься?"); } else { - if(imagesIndex >= imagesCount && direction == 1) { - imagesIndex = 1; - } else if(imagesIndex <= 1 && direction == 0) { - imagesIndex = imagesCount; + let current_index = __getIndex() + if(current_index >= imagesCount && direction == 1) { + shown_offset = 1 + current_index = 1 + } else if(current_index <= 1 && direction == 0) { + shown_offset += imagesCount - 1 + current_index = imagesCount } else if(direction == 1) { - imagesIndex++; + shown_offset += 1 + current_index += 1 } else if(direction == 0) { - imagesIndex--; + shown_offset -= 1 + current_index -= 1 } - let photoURL = json.body[imagesIndex - 1].url; + currentImageid = __getByIndex(current_index) + if(!currentImageid) { + if(type == 'album') { + if(direction == 1) { + offset += albums_per_page + } else { + offset -= albums_per_page + } + + await __loadContext(type, post, true, direction == 0) + } else { + return + } + } + currentImageid = currentImageid.id + let photoURL = json.body[currentImageid].url; - u("#ovk-photo-img").last().src = photoURL; + photo_viewer.getNode().find("#ovk-photo-img").last().src = '' + photo_viewer.getNode().find("#ovk-photo-img").last().src = photoURL; __reloadTitleBar(); - __loadDetails(json.body[imagesIndex - 1].id, imagesIndex); + __loadDetails(json.body[currentImageid].id); } } - let slideLeft = u(".ovk-photo-slide-left"); - - slideLeft.on("click", (e) => { - __slidePhoto(0); - }); - - let slideRight = u(".ovk-photo-slide-right"); - - slideRight.on("click", (e) => { - __slidePhoto(1); - }); - - let data = new FormData() - data.append('parentType', type); + async function __loadContext(type, id, ref = false, inverse = false) { + if(type == 'post' || type == 'comment') { + const form_data = new FormData() + form_data.append('parentType', type); - if(type) { - ky.post("/iapi/getPhotosFromPost/" + (type == "post" ? post : "1_"+post), { - hooks: { - afterResponse: [ - async (_request, _options, response) => { - json = await response.json(); - - imagesCount = json.body.length; - imagesIndex = 0; - // Это всё придётся правда на 1 прибавлять - - json.body.every(element => { - imagesIndex++; - if(element.id == photo_id) { - return false; - } else { - return true; - } - }); - - __reloadTitleBar(); - __loadDetails(json.body[imagesIndex - 1].id, imagesIndex); } - ] - }, - body: data - }); - } else { - imagesCount = 1 - __reloadTitleBar() - __loadDetails(photo_id, imagesIndex) + const endpoint_url = `/iapi/getPhotosFromPost/${type == "post" ? id : "1_"+id}` + const fetcher = await fetch(endpoint_url, { + method: 'POST', + body: form_data, + }) + json = await fetcher.json() + imagesCount = Object.entries(json.body).length + } else { + const params = { + 'offset': offset, + 'count': albums_per_page, + 'owner_id': id.split('_')[0], + 'album_id': id.split('_')[1], + 'photo_sizes': 1 + } + + const result = await window.OVKAPI.call('photos.get', params) + const converted_items = {} + + result.items.forEach(item => { + const id = item.owner_id + '_' + item.id + converted_items[id] = { + 'url': item.src_xbig, + 'id': id, + } + }) + imagesCount = result.count + + if(!json) + json = {'body': []} + + if(!inverse) { + json.body = Object.assign(converted_items, json.body) + } else { + json.body = Object.assign(json.body, converted_items) + } + } + + currentImageid = photo_id } - return u(".ovk-photo-view-dimmer"); + photo_viewer.getNode().find(".ovk-photo-slide-left").on("click", (e) => { + __slidePhoto(0); + }) + photo_viewer.getNode().find(".ovk-photo-slide-right").on("click", (e) => { + __slidePhoto(1); + }) + + if(!type) { + imagesCount = 1 + json = { + 'body': {} + } + + json.body[photo_id] = { + 'id': photo_id, + 'url': photo + } + currentImageid = photo_id + + __reloadTitleBar() + __loadDetails(photo_id) + } else { + await __loadContext(type, post) + shown_offset = offset + __getIndex() + + __reloadTitleBar(); + __loadDetails(json.body[currentImageid].id); + } + + return photo_viewer.getNode() } u("#write > form").on("keydown", function(event) { @@ -261,6 +293,28 @@ u("#write > form").on("keydown", function(event) { this.submit(); }); +function reportPhoto(photo_id) { + uReportMsgTxt = tr("going_to_report_photo"); + uReportMsgTxt += "
"+tr("report_question_text"); + uReportMsgTxt += "

"+tr("report_reason")+": " + + MessageBox(tr("report_question"), uReportMsgTxt, [tr("confirm_m"), tr("cancel")], [ + (function() { + res = document.querySelector("#uReportMsgInput").value; + xhr = new XMLHttpRequest(); + xhr.open("GET", "/report/" + photo_id + "?reason=" + res + "&type=photo", true); + xhr.onload = (function() { + if(xhr.responseText.indexOf("reason") === -1) + MessageBox(tr("error"), tr("error_sending_report"), ["OK"], [Function.noop]); + else + MessageBox(tr("action_successfully"), tr("will_be_watched"), ["OK"], [Function.noop]); + }); + xhr.send(null); + }), + Function.noop + ]); +} + var tooltipClientTemplate = Handlebars.compile(` diff --git a/Web/static/js/messagebox.js b/Web/static/js/messagebox.js index 0bc51d86..e75d2c7e 100644 --- a/Web/static/js/messagebox.js +++ b/Web/static/js/messagebox.js @@ -9,6 +9,7 @@ class CMessageBox { const close_on_buttons = options.close_on_buttons ?? true const unique_name = options.unique_name ?? null const warn_on_exit = options.warn_on_exit ?? false + const custom_template = options.custom_template ?? null if(unique_name && window.messagebox_stack.find(item => item.unique_name == unique_name) != null) { return } @@ -20,7 +21,14 @@ class CMessageBox { this.unique_name = unique_name this.warn_on_exit = warn_on_exit - u('body').addClass('dimmed').append(this.__getTemplate()) + if(!custom_template) { + u('body').addClass('dimmed').append(this.__getTemplate()) + } else { + custom_template.addClass('ovk-msg-all') + custom_template.attr('data-id', this.id) + u('body').addClass('dimmed').append(custom_template) + } + u('html').attr('style', 'overflow-y:hidden') buttons.forEach((text, callback) => { @@ -40,7 +48,7 @@ class CMessageBox { __getTemplate() { return u( - `
+ `
${this.title}
${this.body}
@@ -50,7 +58,7 @@ class CMessageBox { } getNode() { - return u(`.ovk-diag-cont[data-id='${this.id}']`) + return u(`.ovk-msg-all[data-id='${this.id}']`) } async __showCloseConfirmationDialog() { @@ -73,8 +81,8 @@ class CMessageBox { } __exitDialog() { - u(`.ovk-diag-cont[data-id='${this.id}']`).remove() - if(u('.ovk-diag-cont').length < 1) { + this.getNode().remove() + if(u('.ovk-msg-all').length < 1) { u('body').removeClass('dimmed') u('html').attr('style', 'overflow-y:scroll') } diff --git a/Web/static/js/openvk.cls.js b/Web/static/js/openvk.cls.js index 75036fae..8b5bee57 100644 --- a/Web/static/js/openvk.cls.js +++ b/Web/static/js/openvk.cls.js @@ -48,7 +48,7 @@ function parseAjaxResponse(responseString) { document.addEventListener("DOMContentLoaded", function() { //BEGIN - $(document).on("click", "#_photoDelete", function(e) { + $(document).on("click", "#_photoDelete, #_videoDelete", function(e) { var formHtml = "
"; formHtml += ""; formHtml += "";