2018-10-12 14:32:53 +02:00
const ELECTRON _APP _VERSION = "2.3.82" ;
2017-07-26 20:02:08 +02:00
const ELECTRON _APP _URL _LINUX = "https://github.com/zulip/zulip-electron/releases/download/v" + ELECTRON _APP _VERSION + "/Zulip-" + ELECTRON _APP _VERSION + "-x86_64.AppImage" ;
const ELECTRON _APP _URL _MAC = "https://github.com/zulip/zulip-electron/releases/download/v" + ELECTRON _APP _VERSION + "/Zulip-" + ELECTRON _APP _VERSION + ".dmg" ;
const ELECTRON _APP _URL _WINDOWS = "https://github.com/zulip/zulip-electron/releases/download/v" + ELECTRON _APP _VERSION + "/Zulip-Web-Setup-" + ELECTRON _APP _VERSION + ".exe" ;
2017-07-08 02:28:18 +02:00
2017-11-17 19:50:55 +01:00
import render _tabs from './team.js' ;
2019-01-14 20:13:47 +01:00
import { detect _user _os } from './tabbed-instructions.js' ;
2017-11-17 19:50:55 +01:00
2017-02-28 01:45:25 +01:00
// this will either smooth scroll to an anchor where the `name`
// is the same as the `scroll-to` reference, or to a px height
// (as specified like `scroll-to='0px'`).
var ScrollTo = function ( ) {
$ ( "[scroll-to]" ) . click ( function ( ) {
var sel = $ ( this ) . attr ( "scroll-to" ) ;
// if the `scroll-to` is a parse-able pixel value like `50px`,
// then use that as the scrollTop, else assume it is a selector name
// and find the `offsetTop`.
var top = /\dpx/ . test ( sel ) ?
2018-05-06 21:43:17 +02:00
parseInt ( sel , 10 ) :
$ ( "[name='" + sel + "']" ) . offset ( ) . top ;
2017-02-28 01:45:25 +01:00
$ ( "body" ) . animate ( { scrollTop : top + "px" } , 300 ) ;
} ) ;
} ;
2017-08-01 07:21:44 +02:00
export function path _parts ( ) {
2017-07-18 04:40:31 +02:00
return window . location . pathname . split ( '/' ) . filter ( function ( chunk ) {
return chunk !== '' ;
} ) ;
}
2017-07-01 01:29:15 +02:00
2017-04-20 20:44:49 +02:00
var hello _events = function ( ) {
var counter = 0 ;
$ ( window ) . scroll ( function ( ) {
if ( counter % 2 === 0 ) {
$ ( ".screen.hero-screen .message-feed" ) . css ( "transform" , "translateY(-" + $ ( this ) . scrollTop ( ) / 5 + "px)" ) ;
}
counter += 1 ;
} ) ;
$ ( ".footer" ) . addClass ( "hello" ) ;
} ;
2017-07-08 02:28:18 +02:00
var apps _events = function ( ) {
var info = {
windows : {
image : "/static/images/landing-page/microsoft.png" ,
alt : "Windows" ,
description : "Zulip for Windows is even better than Zulip on the web, with a cleaner look, tray integration, native notifications, and support for multiple Zulip accounts." ,
link : ELECTRON _APP _URL _WINDOWS ,
2017-09-28 03:37:05 +02:00
show _instructions : true ,
2018-09-15 21:35:25 +02:00
install _guide : "/help/desktop-app-install-guide" ,
2017-07-08 02:28:18 +02:00
} ,
mac : {
image : "/static/images/landing-page/macbook.png" ,
2017-08-26 09:33:47 +02:00
alt : "macOS" ,
description : "Zulip on macOS is even better than Zulip on the web, with a cleaner look, tray integration, native notifications, and support for multiple Zulip accounts." ,
2017-07-08 02:28:18 +02:00
link : ELECTRON _APP _URL _MAC ,
2017-09-28 03:37:05 +02:00
show _instructions : true ,
2018-09-15 21:35:25 +02:00
install _guide : "/help/desktop-app-install-guide" ,
2017-07-08 02:28:18 +02:00
} ,
android : {
image : "/static/images/app-screenshots/zulip-android.png" ,
alt : "Android" ,
description : "Zulip's native Android app makes it easy to keep up while on the go." ,
2017-09-28 20:26:52 +02:00
link : "https://play.google.com/store/apps/details?id=com.zulipmobile" ,
2017-07-08 02:28:18 +02:00
} ,
ios : {
image : "/static/images/app-screenshots/zulip-iphone-rough.png" ,
alt : "iOS" ,
description : "Zulip's native iOS app makes it easy to keep up while on the go." ,
link : "https://itunes.apple.com/us/app/zulip/id1203036395" ,
} ,
linux : {
image : "/static/images/landing-page/ubuntu.png" ,
alt : "Linux" ,
description : "Zulip on the Linux desktop is even better than Zulip on the web, with a cleaner look, tray integration, native notifications, and support for multiple Zulip accounts." ,
link : ELECTRON _APP _URL _LINUX ,
2017-09-28 03:37:05 +02:00
show _instructions : true ,
2018-09-15 21:35:25 +02:00
install _guide : "/help/desktop-app-install-guide" ,
2017-07-08 02:28:18 +02:00
} ,
} ;
2017-07-28 04:29:37 +02:00
var version ;
2017-07-08 02:28:18 +02:00
2017-07-28 04:29:37 +02:00
function get _version _from _path ( ) {
var result ;
var parts = path _parts ( ) ;
2017-07-08 02:28:18 +02:00
2017-07-28 04:29:37 +02:00
Object . keys ( info ) . forEach ( function ( version ) {
2018-06-03 21:00:21 +02:00
if ( parts . indexOf ( version ) !== - 1 ) {
2017-07-28 04:29:37 +02:00
result = version ;
2017-07-08 02:28:18 +02:00
}
2017-07-28 04:29:37 +02:00
} ) ;
2017-07-08 02:28:18 +02:00
2019-01-14 20:13:47 +01:00
result = result || detect _user _os ( ) ;
2017-07-28 04:29:37 +02:00
return result ;
}
function get _path _from _version ( ) {
return '/apps/' + version ;
}
2017-07-08 02:28:18 +02:00
2017-07-28 04:29:37 +02:00
function update _path ( ) {
var next _path = get _path _from _version ( ) ;
history . pushState ( version , '' , next _path ) ;
2017-07-08 02:28:18 +02:00
}
2017-07-28 04:29:37 +02:00
var update _page = function ( ) {
2017-09-28 03:37:05 +02:00
var $download _instructions = $ ( ".download-instructions" ) ;
2018-04-27 18:14:55 +02:00
var $third _party _apps = $ ( "#third-party-apps" ) ;
2019-03-03 16:59:03 +01:00
var $download _android _apk = $ ( "#download-android-apk" ) ;
2017-07-08 02:28:18 +02:00
var version _info = info [ version ] ;
2017-09-28 03:37:05 +02:00
2017-07-08 02:28:18 +02:00
$ ( ".info .platform" ) . text ( version _info . alt ) ;
$ ( ".info .description" ) . text ( version _info . description ) ;
$ ( ".info .link" ) . attr ( "href" , version _info . link ) ;
$ ( ".image img" ) . attr ( "src" , version _info . image ) ;
2017-09-29 20:27:56 +02:00
$download _instructions . find ( "a" ) . attr ( "href" , version _info . install _guide ) ;
2017-09-28 03:37:05 +02:00
if ( version _info . show _instructions ) {
$download _instructions . show ( ) ;
} else {
$download _instructions . hide ( ) ;
}
2018-04-27 18:14:55 +02:00
if ( version === "mac" || version === "windows" || version === "linux" ) {
$third _party _apps . show ( ) ;
} else {
$third _party _apps . hide ( ) ;
}
2019-03-03 16:59:03 +01:00
$download _android _apk . toggle ( version === "android" ) ;
2017-07-08 02:28:18 +02:00
} ;
2017-07-28 04:29:37 +02:00
$ ( window ) . on ( 'popstate' , function ( ) {
version = get _version _from _path ( ) ;
update _page ( ) ;
$ ( "body" ) . animate ( { scrollTop : 0 } , 200 ) ;
} ) ;
2017-07-08 02:28:18 +02:00
2017-07-28 04:29:37 +02:00
$ ( ".apps a .icon" ) . click ( function ( e ) {
var next _version = $ ( e . target ) . closest ( 'a' )
. attr ( 'href' )
. replace ( '/apps/' , '' ) ;
version = next _version ;
2017-07-08 02:28:18 +02:00
2017-07-28 04:29:37 +02:00
update _path ( ) ;
update _page ( ) ;
2017-07-08 02:28:18 +02:00
$ ( "body" ) . animate ( { scrollTop : 0 } , 200 ) ;
2017-07-28 04:29:37 +02:00
return false ;
2017-07-08 02:28:18 +02:00
} ) ;
2017-07-28 04:29:37 +02:00
// init
version = get _version _from _path ( ) ;
history . replaceState ( version , '' , get _path _from _version ( ) ) ;
update _page ( ) ;
2017-07-08 02:28:18 +02:00
} ;
2017-02-28 01:45:25 +01:00
var events = function ( ) {
ScrollTo ( ) ;
$ ( "a" ) . click ( function ( e ) {
2017-10-26 02:06:47 +02:00
// if a user is holding the CMD/CTRL key while clicking a link, they
// want to open the link in another browser tab which means that we
// should preserve the state of this one. Return out, and don't fade
// the page.
if ( e . metaKey || e . ctrlKey ) {
return ;
}
2017-02-28 01:45:25 +01:00
// if the pathname is different than what we are already on, run the
// custom transition function.
2017-07-08 02:28:18 +02:00
if ( window . location . pathname !== this . pathname && ! this . hasAttribute ( "download" ) &&
! /no-action/ . test ( this . className ) ) {
2017-02-28 01:45:25 +01:00
e . preventDefault ( ) ;
2018-05-07 21:01:32 +02:00
2017-02-28 01:45:25 +01:00
setTimeout ( function ( ) {
window . location . href = $ ( this ) . attr ( "href" ) ;
2017-07-27 02:23:43 +02:00
} . bind ( this ) , 500 ) ;
2017-02-28 01:45:25 +01:00
}
} ) ;
// get the location url like `zulipchat.com/features/`, cut off the trailing
// `/` and then split by `/` to get ["zulipchat.com", "features"], then
// pop the last element to get the current section (eg. `features`).
2017-03-21 01:41:50 +01:00
var location = window . location . pathname . replace ( /\/#*$/ , "" ) . split ( /\// ) . pop ( ) ;
2017-02-28 01:45:25 +01:00
2018-07-06 23:19:15 +02:00
$ ( "[data-on-page='" + location + "']" ) . addClass ( "active" ) ;
2017-02-28 01:45:25 +01:00
$ ( "body" ) . click ( function ( e ) {
var $e = $ ( e . target ) ;
2017-06-12 22:05:29 +02:00
if ( $e . is ( "nav ul .exit" ) ) {
2017-02-28 01:45:25 +01:00
$ ( "nav ul" ) . removeClass ( "show" ) ;
}
2018-01-31 01:40:31 +01:00
if ( $ ( "nav ul.show" ) && ! $e . closest ( "nav ul.show" ) . length && ! $e . is ( "nav ul.show" ) ) {
$ ( "nav ul" ) . removeClass ( "show" ) ;
}
2017-02-28 01:45:25 +01:00
} ) ;
2018-01-31 01:40:31 +01:00
$ ( ".hamburger" ) . click ( function ( e ) {
2017-02-28 01:45:25 +01:00
$ ( "nav ul" ) . addClass ( "show" ) ;
2018-01-31 01:40:31 +01:00
e . stopPropagation ( ) ;
2017-02-28 01:45:25 +01:00
} ) ;
2017-05-10 19:55:40 +02:00
2018-06-03 21:00:21 +02:00
if ( path _parts ( ) . indexOf ( "apps" ) !== - 1 ) {
2017-07-08 02:28:18 +02:00
apps _events ( ) ;
}
2017-02-28 01:45:25 +01:00
2018-06-03 21:00:21 +02:00
if ( path _parts ( ) . indexOf ( 'hello' ) !== - 1 ) {
2017-04-20 20:44:49 +02:00
hello _events ( ) ;
}
2017-02-28 01:45:25 +01:00
} ;
2017-06-21 03:14:26 +02:00
2017-02-28 01:45:25 +01:00
// run this callback when the page is determined to have loaded.
var load = function ( ) {
2018-05-01 22:54:30 +02:00
// Initiate the bootstrap carousel logic
$ ( '.carousel' ) . carousel ( {
interval : false ,
} ) ;
2018-05-25 15:16:10 +02:00
// Move to the next slide on clicking inside the carousel container
$ ( ".carousel-inner .item-container" ) . click ( function ( e ) {
2018-06-04 21:07:09 +02:00
var get _tag _name = e . target . tagName . toLowerCase ( ) ;
var is _button = get _tag _name === "button" ;
var is _link = get _tag _name === "a" ;
var is _last _slide = $ ( "#tour-carousel .carousel-inner .item:last-child" ) . hasClass ( "active" ) ;
// Do not trigger this event if user clicks on a button, link
// or if it's the last slide
var move _slide _forward = ! is _button && ! is _link && ! is _last _slide ;
if ( move _slide _forward ) {
2018-06-04 10:39:08 +02:00
$ ( this ) . closest ( '.carousel' ) . carousel ( 'next' ) ;
2018-05-25 15:16:10 +02:00
}
} ) ;
2018-06-04 17:15:01 +02:00
$ ( ".carousel-link-button" ) . click ( function ( ) {
window . location . href = $ ( this ) . attr ( "href" ) ;
} ) ;
2018-06-04 10:18:18 +02:00
$ ( '.carousel' ) . on ( 'slid' , function ( ) {
var $this = $ ( this ) ;
$this . find ( '.visibility-control' ) . show ( ) ;
if ( $this . find ( '.carousel-inner .item:first' ) . hasClass ( 'active' ) ) {
$this . find ( '.left.visibility-control' ) . hide ( ) ;
} else if ( $this . find ( '.carousel-inner .item:last' ) . hasClass ( 'active' ) ) {
$this . find ( '.right.visibility-control' ) . hide ( ) ;
}
} ) ;
2017-06-21 03:14:26 +02:00
// Set up events / categories / search
2017-02-28 01:45:25 +01:00
events ( ) ;
} ;
if ( document . readyState === "complete" ) {
load ( ) ;
} else {
2017-10-05 16:01:50 +02:00
$ ( load ) ;
2017-02-28 01:45:25 +01:00
}
2017-11-17 19:50:55 +01:00
$ ( function ( ) {
if ( window . location . pathname === '/team/' ) {
render _tabs ( ) ;
}
} ) ;
2018-03-12 04:45:01 +01:00
// Prevent Firefox from bfcaching the page.
// According to https://developer.mozilla.org/en-US/docs/DOM/window.onunload
// Using this event handler in your page prevents Firefox from caching the
// page in the in-memory bfcache (backward/forward cache).
$ ( window ) . on ( 'unload' , function ( ) {
$ ( window ) . unbind ( 'unload' ) ;
} ) ;