cryptpad/customize.dist/template.js

117 lines
4.7 KiB
JavaScript
Raw Normal View History

2017-06-21 16:02:38 +00:00
define([
'jquery',
'/common/hyperscript.js',
'/customize/pages.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
2017-11-21 14:52:21 +00:00
], function ($, h, Pages) {
2017-06-21 16:02:38 +00:00
$(function () {
var $body = $('body');
var isMainApp = function () {
2017-08-25 14:07:53 +00:00
return /^\/(pad|code|slide|poll|whiteboard|file|media|contacts|drive|settings|profile|todo)\/$/.test(location.pathname);
};
2017-06-21 16:02:38 +00:00
2017-06-22 09:06:11 +00: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-21 16:02:38 +00:00
2017-06-22 09:06:11 +00:00
var pathname = location.pathname;
if (isMainApp()) {
if (typeof(Pages[pathname]) === 'function') {
2017-06-30 14:20:10 +00:00
var $flash = $('body, #iframe-container, #pad-iframe, textarea');
2017-06-30 14:10:42 +00:00
$flash.css({
2017-06-30 14:20:10 +00:00
display: 'none',
opacity: 0,
overflow: 'hidden',
2017-06-30 14:10:42 +00:00
});
2017-06-30 14:20:10 +00:00
var ready = function () {
$flash.css({
display: '',
opacity: '',
overflow: '',
});
};
2017-06-30 14:10:42 +00:00
2017-06-27 16:17:52 +00:00
require([
2017-09-13 14:19:26 +00:00
'less!/customize/src/less2/loading.less'
2017-06-27 16:17:52 +00:00
], function () {
if (/whiteboard/.test(pathname)) {
$('body').html(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require(['/whiteboard/main.js'], ready);
2017-06-27 16:17:52 +00:00
} else if (/poll/.test(pathname)) {
$('body').html(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require(['/poll/main.js'], ready);
2017-06-27 16:17:52 +00:00
} else if (/drive/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require(['/drive/main.js'], ready);
2017-07-12 16:34:16 +00:00
} else if (/\/file\//.test(pathname)) {
2017-06-27 16:17:52 +00:00
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require([ '/file/main.js' ], ready);
} else if (/^\/contacts\/$/.test(pathname)) {
2017-07-06 16:00:03 +00:00
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-07-17 15:18:28 +00:00
require([ '/contacts/main.js' ], ready);
2017-06-27 16:17:52 +00:00
} else if (/pad/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require([ '/pad/main.js' ], ready);
2017-06-27 16:17:52 +00:00
} else if (/code/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require([ '/code/main.js' ], ready);
2017-06-27 16:17:52 +00:00
} else if (/slide/.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
2017-06-30 14:10:42 +00:00
require([ '/slide/main.js' ], ready);
2017-07-10 16:29:23 +00:00
} else if (/^\/settings\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/settings/main.js', ], ready);
2017-07-12 16:34:16 +00:00
} else if (/^\/profile\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/profile/main.js', ], ready);
2017-07-23 12:27:47 +00:00
} else if (/^\/todo\//.test(pathname)) {
$('body').append(h('body', Pages[pathname]()).innerHTML);
require([ '/todo/main.js', ], ready);
2017-06-27 16:17:52 +00:00
}
});
return;
}
2017-08-04 12:50:35 +00: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 12:50:35 +00:00
if (css === '')
{
css = 'index';
}
$('body').addClass('cp-page-' + css);
2017-06-22 09:06:11 +00:00
}
2017-10-23 09:57:10 +00:00
window.Tether = function () {};
require([
2017-07-22 14:43:53 +00: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-12 16:34:16 +00: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 14:01:50 +00:00
} else if (/invite/.test(pathname)) {
require([ '/invite/main.js'], function () {});
} else {
require([ '/customize/main.js', ], function () {});
}
});
});
});