2023-10-20 14:35:26 +00:00
// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
//
// SPDX-License-Identifier: AGPL-3.0-or-later
2017-06-21 16:02:38 +00:00
define ( [
'/common/hyperscript.js' ,
2018-05-22 13:26:35 +00:00
'/common/common-language.js' ,
2024-03-26 13:55:27 +00:00
'/common/common-util.js' ,
2020-01-20 13:53:02 +00:00
'/customize/application_config.js' ,
2017-09-07 14:39:20 +00:00
'/customize/messages.js' ,
2018-01-12 16:39:36 +00:00
'jquery' ,
2021-04-26 13:01:33 +00:00
'/api/config' ,
2022-05-03 12:50:18 +00:00
'optional!/api/instance' ,
2024-03-26 13:55:27 +00:00
] , function ( h , Language , Util , AppConfig , Msg , $ , ApiConfig , Instance ) {
2017-06-21 16:02:38 +00:00
var Pages = { } ;
2018-10-25 09:41:18 +00:00
Pages . setHTML = function ( e , html ) {
e . innerHTML = html ;
return e ;
} ;
2017-06-21 16:02:38 +00:00
2021-03-24 09:11:47 +00: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 09:24:52 +00: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 08:16:52 +00: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 13:26:35 +00:00
var languageSelector = function ( ) {
var languages = Msg . _languages ;
var selected = Msg . _languageUsed ;
var keys = Object . keys ( languages ) . sort ( ) ;
2023-08-09 11:25:10 +00:00
var options = keys . map ( function ( l ) {
var attr = { value : l } ;
2018-05-22 13:26:35 +00:00
if ( selected === l ) { attr . selected = 'selected' ; }
2023-08-09 11:25:10 +00:00
return h ( 'option' , attr , languages [ l ] ) ;
2018-05-22 13:26:35 +00:00
} ) ;
2023-08-09 11:25:10 +00:00
var select = h ( 'select' , { 'aria-label' : Msg . selectLanguage } , options ) ;
2018-05-22 13:26:35 +00:00
$ ( select ) . change ( function ( ) {
Language . setLanguage ( $ ( select ) . val ( ) || '' , null , function ( ) {
window . location . reload ( ) ;
} ) ;
} ) ;
return select ;
} ;
2022-03-23 09:59:16 +00:00
var footLink = function ( ref , loc , text , icon ) {
2021-04-09 08:05:03 +00:00
if ( ! ref ) { return ; }
2017-08-01 12:17:02 +00:00
var attrs = {
href : ref ,
} ;
2022-03-23 09:59:16 +00:00
var iconName = '' ;
2017-08-01 12:17:02 +00:00
if ( ! /^\// . test ( ref ) ) {
attrs . target = '_blank' ;
attrs . rel = 'noopener noreferrer' ;
}
if ( loc ) {
attrs [ 'data-localization' ] = loc ;
text = Msg [ loc ] ;
}
2022-03-23 09:59:16 +00:00
if ( icon ) {
iconName = 'i.fa.fa-' + icon ;
2022-03-25 06:03:56 +00:00
icon = h ( iconName ) ;
2022-03-23 09:59:16 +00:00
}
return h ( 'a' , attrs , [ icon , text ] ) ;
2017-08-01 12:17:02 +00:00
} ;
2024-03-26 13:55:27 +00:00
let urlArgs = ApiConfig . requireConf && ApiConfig . requireConf . urlArgs ;
Pages . versionString = Util . getVersionFromUrlArgs ( urlArgs ) ;
2020-05-28 18:37:50 +00:00
2022-02-24 10:07:05 +00:00
var customURLs = Pages . customURLs = { } ;
( function ( ) {
var defaultURLs = {
2023-05-16 12:54:39 +00:00
source : 'https://github.com/cryptpad/cryptpad' ,
2022-02-24 10:07:05 +00:00
} ;
var l = Msg . _getLanguage ( ) ;
2023-09-26 14:26:12 +00:00
[ 'imprint' , 'privacy' , 'terms' , 'status' , 'roadmap' , 'source' ] . forEach ( function ( k ) {
2022-02-24 10:07:05 +00:00
var value = AppConfig [ k ] ;
2022-05-13 10:20:38 +00:00
//console.log('links', k, value);
2022-02-24 10:07:05 +00: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 12:23:14 +00:00
var value = AppConfig . hostDescription ;
Pages . hostDescription = ( value && ( value [ l ] || value . default ) ) || Msg . home _host ;
2022-05-03 12:50:18 +00:00
Pages . Instance = { } ;
Object . keys ( Instance ) . forEach ( function ( k ) {
var value = Instance [ k ] ;
2022-05-04 13:05:30 +00:00
Pages . Instance [ k ] = value [ l ] || value . default || undefined ;
2022-05-03 12:50:18 +00: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 10:07:05 +00:00
} ( ) ) ;
2020-06-10 14:49:29 +00:00
// used for the about menu
2022-02-24 10:07:05 +00:00
Pages . imprintLink = footLink ( customURLs . imprint , 'imprint' ) ;
Pages . privacyLink = footLink ( customURLs . privacy , 'privacy' ) ;
2022-05-13 13:26:49 +00:00
Pages . termsLink = footLink ( customURLs . terms , 'terms' ) ;
2022-02-24 10:07:05 +00:00
Pages . sourceLink = footLink ( customURLs . source , 'footer_source' ) ;
2022-09-09 11:57:09 +00:00
Pages . docsLink = footLink ( 'https://docs.cryptpad.org' , 'docs_link' ) ;
2022-02-24 10:07:05 +00:00
Pages . roadmapLink = footLink ( customURLs . roadmap , 'footer_roadmap' ) ;
2020-06-10 14:49:29 +00:00
2017-08-01 12:17:02 +00:00
2022-03-23 09:59:16 +00:00
Pages . infopageFooter = function ( ) {
2022-05-13 09:45:00 +00:00
var donateButton ;
if ( ! ApiConfig . removeDonateButton ) {
2022-09-08 09:35:15 +00:00
donateButton = footLink ( 'https://opencollective.com/cryptpad/contribute/' , 'footer_donate' , null , 'money' ) ; // TODO migrate to forkawesome and use the OpenCollective icon
2022-05-13 09:45:00 +00:00
}
2022-03-23 09:59:16 +00:00
return h ( 'footer.cp-footer' , [
h ( 'div.cp-footer-left' , [
2022-05-13 11:40:12 +00: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 09:59:16 +00:00
] ) ,
2022-05-06 17:00:30 +00:00
h ( 'span.cp-footer-version' , 'v' + Pages . versionString )
] ) ,
h ( 'div.cp-footer-center' , [
2022-05-04 15:57:02 +00:00
h ( 'div.cp-logo-btns' , [
footLink ( 'https://cryptpad.org' , null , Msg . footer _website , 'link' ) ,
2022-05-13 09:45:00 +00:00
donateButton ,
2022-05-04 15:57:02 +00:00
] )
2022-03-23 09:59:16 +00:00
] ) ,
2022-05-06 17:00:30 +00:00
h ( 'div.cp-footer-right' , [
2022-03-23 09:59:16 +00:00
h ( 'div.cp-footer-language' , [
h ( 'i.fa.fa-language' , { 'aria-hidden' : 'true' } ) ,
languageSelector ( )
] )
] )
] ) ;
} ;
2018-10-25 09:41:18 +00:00
Pages . infopageTopbar = function ( ) {
2017-08-04 14:48:01 +00:00
var rightLinks ;
var username = window . localStorage . getItem ( 'User_name' ) ;
2021-04-26 13:01:33 +00:00
var registerLink ;
if ( ! ApiConfig . restrictRegistration ) {
2022-03-23 09:59:16 +00: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 13:01:33 +00:00
}
2017-08-04 14:48:01 +00:00
if ( username === null ) {
rightLinks = [
2022-03-23 09:59:16 +00: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 13:01:33 +00:00
registerLink ,
2017-08-04 14:48:01 +00:00
] ;
} else {
2017-08-11 09:32:21 +00:00
rightLinks = h ( 'a.nav-item.nav-link.cp-user-btn' , { href : '/drive/' } , [
2022-03-23 09:59:16 +00:00
h ( 'i.fa.fa-user-circle' , { 'aria-hidden' : 'true' } ) ,
2017-08-04 14:48:01 +00:00
" " ,
username
] ) ;
}
2022-05-06 08:25:00 +00:00
var isHome = [ '/' , '/index.html' ] . includes ( window . location . pathname ) ;
2022-05-06 10:10:44 +00: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-06 17:00:30 +00:00
h ( 'img' , {
src : '/customize/CryptPad_logo.svg' ,
"aria-hidden" : true ,
alt : ''
} ) ,
2022-05-06 10:10:44 +00:00
Msg . homePage
2022-05-06 08:25:00 +00:00
] ) ;
2018-03-20 10:05:43 +00:00
return h ( 'nav.navbar.navbar-expand-lg' ,
2022-03-30 10:19:35 +00:00
[
2022-05-06 08:25:00 +00:00
! isHome ? homeLink : undefined ,
2022-05-06 10:10:44 +00: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 11:57:09 +00:00
h ( 'a.nav-item.nav-link' , { href : 'https://docs.cryptpad.org' } ,
2022-03-23 09:59:16 +00:00
[ h ( 'i.fa.fa-book' , { 'aria-hidden' : 'true' } ) , Msg . docs _link ] ) ,
2022-03-30 10:19:35 +00:00
] . concat ( rightLinks )
2017-08-04 09:33:28 +00:00
) ;
} ;
2017-06-21 16:02:38 +00:00
return Pages ;
} ) ;