FloatingPhotoViewer: Refactor, and make it better

- Now you can actually check the comments under EVERY photo
- Fix for textarea. Now you can publish comments
This commit is contained in:
veselcraft 2023-01-20 02:46:17 +03:00
parent 831a41754d
commit a3843e8417
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
4 changed files with 39 additions and 22 deletions

View file

@ -28,7 +28,7 @@
<div style="width: 100%; min-height: 100px;" class="ovk-photo-details"> <div style="width: 100%; min-height: 100px;" class="ovk-photo-details">
<div style="float: left; min-height: 100px; width: 70%;"> <div style="float: left; min-height: 100px; width: 70%;">
{include "../components/comments.xml", comments => $comments, count => $cCount, page => $cPage, model => "photos", parent => $photo} {include "../components/comments.xml", comments => $comments, count => $cCount, page => $cPage, model => "photos", parent => $photo, custom_id => 999}
</div> </div>
<div style="float: left; min-height: 100px; width: 30%;"> <div style="float: left; min-height: 100px; width: 30%;">
<div> <div>

View file

@ -4,7 +4,7 @@
{var $commentsURL = "/al_comments/create/$model/" . $parent->getId()} {var $commentsURL = "/al_comments/create/$model/" . $parent->getId()}
{var $club = $parent instanceof \openvk\Web\Models\Entities\Post && $parent->getTargetWall() < 0 ? (new openvk\Web\Models\Repositories\Clubs)->get(abs($parent->getTargetWall())) : $club} {var $club = $parent instanceof \openvk\Web\Models\Entities\Post && $parent->getTargetWall() < 0 ? (new openvk\Web\Models\Repositories\Clubs)->get(abs($parent->getTargetWall())) : $club}
{if !$readOnly} {if !$readOnly}
{include "textArea.xml", route => $commentsURL, postOpts => false, graffiti => (bool) ovkGetQuirk("comments.allow-graffiti"), club => $club} {include "textArea.xml", route => $commentsURL, postOpts => false, graffiti => (bool) ovkGetQuirk("comments.allow-graffiti"), club => $club, custom_id => $custom_id}
{/if} {/if}
</div> </div>

View file

@ -1,5 +1,6 @@
{php if(!isset($GLOBALS["textAreaCtr"])) $GLOBALS["textAreaCtr"] = 10;} {php if(!isset($GLOBALS["textAreaCtr"])) $GLOBALS["textAreaCtr"] = 10;}
{var $textAreaId = ($post ?? NULL) === NULL ? (++$GLOBALS["textAreaCtr"]) : $post->getId()} {var $textAreaId = ($post ?? NULL) === NULL ? (++$GLOBALS["textAreaCtr"]) : $post->getId()}
{var $textAreaId = ($custom_id ?? NULL) === NULL ? $textAreaId : $custom_id}
<div id="write" style="padding: 5px 0;" onfocusin="expand_wall_textarea({$textAreaId});"> <div id="write" style="padding: 5px 0;" onfocusin="expand_wall_textarea({$textAreaId});">
<form action="{$route}" method="post" enctype="multipart/form-data" style="margin:0;"> <form action="{$route}" method="post" enctype="multipart/form-data" style="margin:0;">

View file

@ -173,6 +173,8 @@ function OpenMiniature(e, photo, post, photo_id) {
let imagesCount = 0; let imagesCount = 0;
let imagesIndex = 0; let imagesIndex = 0;
let tempDetailsSection = [];
let dialog = u( let dialog = u(
`<div class="ovk-photo-view-dimmer"> `<div class="ovk-photo-view-dimmer">
@ -208,6 +210,36 @@ function OpenMiniature(e, photo, post, photo_id) {
__closeDialog(); __closeDialog();
}); });
function __reloadTitleBar() {
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount;
}
function __loadDetails(photo_id, index) {
if(tempDetailsSection[index] == null) {
u(".ovk-photo-details").last().innerHTML = '<img src="/assets/packages/static/openvk/img/loading_mini.gif">';
ky("/photo" + photo_id, {
hooks: {
afterResponse: [
async (_request, _options, response) => {
let parser = new DOMParser();
let body = parser.parseFromString(await response.text(), "text/html");
let element = u(body.getElementsByClassName("ovk-photo-details")).last();
tempDetailsSection[index] = element.innerHTML;
if(index == imagesIndex) {
u(".ovk-photo-details").last().innerHTML = element.innerHTML;
}
}
]
}
});
} else {
u(".ovk-photo-details").last().innerHTML = tempDetailsSection[index];
}
}
function __slidePhoto(direction) { function __slidePhoto(direction) {
/* direction = 1 - right /* direction = 1 - right
direction = 0 - left */ direction = 0 - left */
@ -227,7 +259,8 @@ function OpenMiniature(e, photo, post, photo_id) {
let photoURL = json.body[imagesIndex - 1].url; let photoURL = json.body[imagesIndex - 1].url;
u("#ovk-photo-img").last().src = photoURL; u("#ovk-photo-img").last().src = photoURL;
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount; __reloadTitleBar();
__loadDetails(json.body[imagesIndex - 1].id, imagesIndex);
} }
} }
@ -262,25 +295,8 @@ function OpenMiniature(e, photo, post, photo_id) {
} }
}); });
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount; __reloadTitleBar();
} __loadDetails(json.body[imagesIndex - 1].id, imagesIndex); }
]
}
});
ky("/photo" + photo_id, {
hooks: {
afterResponse: [
async (_request, _options, response) => {
let parser = new DOMParser();
let body = parser.parseFromString(await response.text(), "text/html");
let element = u(body.getElementsByClassName("ovk-photo-details")).last();
u(".ovk-photo-details").last().innerHTML = element.innerHTML;
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount;
}
] ]
} }
}); });