Skip to content

Commit

Permalink
restore search functionality + some bugfixes
Browse files Browse the repository at this point in the history
(still unusable)
  • Loading branch information
mrilyew committed Oct 26, 2024
1 parent 53d735c commit 190e0ac
Show file tree
Hide file tree
Showing 28 changed files with 768 additions and 430 deletions.
Binary file added res/arrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/menu_icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions res/mobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
$(document).on('click', '.show_more_info_profile_link', (e) => {
$('.show_more_info_profile_content').toggleClass('active')
$('.show_more_info_profile_link').html([tr('mobile_user_info_show_details'), tr('mobile_user_info_hide')][Number($('.show_more_info_profile_content').hasClass('active'))])
})

u(document).on("click", ".post-like-button-natural", function(e) {
e.preventDefault();

const thisBtn = u(e.target).closest('a');
const link = thisBtn.attr("href");
const heart = thisBtn.find('.like');
const counter = thisBtn.find('.likeCnt');
const likes = counter.text() === "" ? 0 : counter.text();
const isLiked = Number(thisBtn.attr("data-liked")) == 1;

fetch(link, {
method: 'POST'
})

thisBtn.attr("data-liked", isLiked ? '1' : '0')

if(!isLiked) {
heart.attr("id", 'liked');
} else {
heart.attr("id", '');
}

counter.text(parseInt(likes) + (isLiked ? -1 : 1));
if (counter.text() === "0") {
counter.text("");
}

return false;
})

u(document).on('click', '#search_options_toggler', (e) => {
u('.search_options').toggleClass('hidden')
u('#search_options_toggler_arrow').toggleClass('shown')
})

u(document).on('click', '#__mobile_reset_search', (e) => {
u('.main .header_search_inputbt .sr_input').nodes[0].value = ''
u(`.page_search_options input[type='text']`).nodes.forEach(inp => {
inp.value = ''
})

u(`.page_search_options input[type='checkbox']`).nodes.forEach(chk => {
chk.checked = false
})

u(`.page_search_options input[type='radio']`).nodes.forEach(rad => {
if(rad.dataset.default) {
rad.checked = true
return
}

rad.checked = false
})

u(`.page_search_options select`).nodes.forEach(sel => {
sel.value = sel.dataset.default
})
})

function escapeHtml(text) {
var map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};

return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}

// maybe сделать скрипт с подобными функциями чтобы не приходилось копипастить?
function highlightText(searchText, container_selector, selectors = []) {
const container = u(container_selector)
const regexp = new RegExp(`(${searchText})`, 'gi')

function highlightNode(node) {
if(node.nodeType == 3) {
let newNode = escapeHtml(node.nodeValue)
newNode = newNode.replace(regexp, (match, ...args) => {
return `<span class='highlight'>${escapeHtml(match)}</span>`
})

const tempDiv = document.createElement('div')
tempDiv.innerHTML = newNode

while(tempDiv.firstChild) {
node.parentNode.insertBefore(tempDiv.firstChild, node)
}
node.parentNode.removeChild(node)
} else if(node.nodeType === 1 && node.tagName !== 'SCRIPT' && node.tagName !== 'BR' && node.tagName !== 'STYLE') {
Array.from(node.childNodes).forEach(highlightNode);
}
}

selectors.forEach(selector => {
elements = container.find(selector)
if(!elements || elements.length < 1) return;

elements.nodes.forEach(highlightNode)
})
}
42 changes: 37 additions & 5 deletions res/mobile_audios.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function initPlayer(id, keys, url, length) {
}
};

player.querySelector(".tracks").style.display = "flex"

const dashPlayer = dashjs.MediaPlayer().create();
dashPlayer.initialize(audio, url, false);
dashPlayer.setProtectionData(protData);

playButton.addEventListener("click", (event) => {
if(audio.paused) {
u('.tracks').attr('style', 'display:none;')
player.querySelector(".tracks").style.display = "flex"
document.querySelectorAll('audio').forEach(el => el.pause());
audio.play()
} else {
Expand Down Expand Up @@ -84,7 +84,7 @@ function initPlayer(id, keys, url, length) {
nextPlayer = player.nextElementSibling
}

if(!nextPlayer) return
if(!nextPlayer || nextPlayer.classList.contains('withdrawn')) return

initPlayer(nextPlayer.dataset.id,
JSON.parse(nextPlayer.dataset.keys),
Expand Down Expand Up @@ -122,7 +122,7 @@ function initPlayer(id, keys, url, length) {
player.querySelector(".lengthTrack .usedPart").style.width = `${ ps}%`;
})
} catch(e) {
console.log("Что-то ёбнулось")
console.log("Что-то сломалось.")
}

// тяжело без jquery
Expand Down Expand Up @@ -195,4 +195,36 @@ $(document).on("click", "#bookmarkPlaylist, #unbookmarkPlaylist", (e) => {
fastError(response.flash.message)
}
})
})
})

u(document).on('click', '.litePlayer .add-icon, .litePlayer .del-icon', (e) => {
const target = u(e.target)
const act = target.hasClass('add-icon') ? 'add' : 'remove'
const id = Number(target.attr('data-id'))
$.ajax({
type: 'POST',
url: `/audio${id}/action?act=${act}`,
data: {
hash: u("meta[name=csrf]").attr("value"),
},
beforeSend: () => {
target.addClass('lagged')
},
success: (response) => {
target.removeClass('lagged')
if(response.success) {
if(act == 'add') {
target.addClass('del-icon')
target.removeClass('add-icon')
} else {
target.removeClass('del-icon')
target.addClass('add-icon')
}

return
}

console.error(response)
}
})
})
90 changes: 0 additions & 90 deletions res/podrobnee.js

This file was deleted.

Loading

0 comments on commit 190e0ac

Please sign in to comment.