cryptpad/customize.dist/template.js

119 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-06-22 00:02:38 +08:00
define([
'jquery',
'/common/hyperscript.js',
'/customize/pages.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
2017-11-21 22:52:21 +08:00
], function ($, h, Pages) {
2017-06-22 00:02:38 +08:00
$(function () {
var $body = $('body');
var isMainApp = function () {
2017-08-25 22:07:53 +08:00
return /^\/(pad|code|slide|poll|whiteboard|file|media|contacts|drive|settings|profile|todo)\/$/.test(location.pathname);
};
2017-06-22 00:02:38 +08:00
2017-06-22 17:06:11 +08:00
var infoPage = function () {
return h('div#mainBlock.hidden', typeof(Pages[location.pathname]) === 'function'?
Pages[location.pathname](): [h('div#container')]);
};
var $main = $(infoPage());
2017-06-22 00:02:38 +08:00
2017-06-22 17:06:11 +08:00
var pathname = location.pathname;
if (isMainApp()) {
if (typeof(Pages[pathname]) === 'function') {
2017-06-30 22:20:10 +08:00
var $flash = $('body, #iframe-container, #pad-iframe, textarea');
2017-06-30 22:10:42 +08:00
$flash.css({
2017-06-30 22:20:10 +08:00
display: 'none',
opacity: 0,
overflow: 'hidden',
2017-06-30 22:10:42 +08:00
});
2017-06-30 22:20:10 +08:00
var ready = function () {
$flash.css({
display: '',
opacity: '',
overflow: '',
});
};
2017-06-30 22:10:42 +08:00
2017-06-28 00:17:52 +08:00
require([
2017-09-13 22:19:26 +08:00
'less!/customize/src/less2/loading.less'
2017-06-28 00:17:52 +08:00
], function () {
if (/whiteboard/.test(pathname)) {
$('body').html(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require(['/whiteboard/main.js'], ready);
2017-06-28 00:17:52 +08:00
} else if (/poll/.test(pathname)) {
$('body').html(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require(['/poll/main.js'], ready);
2017-06-28 00:17:52 +08:00
} else if (/drive/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require(['/drive/main.js'], ready);
2017-07-13 00:34:16 +08:00
} else if (/\/file\//.test(pathname)) {
2017-06-28 00:17:52 +08:00
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require([ '/file/main.js' ], ready);
} else if (/^\/contacts\/$/.test(pathname)) {
2017-07-07 00:00:03 +08:00
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-07-17 23:18:28 +08:00
require([ '/contacts/main.js' ], ready);
2017-06-28 00:17:52 +08:00
} else if (/pad/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require([ '/pad/main.js' ], ready);
2017-06-28 00:17:52 +08:00
} else if (/code/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require([ '/code/main.js' ], ready);
2017-06-28 00:17:52 +08:00
} else if (/slide/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 22:10:42 +08:00
require([ '/slide/main.js' ], ready);
2017-07-11 00:29:23 +08:00
} else if (/^\/settings\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/settings/main.js', ], ready);
2017-07-13 00:34:16 +08:00
} else if (/^\/profile\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/profile/main.js', ], ready);
2017-07-23 20:27:47 +08:00
} else if (/^\/todo\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/todo/main.js', ], ready);
2017-06-28 00:17:52 +08:00
}
});
return;
}
2017-08-04 20:50:35 +08:00
} else {
// add class on info-pages
var css = location.pathname.replace(/(index)?\.html$/gi, "") // .html
.replace(/[^a-zA-Z]+/gi, '-') // any non-alpha character
.replace(/^-|-$/g, ''); // starting/trailing dashes
2017-08-04 20:50:35 +08:00
if (css === '')
{
css = 'index';
}
$('body').addClass('cp-page-' + css);
2017-06-22 17:06:11 +08:00
}
2017-10-23 17:57:10 +08:00
window.Tether = function () {};
require([
2017-07-22 22:43:53 +08:00
'less!/customize/src/less2/main.less',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
'/bower_components/bootstrap/dist/js/bootstrap.min.js'
], function () {
$body.append($main);
2017-07-13 00:34:16 +08:00
if (/^\/user\//.test(pathname)) {
require([ '/user/main.js'], function () {});
} else if (/^\/register\//.test(pathname)) {
require([ '/register/main.js' ], function () {});
} else if (/^\/login\//.test(pathname)) {
require([ '/login/main.js' ], function () {});
} else if (/^\/($|^\/index\.html$)/.test(pathname)) {
// TODO use different top bar
require([ '/customize/main.js', ], function () {});
2017-07-05 22:01:50 +08:00
} else if (/invite/.test(pathname)) {
require([ '/invite/main.js'], function () {});
2018-03-13 18:31:08 +08:00
} else if (/faq/.test(pathname)) {
window.location.hash = window.location.hash;
} else {
require([ '/customize/main.js', ], function () {});
}
});
});
});