arrow-admin
Version:
Arrow Admin Website
85 lines (78 loc) • 3.39 kB
JavaScript
define(['jquery', 'toc'], function ($, TOC) {
return function (src, enablePartialLoads, callback) {
if (!callback) {
callback = enablePartialLoads;
enablePartialLoads = false;
}
var isCMS = src === 'cms';
var loadingHTML = '<div id="loader"><i class="icon-spin5 animate-spin"></i> Loading...</div>';
$('#mainContent').html(loadingHTML).load(src, loaded);
if (enablePartialLoads) {
$('#nav-secondary').on('click', 'a', function (evt) {
var href = $(this).attr('href'),
page = isCMS ? src : href.replace('.html?', '/');
history.pushState({href: href}, '', href);
if (!isCMS) { TOC.reRenderMenu(); }
$('#mainContent').html(loadingHTML).load(page, loaded);
evt.preventDefault();
});
window.onpopstate = function () {
var href = window.location.pathname.split('/').pop() + (window.location.search || ''),
page = isCMS ? src : (window.location.search ? href.replace('.html?', '/') : href.split('.')[0]);
if (!isCMS) { TOC.reRenderMenu(); }
$('#mainContent').html(loadingHTML).load(page, loaded);
};
}
function loaded(response, status, xhr) {
var content = $('#mainContent'),
body = $('body');
if (status === 'error') {
body.addClass('error-tpl');
content.removeClass('panel content');
var html = [];
html.push('<section class="text-center center-block">');
if (xhr.status === 404) {
html.push('<h1><i class="icon-404_link"></i>404</h1>');
html.push('<hr>');
html.push('<p class="txt-spaced txt-16 txt-medgray">The resource you requested cannot be not found.</p>');
html.push('<hr>');
html.push('<p class="txt-left txt-14 txt-medgray">');
html.push('Check your URL. It could be that the URL was entered incorrectly or, when you pasted the URL into your browser, it was malformed.');
}
else {
html.push('<h1>' + xhr.status + '</h1>');
html.push('<hr>');
html.push('<p class="txt-spaced txt-16 txt-medgray">' + xhr.statusText + '</p>');
html.push('<hr>');
html.push('<p class="txt-left txt-14 txt-medgray">');
}
html.push('It could also be that we have gotten something wrong and have an issue.');
html.push('If you are still having problems with the URL, you can reach us at <a href="mailto:appc.support@appcelerator.com">appc.support@appcelerator.com</a>, and we will be glad to see what we can do to assist.');
html.push('</p>');
html.push('<hr> ');
html.push('<ul class="mg-top-l list-unstyled txt-spaced">');
html.push('<li><a class="txt-14" href="/">Dashboard</a></li>');
html.push('<li><a class="txt-14" href="http://status.appcelerator.com">Status</a></li>');
html.push('<li><a class="txt-14" href="http://support2.appcelerator.com/">Support</a></li>');
html.push('</ul>');
html.push('</section>');
content.html(html.join('\n'));
}
else {
body.removeClass('error-tpl');
content.addClass('panel content');
// join together blockquote and code as one big block
$('blockquote.unformat + pre.highlight').prev().addClass('noborder');
$('blockquote.unformat + pre.highlight div.toolbar').each(function () {
var el = $(this).parent('pre.highlight').prev('blockquote.unformat');
// move it to the blockquote
el.append($(this));
});
body.trigger('contentloaded');
if (callback) {
callback();
}
}
}
};
});