diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-03-10 13:20:28 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-03-10 13:20:28 +0100 |
| commit | 555fb6c8d95caa4349922c23818fc9e115226057 (patch) | |
| tree | f9426e071c1d3a87b434dd7cc1b127baf3593baa /public | |
| parent | fd896111e5d045dccc3b6568229b3b9191a2b921 (diff) | |
new router, handle opus, eslintrc
Diffstat (limited to 'public')
| -rw-r--r-- | public/assets/js/lib/sdk/auth.js | 4 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/audio.js | 2 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/files.js | 4 | ||||
| -rw-r--r-- | public/assets/js/vendor/view/router.js | 35 |
4 files changed, 28 insertions, 17 deletions
diff --git a/public/assets/js/lib/sdk/auth.js b/public/assets/js/lib/sdk/auth.js index 0b49449..63a903c 100644 --- a/public/assets/js/lib/sdk/auth.js +++ b/public/assets/js/lib/sdk/auth.js @@ -64,7 +64,7 @@ var auth = (function(){ auth.clear_user() } auth.logged_in = function(){ - return (auth.user.id && auth.user.id !== -1 && auth.user.id !== "undefined") + return (auth.user && auth.user.id && auth.user.id !== -1 && auth.user.id !== "undefined") } auth.checkin = function(opt){ $.ajax({ @@ -72,7 +72,7 @@ var auth = (function(){ url: '/api/checkin', headers: { "csrf-token": $("[name=_csrf]").attr("value") }, success: function(data){ - if (data && data.user && data.user.id !== -1) { + if (data && data.user && data.user.id && data.user.id !== -1) { auth.set_user(data.user) opt.success(data.user) return diff --git a/public/assets/js/lib/views/details/audio.js b/public/assets/js/lib/views/details/audio.js index 0f16dc7..c876520 100644 --- a/public/assets/js/lib/views/details/audio.js +++ b/public/assets/js/lib/views/details/audio.js @@ -17,7 +17,7 @@ var audio = (function(){ music = [] var links = document.querySelectorAll("a") Array.prototype.slice.apply(links).forEach(function(link){ - if (! link.href.match(/\.(mp3|wav|ogg)$/)) return + if (! link.href.match(/\.(mp3|wav|ogg|opus)$/)) return link.dataset.index = music.length music.push(link) if (playing && link.href === el.src) { diff --git a/public/assets/js/lib/views/details/files.js b/public/assets/js/lib/views/details/files.js index b6f1794..3c7f84f 100644 --- a/public/assets/js/lib/views/details/files.js +++ b/public/assets/js/lib/views/details/files.js @@ -25,7 +25,7 @@ var FilesView = FormView.extend({ // return } total += file.size - has_music = has_music || file.filename.match(/(mp3|wav|ogg)/i) + has_music = has_music || file.filename.match(/(mp3|wav|ogg|opus)$/i) }.bind(this)) this.total = total @@ -137,7 +137,7 @@ var FilesView = FormView.extend({ pick: function(e){ if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey) return - if (! e.target.href || ! e.target.href.match(/(mp3|wav|ogg)/i)) return + if (! e.target.href || ! e.target.href.match(/(mp3|wav|ogg|opus)$/i)) return e.preventDefault() audio.play( e.target.dataset.index ) // index set in audio.js }, diff --git a/public/assets/js/vendor/view/router.js b/public/assets/js/vendor/view/router.js index b0e2f84..3b0d939 100644 --- a/public/assets/js/vendor/view/router.js +++ b/public/assets/js/vendor/view/router.js @@ -1,21 +1,34 @@ var Router = View.extend({ + routeByHash: false, + go: function(url){ this.parseRoute(url) }, + + pushState: function(url){ + if (this.routeByHash) { + window.location.hash = url + } + else if (window.history) { + window.history.pushState(null, null, url) + } + }, route: function(){ - this.originalPath = window.location.pathname - this.parseRoute(window.location.pathname) - }, - - pushState: function(pathname){ - window.history.pushState({}, "", pathname) + var path = this.routeByHash ? window.location.hash.substr(0) : window.location.pathname + path = path || "/" + this.originalPath = path + this.parseRoute(path) }, parseRoute: function(pathname){ + + pathname = pathname.replace(/^#/, "") + + if (pathname[0] !== "/") { pathname = "/" + pathname } - var routes = is_mobile && this.mobileRoutes ? this.mobileRoutes : this.routes, + var routes = this.routes, path = pathname.split("/"); for (var i = 0; i < path.length; i++) { @@ -23,7 +36,7 @@ var Router = View.extend({ path[i] = null } } - + if (pathname in routes) { this[this.routes[pathname]]() return @@ -62,10 +75,8 @@ var Router = View.extend({ } } } - - if (is_mobile) { - window.location.href = "/" - } + // Redirect to root on 404 + window.location = '/' } }) |
