Ajaxify improvement, `/assets/uploads`

v1.18.x
Peter Jaszkowiak 8 years ago
parent 7ba111acdd
commit 8f27d7810b

@ -249,48 +249,37 @@ $(document).ready(function () {
$(window).trigger('action:script.load', data); $(window).trigger('action:script.load', data);
// Require and parse modules // Require and parse modules
var outstanding = 0; var outstanding = data.scripts.length;
var onReady = function () {
if (outstanding) { data.scripts.map(function (script) {
return setTimeout(onReady, 100); if (typeof script === 'function') {
return function (next) {
script();
next();
};
} }
if (typeof script === 'string') {
data.scripts = data.scripts.filter(Boolean); return function (next) {
data.scripts.forEach(function (functionRef) { require([script], function (script) {
functionRef(); if (script && script.init) {
}); script.init();
}
callback(); next();
}; }, function () {
// ignore 404 error
data.scripts.forEach(function (script, idx) { next();
switch (typeof script) { });
case 'string': };
++outstanding;
(function (idx) {
require([script], function (script) {
if (script && script.init) {
data.scripts[idx] = script.init;
} else {
data.scripts[idx] = null;
}
--outstanding;
});
}(idx));
break;
case 'function':
// No changes needed
break;
default:
// Neither? No comprende
data.scripts[idx] = undefined;
break;
} }
return null;
}).filter(Boolean).forEach(function (fn) {
fn(function () {
outstanding -= 1;
if (outstanding === 0) {
callback();
}
});
}); });
onReady();
}; };
ajaxify.loadData = function (url, callback) { ajaxify.loadData = function (url, callback) {

@ -365,7 +365,7 @@ Controllers.handle404 = function (req, res) {
if (isClientScript.test(req.url)) { if (isClientScript.test(req.url)) {
res.type('text/javascript').status(200).send(''); res.type('text/javascript').status(200).send('');
} else if (req.path.startsWith(relativePath + '/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') { } else if (req.path.startsWith(relativePath + '/assets/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') {
meta.errors.log404(req.path || ''); meta.errors.log404(req.path || '');
res.sendStatus(404); res.sendStatus(404);
} else if (req.accepts('html')) { } else if (req.accepts('html')) {

Loading…
Cancel
Save