diff --git a/js/script.js b/js/script.js index 88373ee6..bd5419fb 100644 --- a/js/script.js +++ b/js/script.js @@ -11,11 +11,48 @@ const ap = new APlayer({ container: document.getElementById('aplayer'), fixed: true }); +//吼吼路由 +var router = new Navigo(null, true, '#!'); +router + .on({ + 'search/:keyword': function(params) { show_search(params.keyword) }, + 'search': function() { show_search() }, + 'album/:artist/:name/:album_artist': function(params) { show_album_songs(params.artist, params.name, params.album_artist) }, + 'album': function() { show_album() }, + 'folder/:dir': function(params) { show_folder(params.dir) }, + 'folder': function() { show_folder() }, + 'artist/:artist': function(params) { show_artist(params.artist) }, + 'artist': function() { show_artist() }, + 'composer/:composer': function(params) { show_composer(params.composer) }, + 'composer': function() { show_composer() }, + 'playlist/:playlistType/:playlistID': function(params) { show_playlist_songs(params.playlistType + '/' + params.playlistID) }, + 'playlist': function() { show_playlist() }, + 'random': function() { show_random() }, + 'now': function() { show_now() }, + 'lrc': function() { show_lrc() }, + 'settings': function() { show_settings() }, + '*': function() { show_home() } + }) + .resolve() +router + .hooks({ + before: function(done, params) { + $("#player").removeClass('hide') + done() + }, + after: function(params) { + $('#drawer a').removeClass('mdui-list-item-active') + $(`#drawer a[href="${$('#content').attr('data-page')}"]`).addClass('mdui-list-item-active') + } + }) + ap.on("play", async function() { //沒歌就隨機播放 - if (ap.list.audios.length == 0) play_random(); + if (ap.list.audios.length == 0) play_random().then(() => { + router.navigate('now'); + show_now() + }) updateMediaSession() - lrc.load(`[00:00.000]`) // 歌詞清空 }) ap.on("loadedmetadata", async function() { lrc.load(`[00:00.000]歌詞讀取中`) @@ -79,48 +116,14 @@ function updateMediaSession() { } // 初始化網頁 $(function() { - // 載入首頁 - show_home() - $('#content').attr('data-page', 'home') - - $('[data-link]').click(function() { - $('[data-link]').removeClass('mdui-list-item-active') - $(this).addClass('mdui-list-item-active') - $('#content').attr('data-page', $(this).attr('data-link')) - $("#player").removeClass('hide') - }) - + $(`#drawer a[href="${$('#content').attr('data-page')}"]`).addClass('mdui-list-item-active') if ($(window).width() < 1024) { - $('[data-link]').attr("mdui-drawer", "{target: '#drawer', swipe: true}") + $('#drawer a').attr("mdui-drawer", "{target: '#drawer', swipe: true}") mdui.mutation() } - - $('[data-link="home"]').click(function() { show_home() }) - $('[data-link="search"]').click(function() { show_search() }) - $('[data-link="album"]').click(function() { show_album() }) - $('[data-link="folder"]').click(function() { show_folder() }) - $('[data-link="artist"]').click(function() { show_artist() }) - $('[data-link="composer"]').click(function() { show_composer() }) - $('[data-link="playlist"]').click(function() { show_playlist() }) - $('[data-link="random"]').click(function() { show_random() }) - $('[data-link="now"]').click(function() { show_now() }) - $('[data-link="lrc"]').click(function() { show_lrc() }) - $('[data-link="settings"]').click(function() { show_settings() }) - $('#player>*:not(.ctrl)').click(function() { - show_now() + router.navigate('now') }); - //圖片讀取錯誤 - $("img").on('error', function() { tryRelogin() }).attr('src', "/img/PokaPlayer.png"); - //返回攔截 - /* window.history.pushState(null, null, "#"); - window.addEventListener("popstate", function(e) { - //show_album() - window.history.pushState(null, null, "#"); - mdui.snackbar({ - message: "點擊返回" - }); - })*/ // 初始化 MediaSession updateMediaSession() }); @@ -160,7 +163,8 @@ function secondToTime(second) { // 首頁 async function show_home() { - // 展示讀取中 + $('#content').attr('data-page', 'home') + // 展示讀取中 var header = HTML_getHeader("PokaPlayer") $("#content").html(header + HTML_getSpinner()) mdui.mutation() @@ -168,10 +172,13 @@ async function show_home() { var data = await getAPI("entry.cgi", "SYNO.AudioStation.Pin", "list", [{ key: "limit", "value": -1 }, { key: "offset", "value": 0 }]), album = HTML_showPins(data.data.items) $("#content").html(header + album) - $("#content>:not(#header-wrapper)").animateCss("fadeIn") + $("#content>:not(#header-wrapper)") + router.updatePageLinks() } //- 搜尋 async function show_search(keyword) { + + $('#content').attr('data-page', 'search') var html = `
沒有任何播放清單
版本 ${getinfo.data.version} / 開發者 ${getinfo.data.author} / ${update}
` $("#about").html(about) @@ -1086,31 +1102,4 @@ function getSnackbarPosition() { return "left-top" else return "left-bottom" -} -// animate css -$.fn.extend({ - animateCss: function(animationName, callback) { - var animationEnd = (function(el) { - var animations = { - animation: 'animationend', - OAnimation: 'oAnimationEnd', - MozAnimation: 'mozAnimationEnd', - WebkitAnimation: 'webkitAnimationEnd', - }; - - for (var t in animations) { - if (el.style[t] !== undefined) { - return animations[t]; - } - } - })(document.createElement('div')); - - this.addClass('animated ' + animationName).one(animationEnd, function() { - $(this).removeClass('animated ' + animationName); - - if (typeof callback === 'function') callback(); - }); - - return this; - }, -}); \ No newline at end of file +} \ No newline at end of file diff --git a/js/template.js b/js/template.js index 95e86c03..0feaff34 100644 --- a/js/template.js +++ b/js/template.js @@ -24,20 +24,21 @@ function HTML_showPins(items) { var img = getCover(type, pin.criteria.artist) var title = pin.name var subtitle = '演出者' - var onclickActions = `show_artist(\`${pin.criteria.artist}\`)` + var link = `artist/${encodeURIComponent(pin.criteria.artist)}` break; case "composer": //作曲者 var img = getCover(type, pin.criteria.composer) var title = pin.name var subtitle = '作曲者' - var onclickActions = `show_composer(\`${pin.criteria.composer}\`)` + var link = `composer/${encodeURIComponent(pin.criteria.composer)}` break; case "genre": //作曲者 var img = getCover(type, pin.criteria.genre) var title = pin.name var subtitle = '類型' + var link = '' var onclickActions = `mdui.snackbar({message: '沒打算做喔,不過資料都給了就給你看一下啦',timeout:500,position:'${getSnackbarPosition()}'});` break; case "folder": @@ -45,14 +46,14 @@ function HTML_showPins(items) { var img = getCover(type, pin.criteria.folder) var title = pin.name var subtitle = '資料夾' - var onclickActions = `show_folder(\`${pin.criteria.folder}\`)` + var link = `folder/${encodeURIComponent(pin.criteria.folder)}` break; case "playlist": //資料夾 var img = getBackground() var title = pin.name var subtitle = '播放清單' - var onclickActions = `show_playlist_songs(\`${pin.criteria.playlist}\`) ` + var link = `playlist/${encodeURIComponent(pin.criteria.playlist)} ` break; case "album": //專輯 @@ -63,14 +64,16 @@ function HTML_showPins(items) { var img = getCover("album", name, artist, album_artist) var title = name var subtitle = artist - var onclickActions = `show_album_songs(\`${artist}\`,\`${name}\`,\`${album_artist}\`)` + var link = `album/${artist?encodeURIComponent(artist):'#'}/${name?encodeURIComponent(name):'#'}/${album_artist?encodeURIComponent(album_artist):'#'}` break; } //await getAlbumSong(albumData.criteria.album, albumData.criteria.album_artist, albumData.criteria.artist) html += `