cryptpad/customize.dist/template.js

81 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-06-21 16:02:38 +00:00
define([
'jquery',
'/common/hyperscript.js',
'/customize/pages.js',
'/components/nthen/index.js',
2017-06-21 16:02:38 +00:00
'css!/components/components-font-awesome/css/font-awesome.min.css',
], function ($, h, Pages, nThen) {
2022-04-04 11:08:18 +00:00
// we consider that there is no valid reason to load any of the info pages
// in an iframe. abort everything if you detect that you are embedded.
if (window.top !== window) { return; }
2017-06-21 16:02:38 +00:00
$(function () {
var $body = $('body');
2017-06-22 09:06:11 +00:00
var pathname = location.pathname;
2018-03-20 09:44:26 +00:00
// add class on info-pages
var pageName = pathname.replace(/(index)?\.html$/gi, "") // .html
2018-03-20 09:44:26 +00:00
.replace(/[^a-zA-Z]+/gi, '-') // any non-alpha character
.replace(/^-|-$/g, ''); // starting/trailing dashes
if (pageName === '') { pageName = 'index'; }
$('body').addClass('cp-page-' + pageName);
var infoPage = function () {
return h('div#mainBlock.hidden', typeof(Pages[pathname]) === 'function'?
Pages[pathname](): [h('div#container')]);
};
2017-06-22 09:06:11 +00:00
2017-10-23 09:57:10 +00:00
window.Tether = function () {};
nThen(function (waitFor) {
var w = waitFor();
require([
'/customize/pages/' + pageName + '.js',
], function (Page) {
infoPage = Page;
w();
}, function () {
w();
});
}).nThen(function () {
require([
2023-07-13 13:36:48 +00:00
'/api/config',
'/common/common-util.js',
'optional!/api/instance',
'less!/customize/src/less2/pages/page-' + pageName + '.less',
'css!/components/bootstrap/dist/css/bootstrap.min.css',
2018-11-05 11:02:27 +00:00
'css!/customize/fonts/cptools/style.css'
2023-07-13 13:36:48 +00:00
], function (ApiConfig, Util, Instance) {
var $main = $(infoPage());
2023-07-13 13:36:48 +00:00
var titleSuffix = (Util.find(Instance, ['name','default']) || '').trim();
if (!titleSuffix || titleSuffix === ApiConfig.httpUnsafeOrigin) {
titleSuffix = window.location.hostname;
}
document.title = document.title + ' - ' + titleSuffix;
$('#placeholder').remove();
$body.append($main);
if (/^\/register\//.test(pathname)) {
require([ '/register/main.js' ], function () {});
2022-12-20 15:56:41 +00:00
} else if (/^\/install\//.test(pathname)) {
require([ '/install/main.js' ], function () {});
2023-05-15 15:33:58 +00:00
} else if (/^\/recovery\//.test(pathname)) {
require([ '/recovery/main.js' ], function () {});
2023-06-27 14:04:32 +00:00
} else if (/^\/ssoauth\//.test(pathname)) {
require([ '/ssoauth/main.js' ], function () {});
} else if (/^\/login\//.test(pathname)) {
require([ '/login/main.js' ], function () {});
} else if (/^\/($|^\/index\.html$)/.test(pathname)) {
require([ '/customize/main.js', ], function () {});
} else {
require([ '/customize/main.js', ], function () {});
}
});
});
});
});