cryptpad/customize.dist/pages.js

289 lines
9.6 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',
], function (h, Language, AppConfig, Msg, $, ApiConfig) {
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;
};
var footerCol = function (title, L, n) {
n = n || 3;
return h('div.col-sm-' + n, [
h('ul.list-unstyled', [
2017-08-04 15:44:02 +00:00
h('li.footer-title', {
'data-localization': title,
}, Msg[title])
].concat(L.map(function (l) {
return h('li', [ l ]);
}))
)
]);
};
var footLink = function (ref, loc, text) {
if (!ref) { return; }
var attrs = {
href: ref,
};
if (!/^\//.test(ref)) {
attrs.target = '_blank';
attrs.rel = 'noopener noreferrer';
}
if (loc) {
attrs['data-localization'] = loc;
text = Msg[loc];
}
return h('a', attrs, text);
};
2021-12-07 03:12:43 +00:00
Pages.versionString = "v4.13.0";
var customURLs = Pages.customURLs = {};
(function () {
var defaultURLs = {
//imprint: '/imprint.html',
//privacy: '/privacy.html',
terms: '/terms.html',
//roadmap: '/roadmap.html',
source: 'https://github.com/xwiki-labs/cryptpad',
};
var l = Msg._getLanguage();
['imprint', 'privacy', 'terms', 'roadmap', 'source'].forEach(function (k) {
var value = AppConfig[k];
if (value === false) { return; }
if (value === true) {
customURLs[k] = defaultURLs[k];
return;
}
if (!value) { return; }
if (typeof(value) === 'string') {
customURLs[k] = value;
return;
}
if (typeof(value) === 'object') {
customURLs[k] = value[l] || value['default'];
}
});
}());
// used for the about menu
Pages.imprintLink = footLink(customURLs.imprint, 'imprint');
Pages.privacyLink = footLink(customURLs.privacy, 'privacy');
Pages.termsLink = footLink(customURLs.terms, 'footer_tos');
Pages.sourceLink = footLink(customURLs.source, 'footer_source');
2020-10-26 14:35:39 +00:00
Pages.docsLink = footLink('https://docs.cryptpad.fr', 'docs_link');
Pages.roadmapLink = footLink(customURLs.roadmap, 'footer_roadmap');
Pages.infopageFooter = function () {
var legalFooter;
// only display the legal part of the footer if it has content
if (Pages.termsLink || Pages.privacyLink || Pages.imprintLink) {
legalFooter = footerCol('footer_legal', [
Pages.termsLink,
Pages.privacyLink,
Pages.imprintLink,
]);
}
var n = legalFooter ? 3: 4;
return h('footer', [
h('div.container', [
h('div.row', [
h('div.col-sm-' + n, [
2020-10-26 14:35:39 +00:00
h('div.cp-logo-foot', [
h('img', {
src: '/customize/CryptPad_logo.svg',
2020-11-05 11:04:04 +00:00
"aria-hidden": true,
alt: ''
2020-10-26 14:35:39 +00:00
}),
h('span.logo-font', 'CryptPad')
2017-08-16 08:51:08 +00:00
])
]),
footerCol('footer_product', [
footLink('/what-is-cryptpad.html', 'topbar_whatIsCryptpad'),
2020-10-26 14:35:39 +00:00
Pages.docsLink,
footLink('/features.html', Pages.areSubscriptionsAllowed()? 'pricing': 'features'), // Messages.pricing, Messages.features
Pages.sourceLink,
footLink('https://opencollective.com/cryptpad/contribute/', 'footer_donate'),
], n),
footerCol('footer_aboutUs', [
footLink('https://blog.cryptpad.fr/', 'blog'),
footLink('/contact.html', 'contact'),
2020-10-26 14:35:39 +00:00
footLink('https://github.com/xwiki-labs/cryptpad/wiki/Contributors', 'footer_team'),
footLink('http://www.xwiki.com', null, 'XWiki SAS'),
2021-04-20 11:01:57 +00:00
Pages.roadmapLink,
], n),
legalFooter,
])
]),
2020-10-26 14:35:39 +00:00
h('div.cp-version-footer', [
languageSelector(),
2020-10-29 15:26:41 +00:00
h('span', "CryptPad " + Pages.versionString)
2020-10-26 14:35:39 +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) {
registerLink = h('a.nav-item.nav-link.cp-register-btn', { href: '/register/'}, Msg.login_register);
}
2017-08-04 14:48:01 +00:00
if (username === null) {
rightLinks = [
h('a.nav-item.nav-link.cp-login-btn', { href: '/login/'}, 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/' }, [
2017-08-04 14:48:01 +00:00
h('i.fa.fa-user-circle'),
" ",
username
]);
}
2018-03-22 09:49:20 +00:00
var button = h('button.navbar-toggler', {
'type':'button',
/*'data-toggle':'collapse',
'data-target':'#menuCollapse',
'aria-controls': 'menuCollapse',
'aria-expanded':'false',
'aria-label':'Toggle navigation'*/
}, h('i.fa.fa-bars '));
$(button).click(function () {
if ($('#menuCollapse').is(':visible')) {
return void $('#menuCollapse').slideUp();
}
$('#menuCollapse').slideDown();
});
2018-03-20 10:05:43 +00:00
return h('nav.navbar.navbar-expand-lg',
h('a.navbar-brand', { href: '/index.html'}, [
2020-11-05 11:04:04 +00:00
h('img', {
src: '/customize/CryptPad_logo.svg?',
'aria-hidden': true,
alt: ''
}), 'CryptPad'
]),
2018-03-22 09:49:20 +00:00
button,
2018-03-20 10:05:43 +00:00
h('div.collapse.navbar-collapse.justify-content-end#menuCollapse', [
h('a.nav-item.nav-link', { href: '/what-is-cryptpad.html'}, Msg.about),
2020-11-19 20:30:21 +00:00
h('a.nav-item.nav-link', { href: 'https://docs.cryptpad.fr'}, Msg.docs_link),
2021-05-28 09:25:33 +00:00
h('a.nav-item.nav-link', { href: '/features.html'}, Pages.areSubscriptionsAllowed()? Msg.pricing: Msg.features),
2018-03-20 10:05:43 +00:00
].concat(rightLinks))
);
};
Pages.crowdfundingButton = function (onClick) {
var _link = h('a', {
href: "https://opencollective.com/cryptpad/",
target: '_blank',
rel: 'noopener',
});
var crowdFunding = h('button', [
Msg.crowdfunding_button
]);
$(crowdFunding).click(function () {
_link.click();
if (typeof(onClick) === 'function') { onClick(); }
});
return crowdFunding;
};
2021-01-21 13:35:16 +00:00
Pages.subscribeButton = function (onClick) {
var _link = h('a', {
href: AppConfig.upgradeURL || "/accounts/",
2021-01-21 13:35:16 +00:00
});
var subscribe = h('button', [
Msg.features_f_subscribe,
2021-01-21 13:35:16 +00:00
]);
$(subscribe).click(function () {
_link.click();
if (typeof(onClick) === 'function') { onClick(); }
});
return subscribe;
};
2017-06-21 16:02:38 +00:00
return Pages;
});