function initGraffiti(event) { let canvas = null; const msgbox = new CMessageBox({ title: tr("draw_graffiti"), body: "
", close_on_buttons: false, warn_on_exit: true, buttons: [tr("save"), tr("cancel")], callbacks: [function() { 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()}); __uploadToTextarea(image, u(event.target).closest('#write')) }, "image/jpeg", 0.92); canvas.teardown(); msgbox.close() }, async function() { const res = await msgbox.__showCloseConfirmationDialog() if(res === true) { canvas.teardown() msgbox.close() } }] }) let watermarkImage = new Image(); watermarkImage.src = "/assets/packages/static/openvk/img/logo_watermark.gif"; msgbox.getNode().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 } }); } u(document).on('click', '.menu_toggler', (e) => { const post_buttons = $(e.target).closest('.post-buttons') const wall_attachment_menu = post_buttons.find('#wallAttachmentMenu') if(wall_attachment_menu.is('.hidden')) { wall_attachment_menu.css({ opacity: 0 }); wall_attachment_menu.toggleClass('hidden').fadeTo(250, 1); } else { wall_attachment_menu.fadeTo(250, 0, function () { $(this).toggleClass('hidden'); }); } }) u(document).on("click", ".post-like-button", function(e) { e.preventDefault(); e.stopPropagation() var thisBtn = u(this).first(); var link = u(this).attr("href"); var heart = u(".heart", thisBtn); var counter = u(".likeCnt", thisBtn); var likes = counter.text() === "" ? 0 : counter.text(); var isLiked = heart.attr("id") === 'liked'; ky.post(link) heart.attr("id", isLiked ? '' : 'liked'); counter.text(parseInt(likes) + (isLiked ? -1 : 1)); if (counter.text() === "0") { counter.text(""); } return false; }); u(document).on("input", "textarea", function(e) { var boost = 5; var textArea = e.target; textArea.style.height = "5px"; var newHeight = textArea.scrollHeight; textArea.style.height = newHeight + boost + "px"; return; // revert to original size if it is larger (possibly changed by user) // textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px"; }); async function OpenMiniature(e, photo, post, photo_id, type = "post") { /* костыли но смешные однако */ e.preventDefault(); // Значения для переключения фоток 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 currentImageid = '0_0'; const photo_viewer = new CMessageBox({ title: '', custom_template: u(` `) }) photo_viewer.getNode().find("#ovk-photo-close").on("click", function(e) { photo_viewer.close() }); function __getIndex(photo_id = null) { return Object.keys(json.body).findIndex(item => item == (photo_id ?? currentImageid)) + 1 } function __getByIndex(id) { const ids = Object.keys(json.body) const _id = ids[id - 1] return json.body[_id] } function __reloadTitleBar() { photo_viewer.getNode().find("#photo_com_title_photos").last().innerHTML = imagesCount > 1 ? tr("photo_x_from_y", shown_offset, imagesCount) : tr("photo"); } 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 ? details.innerHTML : '' if(photo_id == currentImageid) { photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = details ? details.innerHTML : '' } photo_viewer.getNode().find(".ovk-photo-details .bsdn").nodes.forEach(bsdnInitElement) } else { photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = json.body[photo_id].cached } } async function __slidePhoto(direction) { /* direction = 1 - right direction = 0 - left */ if(json == undefined) { console.log("Да подожди ты. Куда торопишься?"); } else { 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) { shown_offset += 1 current_index += 1 } else if(direction == 0) { shown_offset -= 1 current_index -= 1 } 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; photo_viewer.getNode().find("#ovk-photo-img").last().src = '' photo_viewer.getNode().find("#ovk-photo-img").last().src = photoURL; __reloadTitleBar(); __loadDetails(json.body[currentImageid].id); } } async function __loadContext(type, id, ref = false, inverse = false) { if(type == 'post' || type == 'comment') { const form_data = new FormData() form_data.append('parentType', type); 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 } 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() } async function OpenVideo(video_arr = [], init_player = true) { CMessageBox.toggleLoader() const video_owner = video_arr[0] const video_id = video_arr[1] let video_api = null try { video_api = await window.OVKAPI.call('video.get', {'videos': `${video_owner}_${video_id}`, 'extended': 1}) if(!video_api.items || !video_api.items[0]) { throw new Error('Not found') } } catch(e) { CMessageBox.toggleLoader() fastError(e.message) return } // TODO: video lists const video_object = video_api.items[0] const pretty_id = `${video_object.owner_id}_${video_object.id}` const author = find_author(video_object.owner_id, video_api.profiles, video_api.groups) let player_html = '' if(init_player) { if(video_object.platform == 'youtube') { const video_url = new URL(video_object.player) const video_id = video_url.pathname.replace('/', '') player_html = ` ` } else { if(!video_object.is_processed) { player_html = `${tr('video_processing')}` } else { const author_name = `${author.first_name} ${author.last_name}` player_html = `
${tr("learn_more")} |
|
|
${ovk_proc_strtr(escapeHtml(video.title), 50)}
${ovk_proc_strtr(escapeHtml(video.description ?? ""), 140)} ${ovk_proc_strtr(escapeHtml(author_name ?? ""), 100)} |
${!is_attached ? tr("attach") : tr("detach")} |
${tr('info_name')}: | |
${tr('description')}: | |
${tr('video')}: |
${tr('info_name')}: | |
${tr('description')}: | |
${tr('video_link_to_yt')}: |
${isGroup == true ? tr('groups_avatar') : tr('friends_avatar')}
${tr('formats_avatar')}
${tr('troubles_avatar')}
${tr('webcam_avatar')}
${tr("selected_area_rotate")}