diff --git a/static/js/portico/landing-page.js b/static/js/portico/landing-page.js index b8f90e801f..45805af7d5 100644 --- a/static/js/portico/landing-page.js +++ b/static/js/portico/landing-page.js @@ -414,7 +414,6 @@ var hello_events = function () { }; var apps_events = function () { - var version; var info = { windows: { image: "/static/images/landing-page/microsoft.png", @@ -448,35 +447,33 @@ var apps_events = function () { }, }; - var nav_version = { - Win: "windows", - MacIntel: "mac", - Linux: "linux", - iP: "ios", - }; + var version; - // if the hash is not a valid section, then identify it. - version = window.location.hash.replace(/^#/, ""); + function get_version_from_path() { + var result; + var parts = path_parts(); - if (info[version]) { - window.location.hash = version; - } else { - for (var x in nav_version) { - if (navigator.platform.indexOf(x) !== -1) { - window.location.hash = nav_version[x]; - version = nav_version[x]; - break; + Object.keys(info).forEach(function (version) { + if (parts.includes(version)) { + result = version; } - } + }); - if (!version || !info[version]) { - version = "mac"; - } - - window.location.hash = version; + // display Mac app by default + result = result || 'mac'; + return result; } - var update_version = function (version) { + function get_path_from_version() { + return '/apps/' + version; + } + + function update_path() { + var next_path = get_path_from_version(); + history.pushState(version, '', next_path); + } + + var update_page = function () { var version_info = info[version]; $(".info .platform").text(version_info.alt); $(".info .description").text(version_info.description); @@ -484,16 +481,29 @@ var apps_events = function () { $(".image img").attr("src", version_info.image); }; - - window.onhashchange = function () { - update_version(window.location.hash.substr(1)); - }; - - update_version(version); - - $(".apps > .icon").click(function () { + $(window).on('popstate', function () { + version = get_version_from_path(); + update_page(); $("body").animate({ scrollTop: 0 }, 200); }); + + $(".apps a .icon").click(function (e) { + var next_version = $(e.target).closest('a') + .attr('href') + .replace('/apps/', ''); + version = next_version; + + update_path(); + update_page(); + $("body").animate({ scrollTop: 0 }, 200); + + return false; + }); + + // init + version = get_version_from_path(); + history.replaceState(version, '', get_path_from_version()); + update_page(); }; var events = function () { diff --git a/templates/zerver/apps.html b/templates/zerver/apps.html index 315ab4a6f6..dadbe45e81 100644 --- a/templates/zerver/apps.html +++ b/templates/zerver/apps.html @@ -43,11 +43,21 @@

Apps for every platform.

- - - - - + + + + + + + + + + + + + + +
diff --git a/templates/zerver/hello.html b/templates/zerver/hello.html index 7cfbd9bbd0..64a0061e54 100644 --- a/templates/zerver/hello.html +++ b/templates/zerver/hello.html @@ -333,22 +333,22 @@

Desktop

- + - + - +

Mobile

- + - +
diff --git a/zerver/views/home.py b/zerver/views/home.py index 97f96c2770..50aed9401d 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -266,8 +266,8 @@ def desktop_home(request): # type: (HttpRequest) -> HttpResponse return HttpResponseRedirect(reverse('zerver.views.home.home')) -def apps_view(request): - # type: (HttpRequest) -> HttpResponse +def apps_view(request, _): + # type: (HttpRequest, Text) -> HttpResponse if settings.ZILENCER_ENABLED: return render(request, 'zerver/apps.html') return HttpResponseRedirect('https://zulipchat.com/apps/', status=301) diff --git a/zproject/urls.py b/zproject/urls.py index 2d97b0dadb..56b8aa38cf 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -143,7 +143,7 @@ i18n_urls = [ name="zerver.views.integrations.integration_doc"), url(r'^integrations/(.*)', IntegrationView.as_view()), url(r'^about/$', TemplateView.as_view(template_name='zerver/about.html')), - url(r'^apps/$', zerver.views.home.apps_view, name='zerver.views.home.apps_view'), + url(r'^apps/(.*)', zerver.views.home.apps_view, name='zerver.views.home.apps_view'), url(r'^robots\.txt$', RedirectView.as_view(url='/static/robots.txt', permanent=True)),