2017-06-22 00:02:38 +08:00
define ( [
'/common/hyperscript.js' ,
2018-05-22 21:26:35 +08:00
'/common/common-language.js' ,
2020-01-20 21:53:02 +08:00
'/customize/application_config.js' ,
2017-09-07 22:39:20 +08:00
'/customize/messages.js' ,
2018-01-13 00:39:36 +08:00
'jquery' ,
2021-04-26 21:01:33 +08:00
'/api/config' ,
2022-05-03 20:50:18 +08:00
'optional!/api/instance' ,
] , function ( h , Language , AppConfig , Msg , $ , ApiConfig , Instance ) {
2017-06-22 00:02:38 +08:00
var Pages = { } ;
2018-10-25 17:41:18 +08:00
Pages . setHTML = function ( e , html ) {
e . innerHTML = html ;
return e ;
} ;
2017-06-22 00:02:38 +08:00
2021-03-24 17:11:47 +08:00
Pages . externalLink = function ( el , href ) {
if ( ! el ) { return el ; }
el . setAttribute ( "rel" , "noopener noreferrer" ) ;
el . setAttribute ( "target" , "_blank" ) ;
if ( typeof ( href ) === 'string' ) {
el . setAttribute ( "href" , href ) ;
}
return el ;
} ;
2021-04-12 17:24:52 +08:00
// this rewrites URLS to point to the appropriate translation:
// French, German, or English as a default
var documentedLanguages = [ 'en' , 'fr' , 'de' ] ;
Pages . localizeDocsLink = function ( href ) {
try {
var lang = Msg . _getLanguage ( ) ;
if ( documentedLanguages . indexOf ( lang ) > 0 ) {
return href . replace ( '/en/' , '/' + lang + '/' ) ;
}
} catch ( err ) {
console . error ( err ) ;
// if it fails just use the default href (English)
}
return href ;
} ;
Pages . documentationLink = function ( el , href ) {
return Pages . externalLink ( el , Pages . localizeDocsLink ( href ) ) ;
} ;
2021-05-19 16:16:52 +08:00
var accounts = Pages . accounts = {
donateURL : AppConfig . donateURL || "https://opencollective.com/cryptpad/" ,
upgradeURL : AppConfig . upgradeURL
} ;
Pages . areSubscriptionsAllowed = function ( ) {
try {
return ApiConfig . allowSubscriptions && accounts . upgradeURL && ! ApiConfig . restrictRegistration ;
} catch ( err ) { return void console . error ( err ) ; }
} ;
2018-05-22 21:26:35 +08:00
var languageSelector = function ( ) {
var options = [ ] ;
var languages = Msg . _languages ;
var selected = Msg . _languageUsed ;
var keys = Object . keys ( languages ) . sort ( ) ;
keys . forEach ( function ( l ) {
2020-11-05 19:59:15 +08:00
var attr = { value : l , role : 'option' } ;
2018-05-22 21:26:35 +08:00
if ( selected === l ) { attr . selected = 'selected' ; }
options . push ( h ( 'option' , attr , languages [ l ] ) ) ;
} ) ;
2020-11-05 19:59:15 +08:00
var select = h ( 'select' , { role : 'listbox' , 'label' : 'language' } , options ) ;
2018-05-22 21:26:35 +08:00
$ ( select ) . change ( function ( ) {
Language . setLanguage ( $ ( select ) . val ( ) || '' , null , function ( ) {
window . location . reload ( ) ;
} ) ;
} ) ;
return select ;
} ;
2022-03-23 17:59:16 +08:00
var footLink = function ( ref , loc , text , icon ) {
2021-04-09 16:05:03 +08:00
if ( ! ref ) { return ; }
2017-08-01 20:17:02 +08:00
var attrs = {
href : ref ,
} ;
2022-03-23 17:59:16 +08:00
var iconName = '' ;
2017-08-01 20:17:02 +08:00
if ( ! /^\// . test ( ref ) ) {
attrs . target = '_blank' ;
attrs . rel = 'noopener noreferrer' ;
}
if ( loc ) {
attrs [ 'data-localization' ] = loc ;
text = Msg [ loc ] ;
}
2022-03-23 17:59:16 +08:00
if ( icon ) {
iconName = 'i.fa.fa-' + icon ;
2022-03-25 14:03:56 +08:00
icon = h ( iconName ) ;
2022-03-23 17:59:16 +08:00
}
return h ( 'a' , attrs , [ icon , text ] ) ;
2017-08-01 20:17:02 +08:00
} ;
2023-04-27 21:46:40 +08:00
Pages . versionString = "5.3.0" ;
2020-05-29 02:37:50 +08:00
2022-02-24 18:07:05 +08:00
var customURLs = Pages . customURLs = { } ;
( function ( ) {
var defaultURLs = {
2023-05-16 20:54:39 +08:00
source : 'https://github.com/cryptpad/cryptpad' ,
2022-02-24 18:07:05 +08:00
} ;
var l = Msg . _getLanguage ( ) ;
[ 'imprint' , 'privacy' , 'terms' , 'roadmap' , 'source' ] . forEach ( function ( k ) {
var value = AppConfig [ k ] ;
2022-05-13 18:20:38 +08:00
//console.log('links', k, value);
2022-02-24 18:07:05 +08:00
if ( value === false ) { return ; }
if ( value === true ) {
customURLs [ k ] = defaultURLs [ k ] ;
return ;
}
if ( typeof ( value ) === 'string' ) {
customURLs [ k ] = value ;
return ;
}
if ( typeof ( value ) === 'object' ) {
customURLs [ k ] = value [ l ] || value [ 'default' ] ;
}
} ) ;
2022-03-30 20:23:14 +08:00
var value = AppConfig . hostDescription ;
Pages . hostDescription = ( value && ( value [ l ] || value . default ) ) || Msg . home _host ;
2022-05-03 20:50:18 +08:00
Pages . Instance = { } ;
Object . keys ( Instance ) . forEach ( function ( k ) {
var value = Instance [ k ] ;
2022-05-04 21:05:30 +08:00
Pages . Instance [ k ] = value [ l ] || value . default || undefined ;
2022-05-03 20:50:18 +08:00
} ) ;
var name ;
try {
name = Pages . Instance . name || new URL ( '/' , ApiConfig . httpUnsafeOrigin ) . host ;
} catch ( err ) {
name = 'CryptPad' ;
}
Pages . Instance . name = name ;
Pages . Instance . description = Pages . Instance . description || Msg . main _catch _phrase ;
2022-02-24 18:07:05 +08:00
} ( ) ) ;
2020-06-10 22:49:29 +08:00
// used for the about menu
2022-02-24 18:07:05 +08:00
Pages . imprintLink = footLink ( customURLs . imprint , 'imprint' ) ;
Pages . privacyLink = footLink ( customURLs . privacy , 'privacy' ) ;
2022-05-13 21:26:49 +08:00
Pages . termsLink = footLink ( customURLs . terms , 'terms' ) ;
2022-02-24 18:07:05 +08:00
Pages . sourceLink = footLink ( customURLs . source , 'footer_source' ) ;
2022-09-09 19:57:09 +08:00
Pages . docsLink = footLink ( 'https://docs.cryptpad.org' , 'docs_link' ) ;
2022-02-24 18:07:05 +08:00
Pages . roadmapLink = footLink ( customURLs . roadmap , 'footer_roadmap' ) ;
2020-06-10 22:49:29 +08:00
2017-08-01 20:17:02 +08:00
2022-03-23 17:59:16 +08:00
Pages . infopageFooter = function ( ) {
2022-05-13 17:45:00 +08:00
var donateButton ;
if ( ! ApiConfig . removeDonateButton ) {
2022-09-08 17:35:15 +08:00
donateButton = footLink ( 'https://opencollective.com/cryptpad/contribute/' , 'footer_donate' , null , 'money' ) ; // TODO migrate to forkawesome and use the OpenCollective icon
2022-05-13 17:45:00 +08:00
}
2022-03-23 17:59:16 +08:00
return h ( 'footer.cp-footer' , [
h ( 'div.cp-footer-left' , [
2022-05-13 19:40:12 +08:00
h ( 'a' , { href : "https://cryptpad.org" } , [
h ( 'div.cp-logo-foot' , [
h ( 'img' , {
src : '/customize/CryptPad_logo.svg' ,
"aria-hidden" : true ,
alt : ''
} ) ,
h ( 'span.logo-font' , 'CryptPad' )
] )
2022-03-23 17:59:16 +08:00
] ) ,
2022-05-07 01:00:30 +08:00
h ( 'span.cp-footer-version' , 'v' + Pages . versionString )
] ) ,
h ( 'div.cp-footer-center' , [
2022-05-04 23:57:02 +08:00
h ( 'div.cp-logo-btns' , [
footLink ( 'https://cryptpad.org' , null , Msg . footer _website , 'link' ) ,
2022-05-13 17:45:00 +08:00
donateButton ,
2022-05-04 23:57:02 +08:00
] )
2022-03-23 17:59:16 +08:00
] ) ,
2022-05-07 01:00:30 +08:00
h ( 'div.cp-footer-right' , [
2022-03-23 17:59:16 +08:00
h ( 'div.cp-footer-language' , [
h ( 'i.fa.fa-language' , { 'aria-hidden' : 'true' } ) ,
languageSelector ( )
] )
] )
] ) ;
} ;
2018-10-25 17:41:18 +08:00
Pages . infopageTopbar = function ( ) {
2017-08-04 22:48:01 +08:00
var rightLinks ;
var username = window . localStorage . getItem ( 'User_name' ) ;
2021-04-26 21:01:33 +08:00
var registerLink ;
if ( ! ApiConfig . restrictRegistration ) {
2022-03-23 17:59:16 +08:00
registerLink = h ( 'a.nav-item.nav-link.cp-register-btn' , { href : '/register/' } , [
h ( 'i.fa.fa-user' , { 'aria-hidden' : 'true' } ) ,
Msg . login _register
] ) ;
2021-04-26 21:01:33 +08:00
}
2017-08-04 22:48:01 +08:00
if ( username === null ) {
rightLinks = [
2022-03-23 17:59:16 +08:00
h ( 'a.nav-item.nav-link.cp-login-btn' , { href : '/login/' } , [
h ( 'i.fa.fa-sign-in' , { 'aria-hidden' : 'true' } ) ,
Msg . login _login
] ) ,
2021-04-26 21:01:33 +08:00
registerLink ,
2017-08-04 22:48:01 +08:00
] ;
} else {
2017-08-11 17:32:21 +08:00
rightLinks = h ( 'a.nav-item.nav-link.cp-user-btn' , { href : '/drive/' } , [
2022-03-23 17:59:16 +08:00
h ( 'i.fa.fa-user-circle' , { 'aria-hidden' : 'true' } ) ,
2017-08-04 22:48:01 +08:00
" " ,
username
] ) ;
}
2022-05-06 16:25:00 +08:00
var isHome = [ '/' , '/index.html' ] . includes ( window . location . pathname ) ;
2022-05-06 18:10:44 +08:00
var homeLink = h ( 'a.nav-item.nav-link.cp-back-home' /* .navbar-brand */ , { href : '/index.html' } , [
h ( 'i.fa.fa-arrow-left' ) ,
2022-05-07 01:00:30 +08:00
h ( 'img' , {
src : '/customize/CryptPad_logo.svg' ,
"aria-hidden" : true ,
alt : ''
} ) ,
2022-05-06 18:10:44 +08:00
Msg . homePage
2022-05-06 16:25:00 +08:00
] ) ;
2018-03-20 18:05:43 +08:00
return h ( 'nav.navbar.navbar-expand-lg' ,
2022-03-30 18:19:35 +08:00
[
2022-05-06 16:25:00 +08:00
! isHome ? homeLink : undefined ,
2022-05-06 18:10:44 +08:00
h ( 'a.nav-item.nav-link' , { href : '/features.html' } , [
h ( 'i.fa.fa-info-circle' ) ,
Pages . areSubscriptionsAllowed ( ) ? Msg . pricing : Msg . features
] ) ,
2022-09-09 19:57:09 +08:00
h ( 'a.nav-item.nav-link' , { href : 'https://docs.cryptpad.org' } ,
2022-03-23 17:59:16 +08:00
[ h ( 'i.fa.fa-book' , { 'aria-hidden' : 'true' } ) , Msg . docs _link ] ) ,
2022-03-30 18:19:35 +08:00
] . concat ( rightLinks )
2017-08-04 17:33:28 +08:00
) ;
} ;
2017-06-22 00:02:38 +08:00
return Pages ;
} ) ;