mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Save audios list in da localstorage and fix msgbox
This commit is contained in:
parent
db5296eab7
commit
9a81e354ea
5 changed files with 83 additions and 10 deletions
|
@ -912,7 +912,7 @@
|
||||||
width: 500px;
|
width: 500px;
|
||||||
height: 37px;
|
height: 37px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 99;
|
z-index: 1025;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ window.player = new class {
|
||||||
u(this.audioPlayer).trigger('volumechange')
|
u(this.audioPlayer).trigger('volumechange')
|
||||||
}
|
}
|
||||||
|
|
||||||
async setTrack(id) {
|
async setTrack(id, ref = null) {
|
||||||
if(!this.tracks || this.tracks.length < 1) {
|
if(!this.tracks || this.tracks.length < 1) {
|
||||||
makeError('Context is not loaded yet', 'Red', 5000, 1489)
|
makeError('Context is not loaded yet', 'Red', 5000, 1489)
|
||||||
return
|
return
|
||||||
|
@ -313,6 +313,10 @@ window.player = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.is_closed = false
|
this.is_closed = false
|
||||||
|
if(ref != 'localstorage') {
|
||||||
|
this.dump()
|
||||||
|
}
|
||||||
|
|
||||||
this.__updateFace()
|
this.__updateFace()
|
||||||
u(this.audioPlayer).trigger('volumechange')
|
u(this.audioPlayer).trigger('volumechange')
|
||||||
}
|
}
|
||||||
|
@ -405,6 +409,35 @@ window.player = new class {
|
||||||
return u('.bigPlayer').length > 0
|
return u('.bigPlayer').length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump() {
|
||||||
|
const final = {
|
||||||
|
context: this.context,
|
||||||
|
current_track_id: this.current_track_id,
|
||||||
|
tracks: this.tracks,
|
||||||
|
time: this.audioPlayer.currentTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem('audio.lastDump', JSON.stringify(final))
|
||||||
|
console.log('Audio | Tracks was dumped')
|
||||||
|
}
|
||||||
|
|
||||||
|
undump() {
|
||||||
|
localStorage.setItem('audio.lastDump', null)
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadDump(dump_object) {
|
||||||
|
this.context = dump_object.context
|
||||||
|
this.current_track_id = dump_object.current_track_id
|
||||||
|
this.tracks = dump_object.tracks
|
||||||
|
if(this.current_track_id) {
|
||||||
|
await this.setTrack(this.current_track_id, 'localstorage')
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dump_object.time) {
|
||||||
|
this.audioPlayer.currentTime = dump_object.time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Добавляем ощущение продуманности.
|
// Добавляем ощущение продуманности.
|
||||||
__highlightActiveTrack() {
|
__highlightActiveTrack() {
|
||||||
u(`.audiosContainer .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry, .audios_padding .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry`).addClass('nowPlaying')
|
u(`.audiosContainer .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry, .audios_padding .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry`).addClass('nowPlaying')
|
||||||
|
@ -432,7 +465,6 @@ window.player = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handlePageTransition() {
|
async _handlePageTransition() {
|
||||||
console.log('Audio | Switched page :3')
|
|
||||||
const state = this.isAtAudiosPage()
|
const state = this.isAtAudiosPage()
|
||||||
if(!state) {
|
if(!state) {
|
||||||
// AJAX audio player
|
// AJAX audio player
|
||||||
|
@ -721,7 +753,22 @@ window.player = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
await window.player.init(window.__current_page_audio_context)
|
let parsed = null
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(localStorage.getItem('audio.lastDump'))
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
|
if(parsed) {
|
||||||
|
await window.player.init(null)
|
||||||
|
await window.player.loadDump(parsed)
|
||||||
|
if(!window.player.isAtAudiosPage()) {
|
||||||
|
window.player.ajReveal()
|
||||||
|
window.player.__updateFace()
|
||||||
|
u(window.player.audioPlayer).trigger('timeupdate')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await window.player.init(window.__current_page_audio_context)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
u(document).on('click', '.audioEntry .playerButton > .playIcon', async (e) => {
|
u(document).on('click', '.audioEntry .playerButton > .playIcon', async (e) => {
|
||||||
|
@ -1190,8 +1237,10 @@ u(document).on('contextmenu', '.bigPlayer, .audioEmbed, #ajax_audio_player', (e)
|
||||||
ctx_u.find('#audio_ctx_clear_context').on('click', (ev) => {
|
ctx_u.find('#audio_ctx_clear_context').on('click', (ev) => {
|
||||||
const old_url = window.player.context.object.url
|
const old_url = window.player.context.object.url
|
||||||
window.player.pause()
|
window.player.pause()
|
||||||
|
window.player.ajClose()
|
||||||
window.player.__resetContext()
|
window.player.__resetContext()
|
||||||
window.player.__updateFace()
|
window.player.__updateFace()
|
||||||
|
window.player.undump()
|
||||||
window.router.route(old_url)
|
window.router.route(old_url)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -424,7 +424,7 @@ async function OpenVideo(video_arr = [], init_player = true)
|
||||||
|
|
||||||
u('body').append(miniplayer)
|
u('body').append(miniplayer)
|
||||||
miniplayer.find('.miniplayer-body').nodes[0].append(msgbox.getNode().find('.center-part > *').nodes[0])
|
miniplayer.find('.miniplayer-body').nodes[0].append(msgbox.getNode().find('.center-part > *').nodes[0])
|
||||||
miniplayer.attr('style', `left:100px;top:${scrollY}px;`)
|
miniplayer.attr('style', `left:100px;top:0px;`)
|
||||||
miniplayer.find('#__miniplayer_return').on('click', (e) => {
|
miniplayer.find('#__miniplayer_return').on('click', (e) => {
|
||||||
msgbox.reveal()
|
msgbox.reveal()
|
||||||
msgbox.getNode().find('.center-part').nodes[0].append(miniplayer.find('.miniplayer-body > *').nodes[0])
|
msgbox.getNode().find('.center-part').nodes[0].append(miniplayer.find('.miniplayer-body > *').nodes[0])
|
||||||
|
@ -2218,7 +2218,6 @@ $(document).on("click", "#add_image", (e) => {
|
||||||
let video = document.querySelector("#_takeSelfieFrame video")
|
let video = document.querySelector("#_takeSelfieFrame video")
|
||||||
|
|
||||||
if(!navigator.mediaDevices) {
|
if(!navigator.mediaDevices) {
|
||||||
// ех вот бы месседжбоксы были бы классами
|
|
||||||
u("body").removeClass("dimmed");
|
u("body").removeClass("dimmed");
|
||||||
document.querySelector("html").style.overflowY = "scroll"
|
document.querySelector("html").style.overflowY = "scroll"
|
||||||
u(".ovk-diag-cont").remove();
|
u(".ovk-diag-cont").remove();
|
||||||
|
@ -2365,6 +2364,10 @@ async function __processPaginatorNextPage(page)
|
||||||
window.player.loadContext(page)
|
window.player.loadContext(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if(window.router) {
|
||||||
|
window.router.savePreviousPage()
|
||||||
|
}*/
|
||||||
|
|
||||||
const new_url = new URL(location.href)
|
const new_url = new URL(location.href)
|
||||||
new_url.hash = page
|
new_url.hash = page
|
||||||
history.replaceState(null, null, new_url)
|
history.replaceState(null, null, new_url)
|
||||||
|
|
|
@ -82,7 +82,7 @@ class CMessageBox {
|
||||||
|
|
||||||
__exitDialog() {
|
__exitDialog() {
|
||||||
this.getNode().remove()
|
this.getNode().remove()
|
||||||
if(u('.ovk-msg-all').length < 1) {
|
if(u('.ovk-msg-all:not(.msgbox-hidden)').length < 1) {
|
||||||
u('body').removeClass('dimmed')
|
u('body').removeClass('dimmed')
|
||||||
u('html').attr('style', 'overflow-y:scroll')
|
u('html').attr('style', 'overflow-y:scroll')
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class CMessageBox {
|
||||||
hide() {
|
hide() {
|
||||||
u('body').removeClass('dimmed')
|
u('body').removeClass('dimmed')
|
||||||
u('html').attr('style', 'overflow-y:scroll')
|
u('html').attr('style', 'overflow-y:scroll')
|
||||||
this.getNode().attr('style', 'display: none;')
|
this.getNode().attr('style', 'display: none;').addClass('msgbox-hidden')
|
||||||
this.hidden = true
|
this.hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,8 @@ window.router = new class {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async __integratePage() {
|
async __integratePage(scrolling = null) {
|
||||||
window.scrollTo(0, 0)
|
window.scrollTo(0, scrolling ?? 0)
|
||||||
bsdnHydrate()
|
bsdnHydrate()
|
||||||
|
|
||||||
if(u('.paginator:not(.paginator-at-top)').length > 0) {
|
if(u('.paginator:not(.paginator-at-top)').length > 0) {
|
||||||
|
@ -120,6 +120,7 @@ window.router = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.player) {
|
if(window.player) {
|
||||||
|
window.player.dump()
|
||||||
await window.player._handlePageTransition()
|
await window.player._handlePageTransition()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +159,14 @@ window.router = new class {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
savePreviousPage() {
|
||||||
|
this.prev_page_html = {
|
||||||
|
url: location.href,
|
||||||
|
pathname: location.pathname,
|
||||||
|
html: u('.page_body').html(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async route(params = {}) {
|
async route(params = {}) {
|
||||||
if(typeof params == 'string') {
|
if(typeof params == 'string') {
|
||||||
params = {
|
params = {
|
||||||
|
@ -176,6 +185,10 @@ window.router = new class {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.prev_page_html && this.prev_page_html.pathname != location.pathname) {
|
||||||
|
this.prev_page_html = null
|
||||||
|
}
|
||||||
|
|
||||||
const push_url = params.push_state ?? true
|
const push_url = params.push_state ?? true
|
||||||
const next_page_url = new URL(url)
|
const next_page_url = new URL(url)
|
||||||
if(push_url) {
|
if(push_url) {
|
||||||
|
@ -342,6 +355,14 @@ u(document).on('submit', 'form', async (e) => {
|
||||||
|
|
||||||
window.addEventListener('popstate', (e) => {
|
window.addEventListener('popstate', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
/*if(window.router.prev_page_html) {
|
||||||
|
u('.page_body').html(window.router.prev_page_html.html)
|
||||||
|
history.replaceState({'from_router': 1}, '', window.router.prev_page_html.url)
|
||||||
|
window.router.prev_page_html = null
|
||||||
|
window.router.__integratePage()
|
||||||
|
return
|
||||||
|
}*/
|
||||||
|
|
||||||
window.router.route({
|
window.router.route({
|
||||||
url: location.href,
|
url: location.href,
|
||||||
push_state: false,
|
push_state: false,
|
||||||
|
|
Loading…
Reference in a new issue