cryptpad/customize.dist/pages.js

239 lines
8.1 KiB
JavaScript
Raw Normal View History

2017-06-21 16:02:38 +00:00
define([
'/common/hyperscript.js',
'/common/common-language.js',
'/customize/application_config.js',
2017-09-07 14:39:20 +00:00
'/customize/messages.js',
'jquery',
2021-04-26 13:01:33 +00:00
'/api/config',
'optional!/api/instance',
], function (h, Language, AppConfig, Msg, $, ApiConfig, Instance) {
2017-06-21 16:02:38 +00:00
var Pages = {};
Pages.setHTML = function (e, html) {
e.innerHTML = html;
return e;
};
2017-06-21 16:02:38 +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;
};
// 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));
};
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); }
};
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 11:59:15 +00:00
var attr = { value: l, role: 'option'};
if (selected === l) { attr.selected = 'selected'; }
options.push(h('option', attr, languages[l]));
});
2020-11-05 11:59:15 +00:00
var select = h('select', {role: 'listbox', 'label': 'language'}, options);
$(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) {
if (!ref) { return; }
var attrs = {
href: ref,
};
2022-03-23 09:59:16 +00:00
var iconName = '';
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;
icon = h(iconName);
2022-03-23 09:59:16 +00:00
}
return h('a', attrs, [icon, text]);
};
2022-12-21 14:29:00 +00:00
Pages.versionString = "5.2.1";
var customURLs = Pages.customURLs = {};
(function () {
var defaultURLs = {
source: 'https://github.com/xwiki-labs/cryptpad',
};
var l = Msg._getLanguage();
['imprint', 'privacy', 'terms', 'roadmap', 'source'].forEach(function (k) {
var value = AppConfig[k];
//console.log('links', k, value);
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'];
}
});
var value = AppConfig.hostDescription;
Pages.hostDescription = (value && (value[l] || value.default)) || Msg.home_host;
Pages.Instance = {};
Object.keys(Instance).forEach(function (k) {
var value = Instance[k];
Pages.Instance[k] = value[l] || value.default || undefined;
});
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;
}());
// used for the about menu
Pages.imprintLink = footLink(customURLs.imprint, 'imprint');
Pages.privacyLink = footLink(customURLs.privacy, 'privacy');
Pages.termsLink = footLink(customURLs.terms, 'terms');
Pages.sourceLink = footLink(customURLs.source, 'footer_source');
Pages.docsLink = footLink('https://docs.cryptpad.org', 'docs_link');
Pages.roadmapLink = footLink(customURLs.roadmap, 'footer_roadmap');
2022-03-23 09:59:16 +00:00
Pages.infopageFooter = function () {
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-03-23 09:59:16 +00:00
return h('footer.cp-footer', [
h('div.cp-footer-left', [
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
]),
h('span.cp-footer-version', 'v' + Pages.versionString)
]),
h('div.cp-footer-center', [
h('div.cp-logo-btns', [
footLink('https://cryptpad.org', null, Msg.footer_website, 'link'),
donateButton,
])
2022-03-23 09:59:16 +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()
])
])
]);
};
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 {
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
]);
}
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'),
h('img', {
src: '/customize/CryptPad_logo.svg',
"aria-hidden": true,
alt: ''
}),
2022-05-06 10:10:44 +00:00
Msg.homePage
]);
2018-03-20 10:05:43 +00:00
return h('nav.navbar.navbar-expand-lg',
2022-03-30 10:19:35 +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
]),
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-06-21 16:02:38 +00:00
return Pages;
});