2020-06-07 19:04:43 +03:00
|
|
|
|
function humanFileSize(bytes, si) {
|
|
|
|
|
var thresh = si ? 1000 : 1024;
|
|
|
|
|
if(Math.abs(bytes) < thresh) {
|
|
|
|
|
return bytes + ' B';
|
|
|
|
|
}
|
|
|
|
|
var units = si
|
|
|
|
|
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
|
|
|
|
|
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
|
|
|
|
|
var u = -1;
|
|
|
|
|
do {
|
|
|
|
|
bytes /= thresh;
|
|
|
|
|
++u;
|
|
|
|
|
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
|
|
|
|
|
return bytes.toFixed(1)+' '+units[u];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function trim(string) {
|
|
|
|
|
var newStr = string.substring(0, 10);
|
|
|
|
|
if(newStr.length !== string.length)
|
|
|
|
|
newStr += "…";
|
|
|
|
|
|
|
|
|
|
return newStr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 21:15:13 +03:00
|
|
|
|
function handleVideoTAreaUpdate(event, id) {
|
|
|
|
|
console.log(event, id);
|
|
|
|
|
let indicator = u("#post-buttons" + id + " .post-upload");
|
|
|
|
|
let file = event.target.files[0];
|
|
|
|
|
if(typeof file === "undefined") {
|
|
|
|
|
indicator.attr("style", "display: none;");
|
|
|
|
|
} else {
|
|
|
|
|
u("span", indicator.nodes[0]).text("Видеолента: " + trim(file.name) + " (" + humanFileSize(file.size, false) + ")");
|
|
|
|
|
indicator.attr("style", "display: block;");
|
|
|
|
|
}
|
2022-01-10 00:02:19 +03:00
|
|
|
|
|
|
|
|
|
document.querySelector("#post-buttons" + id + " #wallAttachmentMenu").classList.add("hidden");
|
2020-06-07 19:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 15:01:48 +03:00
|
|
|
|
function initGraffiti(id) {
|
2021-10-13 20:50:16 +03:00
|
|
|
|
let canvas = null;
|
2021-12-13 19:22:04 +03:00
|
|
|
|
let msgbox = MessageBox(tr("draw_graffiti"), "<div id='ovkDraw'></div>", [tr("save"), tr("cancel")], [function() {
|
2021-10-13 20:50:16 +03:00
|
|
|
|
canvas.getImage({includeWatermark: false}).toBlob(blob => {
|
|
|
|
|
let fName = "Graffiti-" + Math.ceil(performance.now()).toString() + ".jpeg";
|
|
|
|
|
let image = new File([blob], fName, {type: "image/jpeg", lastModified: new Date().getTime()});
|
|
|
|
|
let trans = new DataTransfer();
|
|
|
|
|
trans.items.add(image);
|
|
|
|
|
|
2021-12-02 15:01:48 +03:00
|
|
|
|
let fileSelect = document.querySelector("#post-buttons" + id + " input[name='_pic_attachment']");
|
2021-10-13 20:50:16 +03:00
|
|
|
|
fileSelect.files = trans.files;
|
|
|
|
|
|
|
|
|
|
u(fileSelect).trigger("change");
|
2021-12-02 15:01:48 +03:00
|
|
|
|
u("#post-buttons" + id + " #write textarea").trigger("focusin");
|
2021-10-13 20:50:16 +03:00
|
|
|
|
}, "image/jpeg", 0.92);
|
|
|
|
|
|
|
|
|
|
canvas.teardown();
|
|
|
|
|
}, function() {
|
|
|
|
|
canvas.teardown();
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
let watermarkImage = new Image();
|
|
|
|
|
watermarkImage.src = "/assets/packages/static/openvk/img/logo_watermark.gif";
|
|
|
|
|
|
|
|
|
|
msgbox.attr("style", "width: 750px;");
|
|
|
|
|
canvas = LC.init(document.querySelector("#ovkDraw"), {
|
|
|
|
|
backgroundColor: "#fff",
|
|
|
|
|
imageURLPrefix: "/assets/packages/static/openvk/js/node_modules/literallycanvas/lib/img",
|
|
|
|
|
watermarkImage: watermarkImage,
|
|
|
|
|
imageSize: {
|
|
|
|
|
width: 640,
|
|
|
|
|
height: 480
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
|
u(".post-like-button").on("click", function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var thisBtn = u(this).first();
|
|
|
|
|
var link = u(this).attr("href");
|
|
|
|
|
var heart = u(".heart", thisBtn);
|
|
|
|
|
var counter = u(".likeCnt", thisBtn);
|
2021-11-27 16:31:00 +03:00
|
|
|
|
var likes = counter.text() === "" ? 0 : counter.text();
|
|
|
|
|
var isLiked = heart.attr("id") === 'liked';
|
2020-06-07 19:04:43 +03:00
|
|
|
|
|
|
|
|
|
ky(link);
|
2021-11-27 16:31:00 +03:00
|
|
|
|
heart.attr("id", isLiked ? '' : 'liked');
|
2020-06-07 19:04:43 +03:00
|
|
|
|
counter.text(parseInt(likes) + (isLiked ? -1 : 1));
|
2021-11-27 16:31:00 +03:00
|
|
|
|
if (counter.text() === "0") {
|
|
|
|
|
counter.text("");
|
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-09 02:58:37 +03:00
|
|
|
|
let picCount = 0;
|
|
|
|
|
|
2021-12-02 15:37:16 +03:00
|
|
|
|
function setupWallPostInputHandlers(id) {
|
2022-12-09 02:58:37 +03:00
|
|
|
|
/* u("#wall-post-input" + id).on("paste", function(e) {
|
2021-12-02 15:37:16 +03:00
|
|
|
|
if(e.clipboardData.files.length === 1) {
|
|
|
|
|
var input = u("#post-buttons" + id + " input[name=_pic_attachment]").nodes[0];
|
|
|
|
|
input.files = e.clipboardData.files;
|
|
|
|
|
|
|
|
|
|
u(input).trigger("change");
|
|
|
|
|
}
|
2022-12-09 02:58:37 +03:00
|
|
|
|
}); */
|
2020-06-07 19:04:43 +03:00
|
|
|
|
|
2021-12-02 15:37:16 +03:00
|
|
|
|
u("#wall-post-input" + id).on("input", function(e) {
|
|
|
|
|
var boost = 5;
|
|
|
|
|
var textArea = e.target;
|
|
|
|
|
textArea.style.height = "5px";
|
|
|
|
|
var newHeight = textArea.scrollHeight;
|
2022-01-30 15:12:57 +03:00
|
|
|
|
textArea.style.height = newHeight + boost + "px";
|
2021-12-02 15:37:16 +03:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// revert to original size if it is larger (possibly changed by user)
|
|
|
|
|
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
|
|
|
|
|
});
|
2022-12-09 02:58:37 +03:00
|
|
|
|
|
|
|
|
|
u(`#wall-post-input${id}`).on("paste", function(e) {
|
|
|
|
|
for (let i = 0; i < e.clipboardData.files.length; i++) {
|
|
|
|
|
console.log(e.clipboardData.files[i]);
|
|
|
|
|
if(e.clipboardData.files[i].type.match('^image/')) {
|
|
|
|
|
let blobURL = URL.createObjectURL(e.clipboardData.files[i]);
|
|
|
|
|
addPhotoMedia(e.clipboardData.files, blobURL, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
u(`#post-buttons${id} input[name=_pic_attachment]`).on("change", function(e) {
|
|
|
|
|
let blobURL = URL.createObjectURL(e.target.files[0]);
|
|
|
|
|
addPhotoMedia(e.target.files, blobURL, id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function addPhotoMedia(files, preview, id) {
|
|
|
|
|
if(getMediaCount() >= 10) {
|
|
|
|
|
alert('Не больше 10 пикч');
|
|
|
|
|
} else {
|
|
|
|
|
picCount++;
|
|
|
|
|
u(`#post-buttons${id} .upload`).append(u(`
|
|
|
|
|
<div class="upload-item" id="aP${picCount}">
|
|
|
|
|
<a href="javascript:removePicture(${picCount})" class="upload-delete">×</a>
|
|
|
|
|
<img src="${preview}">
|
|
|
|
|
</div>
|
|
|
|
|
`));
|
|
|
|
|
u(`div#aP${picCount}`).nodes[0].append(u(`<input type="file" accept="image/*" name="attachPic${picCount}" id="attachPic${picCount}" style="display: none;">`).first());
|
|
|
|
|
let input = u(`#attachPic${picCount}`).nodes[0];
|
|
|
|
|
input.files = files; // нужен рефактор, но щас не
|
|
|
|
|
console.log(input);
|
|
|
|
|
u(input).trigger("change");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMediaCount() {
|
|
|
|
|
return u(`#post-buttons${id} .upload`).nodes[0].children.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removePicture(idA) {
|
|
|
|
|
u(`div#aP${idA}`).nodes[0].remove();
|
2021-12-02 15:37:16 +03:00
|
|
|
|
}
|
2022-04-17 21:36:34 +03:00
|
|
|
|
|
2022-12-15 03:40:25 +03:00
|
|
|
|
function OpenMiniature(e, photo, post, photo_id) {
|
2022-12-14 03:14:34 +03:00
|
|
|
|
/*
|
2022-12-15 03:40:25 +03:00
|
|
|
|
костыли но смешные однако
|
2022-12-14 03:14:34 +03:00
|
|
|
|
*/
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
if(u(".ovk-photo-view").length > 0) return false;
|
2022-12-15 03:40:25 +03:00
|
|
|
|
|
|
|
|
|
// Значения для переключения фоток
|
|
|
|
|
|
|
|
|
|
let json;
|
|
|
|
|
|
|
|
|
|
let imagesCount = 0;
|
|
|
|
|
let imagesIndex = 0;
|
2022-12-14 03:14:34 +03:00
|
|
|
|
|
|
|
|
|
let dialog = u(
|
|
|
|
|
`<div class="ovk-photo-view-dimmer">
|
|
|
|
|
<div class="ovk-photo-view">
|
|
|
|
|
<div class="photo_com_title">
|
2022-12-15 03:40:25 +03:00
|
|
|
|
<text id="photo_com_title_photos">
|
|
|
|
|
<img src="/assets/packages/static/openvk/img/loading_mini.gif">
|
|
|
|
|
</text>
|
2022-12-14 03:14:34 +03:00
|
|
|
|
<div>
|
|
|
|
|
<a id="ovk-photo-close">Закрыть</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<center style="margin-bottom: 8pt;">
|
2022-12-15 03:40:25 +03:00
|
|
|
|
<div class="ovk-photo-slide-left"></div>
|
|
|
|
|
<div class="ovk-photo-slide-right"></div>
|
2022-12-15 16:40:00 +03:00
|
|
|
|
<img src="${photo}" style="max-width: 100%; max-height: 60vh;" id="ovk-photo-img">
|
2022-12-14 03:14:34 +03:00
|
|
|
|
</center>
|
2022-12-15 16:40:00 +03:00
|
|
|
|
<div class="ovk-photo-details">
|
|
|
|
|
<img src="/assets/packages/static/openvk/img/loading_mini.gif">
|
|
|
|
|
</div>
|
2022-12-14 03:14:34 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>`);
|
|
|
|
|
u("body").addClass("dimmed").append(dialog);
|
|
|
|
|
|
|
|
|
|
let button = u("#ovk-photo-close");
|
|
|
|
|
|
|
|
|
|
button.on("click", function(e) {
|
|
|
|
|
let __closeDialog = () => {
|
|
|
|
|
u("body").removeClass("dimmed");
|
|
|
|
|
u(".ovk-photo-view-dimmer").remove();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
__closeDialog();
|
2022-12-15 03:40:25 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
} else if(direction == 1) {
|
|
|
|
|
imagesIndex++;
|
|
|
|
|
} else if(direction == 0) {
|
|
|
|
|
imagesIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let photoURL = json.body[imagesIndex - 1].url;
|
|
|
|
|
|
|
|
|
|
u("#ovk-photo-img").last().src = photoURL;
|
|
|
|
|
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ky.post("/iapi/getPhotosFromPost/" + 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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
u("#photo_com_title_photos").last().innerHTML = "Фотография " + imagesIndex + " из " + imagesCount;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-12-14 03:14:34 +03:00
|
|
|
|
|
2022-12-15 16:40:00 +03:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-14 03:14:34 +03:00
|
|
|
|
return u(".ovk-photo-view-dimmer");
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 21:36:34 +03:00
|
|
|
|
u("#write > form").on("keydown", function(event) {
|
|
|
|
|
if(event.ctrlKey && event.keyCode === 13)
|
|
|
|
|
this.submit();
|
|
|
|
|
});
|
2022-12-17 02:03:02 +03:00
|
|
|
|
|
|
|
|
|
var tooltipClientTemplate = Handlebars.compile(`
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="54" valign="top">
|
|
|
|
|
<img src="{{img}}" width="54" />
|
|
|
|
|
</td>
|
|
|
|
|
<td width="1"></td>
|
|
|
|
|
<td width="150" valign="top">
|
|
|
|
|
<text>
|
|
|
|
|
{{app_tr}}: <b>{{name}}</b>
|
|
|
|
|
</text><br/>
|
2022-12-18 09:25:52 +03:00
|
|
|
|
<a href="{{url}}">${tr("learn_more")}</a>
|
2022-12-17 02:03:02 +03:00
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
var tooltipClientNoInfoTemplate = Handlebars.compile(`
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="150" valign="top">
|
|
|
|
|
<text>
|
|
|
|
|
{{app_tr}}: <b>{{name}}</b>
|
|
|
|
|
</text><br/>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
tippy(".client_app", {
|
|
|
|
|
theme: "light vk",
|
|
|
|
|
content: "⌛",
|
|
|
|
|
allowHTML: true,
|
|
|
|
|
interactive: true,
|
|
|
|
|
interactiveDebounce: 500,
|
|
|
|
|
|
|
|
|
|
onCreate: async function(that) {
|
|
|
|
|
that._resolvedClient = null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow: async function(that) {
|
|
|
|
|
let client_tag = that.reference.dataset.appTag;
|
|
|
|
|
let client_name = that.reference.dataset.appName;
|
|
|
|
|
let client_url = that.reference.dataset.appUrl;
|
|
|
|
|
let client_img = that.reference.dataset.appImg;
|
|
|
|
|
|
|
|
|
|
if(client_name != "") {
|
|
|
|
|
let res = {
|
|
|
|
|
'name': client_name,
|
|
|
|
|
'url': client_url,
|
|
|
|
|
'img': client_img,
|
|
|
|
|
'app_tr': tr("app")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
that.setContent(tooltipClientTemplate(res));
|
|
|
|
|
} else {
|
|
|
|
|
let res = {
|
|
|
|
|
'name': client_tag,
|
|
|
|
|
'app_tr': tr("app")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
that.setContent(tooltipClientNoInfoTemplate(res));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|