mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Adds ajax abstraction. Refactors global dependencies.
This commit is contained in:
parent
018a574d5e
commit
64640ada83
31 changed files with 245 additions and 167 deletions
|
@ -16,13 +16,6 @@
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
"predef": [
|
"predef": [
|
||||||
"amplify",
|
"modulejs"
|
||||||
"Base64",
|
|
||||||
"H5AI_CONFIG",
|
|
||||||
"jQuery",
|
|
||||||
"Modernizr",
|
|
||||||
"modulejs",
|
|
||||||
"moment",
|
|
||||||
"_"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
157
src/_h5ai/js/inc/core/ajax.js
Normal file
157
src/_h5ai/js/inc/core/ajax.js
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
|
||||||
|
modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], function ($, amplify, base64, resource) {
|
||||||
|
|
||||||
|
var reContentType = /^text\/html;h5ai=/,
|
||||||
|
|
||||||
|
getStatus = function (href, withContent, callback) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: href,
|
||||||
|
type: withContent ? 'GET' : 'HEAD',
|
||||||
|
complete: function (xhr) {
|
||||||
|
|
||||||
|
var res = {
|
||||||
|
status: xhr.status,
|
||||||
|
content: xhr.responseText
|
||||||
|
};
|
||||||
|
|
||||||
|
if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
|
||||||
|
res.status = 'h5ai';
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getChecks = function (callback) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: resource.api(),
|
||||||
|
data: {
|
||||||
|
action: 'getchecks'
|
||||||
|
},
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (json) {
|
||||||
|
|
||||||
|
callback(json);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getArchive = function (data, callback) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: resource.api(),
|
||||||
|
data: {
|
||||||
|
action: 'archive',
|
||||||
|
execution: data.execution,
|
||||||
|
format: data.format,
|
||||||
|
hrefs: data.hrefs
|
||||||
|
},
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
beforeSend: function (xhr) {
|
||||||
|
|
||||||
|
if (data.user) {
|
||||||
|
xhr.setRequestHeader('Authorization', 'Basic ' + base64.encode(data.user + ':' + data.password));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function (json) {
|
||||||
|
|
||||||
|
callback(json);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getThumbSrc = function (data, callback) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: resource.api(),
|
||||||
|
data: {
|
||||||
|
action: 'getthumbsrc',
|
||||||
|
type: data.type,
|
||||||
|
href: data.href,
|
||||||
|
mode: data.mode,
|
||||||
|
width: data.width,
|
||||||
|
height: data.height
|
||||||
|
},
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (json) {
|
||||||
|
|
||||||
|
if (json.code === 0) {
|
||||||
|
callback(json.absHref);
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getThumbSrcSmall = function (type, href, callback) {
|
||||||
|
|
||||||
|
getThumbSrc(
|
||||||
|
{
|
||||||
|
type: type,
|
||||||
|
href: href,
|
||||||
|
mode: 'square',
|
||||||
|
width: 16,
|
||||||
|
height: 16
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
getThumbSrcBig = function (type, href, callback) {
|
||||||
|
|
||||||
|
getThumbSrc(
|
||||||
|
{
|
||||||
|
type: type,
|
||||||
|
href: href,
|
||||||
|
mode: 'rational',
|
||||||
|
width: 100,
|
||||||
|
height: 48
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
getHtml = function (url, callback) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
dataType: 'html',
|
||||||
|
success: function (html) {
|
||||||
|
|
||||||
|
callback(html);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
getStatus: getStatus,
|
||||||
|
getChecks: getChecks,
|
||||||
|
getArchive: getArchive,
|
||||||
|
getThumbSrcSmall: getThumbSrcSmall,
|
||||||
|
getThumbSrcBig: getThumbSrcBig,
|
||||||
|
getHtml: getHtml
|
||||||
|
};
|
||||||
|
});
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('core/entry', ['jQuery', 'core/parser', 'model/entry'], function ($, parser, Entry) {
|
modulejs.define('core/entry', ['$', 'core/parser', 'model/entry'], function ($, parser, Entry) {
|
||||||
|
|
||||||
var absHref = document.location.pathname.replace(/[^\/]*$/, '');
|
var absHref = document.location.pathname.replace(/[^\/]*$/, '');
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('core/format', ['moment'], function (moment) {
|
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
|
|
||||||
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
|
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
|
||||||
treshhold = 1000.0,
|
treshhold = 1000.0,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('core/parser', ['jQuery'], function ($) {
|
modulejs.define('core/parser', ['$'], function ($) {
|
||||||
|
|
||||||
if ($('#data-apache-autoindex').length) {
|
if ($('#data-apache-autoindex').length) {
|
||||||
return modulejs.require('parser/apache-autoindex');
|
return modulejs.require('parser/apache-autoindex');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('core/settings', ['H5AI_CONFIG'], function (config) {
|
modulejs.define('core/settings', ['config', '_'], function (config, _) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
rootAbsHref: '/',
|
rootAbsHref: '/',
|
||||||
|
@ -12,7 +12,7 @@ modulejs.define('core/settings', ['H5AI_CONFIG'], function (config) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
modulejs.define('core/types', ['H5AI_CONFIG'], function (config) {
|
modulejs.define('core/types', ['config', '_'], function (config, _) {
|
||||||
|
|
||||||
var reEndsWithSlash = /\/$/,
|
var reEndsWithSlash = /\/$/,
|
||||||
reStartsWithDot = /^\./,
|
reStartsWithDot = /^\./,
|
||||||
|
@ -61,7 +61,7 @@ modulejs.define('core/types', ['H5AI_CONFIG'], function (config) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
modulejs.define('core/langs', ['H5AI_CONFIG'], function (config) {
|
modulejs.define('core/langs', ['config', '_'], function (config, _) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
lang: 'unknown',
|
lang: 'unknown',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/crumb', ['jQuery', 'core/settings', 'core/resource', 'core/entry'], function ($, allsettings, resource, entry) {
|
modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/entry'], function (_, $, allsettings, resource, entry) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/custom', ['jQuery', 'core/settings'], function ($, allsettings) {
|
modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/ajax'], function (_, $, allsettings, ajax) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -16,23 +16,19 @@ modulejs.define('ext/custom', ['jQuery', 'core/settings'], function ($, allsetti
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(settings.header)) {
|
if (_.isString(settings.header)) {
|
||||||
$.ajax({
|
ajax.getHtml(settings.header, function (html) {
|
||||||
url: settings.header,
|
|
||||||
dataType: 'html',
|
|
||||||
success: function (data) {
|
|
||||||
|
|
||||||
$('<div id="content-header">' + data + '</div>').prependTo('#content');
|
if (html) {
|
||||||
|
$('<div id="content-header">' + html + '</div>').prependTo('#content');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(settings.footer)) {
|
if (_.isString(settings.footer)) {
|
||||||
$.ajax({
|
ajax.getHtml(settings.footer, function (html) {
|
||||||
url: settings.footer,
|
|
||||||
dataType: 'html',
|
|
||||||
success: function (data) {
|
|
||||||
|
|
||||||
$('<div id="content-footer">' + data + '</div>').appendTo('#content');
|
if (html) {
|
||||||
|
$('<div id="content-footer">' + html + '</div>').appendTo('#content');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/download', ['jQuery', 'core/settings', 'core/resource', 'core/event'], function ($, allsettings, resource, event) {
|
modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/ajax'], function (_, $, allsettings, resource, event, ajax) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -33,19 +33,19 @@ modulejs.define('ext/download', ['jQuery', 'core/settings', 'core/resource', 'co
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleResponse = function (response) {
|
handleResponse = function (json) {
|
||||||
|
|
||||||
$download.removeClass('current');
|
$download.removeClass('current');
|
||||||
$img.attr('src', resource.image('download'));
|
$img.attr('src', resource.image('download'));
|
||||||
|
|
||||||
if (response) {
|
if (json) {
|
||||||
if (response.code === 0) {
|
if (json.code === 0) {
|
||||||
setTimeout(function () { // wait here so the img above can be updated in time
|
setTimeout(function () { // wait here so the img above can be updated in time
|
||||||
|
|
||||||
window.location = resource.api() + '?action=getarchive&id=' + response.id + '&as=h5ai-selection.' + settings.format;
|
window.location = resource.api() + '?action=getarchive&id=' + json.id + '&as=h5ai-selection.' + settings.format;
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
if (response.code === 401) {
|
if (json.code === 401) {
|
||||||
$downloadAuth
|
$downloadAuth
|
||||||
.css({
|
.css({
|
||||||
left: $download.offset().left,
|
left: $download.offset().left,
|
||||||
|
@ -65,34 +65,13 @@ modulejs.define('ext/download', ['jQuery', 'core/settings', 'core/resource', 'co
|
||||||
|
|
||||||
$download.addClass('current');
|
$download.addClass('current');
|
||||||
$img.attr('src', resource.image('loading.gif', true));
|
$img.attr('src', resource.image('loading.gif', true));
|
||||||
$.ajax({
|
ajax.getArchive({
|
||||||
url: resource.api(),
|
execution: settings.execution,
|
||||||
data: {
|
format: settings.format,
|
||||||
action: 'archive',
|
hrefs: hrefsStr,
|
||||||
execution: settings.execution,
|
user: $downloadUser.val(),
|
||||||
format: settings.format,
|
password: $downloadPassword.val()
|
||||||
hrefs: hrefsStr
|
}, handleResponse);
|
||||||
},
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
beforeSend: function (xhr) {
|
|
||||||
|
|
||||||
var user = $downloadUser.val(),
|
|
||||||
password = $downloadPassword.val();
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
xhr.setRequestHeader('Authorization', 'Basic ' + Base64.encode(user + ':' + password));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
success: function (response) {
|
|
||||||
|
|
||||||
handleResponse(response);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
handleResponse();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onSelection = function (entries) {
|
onSelection = function (entries) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/filter', ['jQuery', 'core/settings', 'core/resource'], function ($, allsettings, resource) {
|
modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource'], function (_, $, allsettings, resource) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/folderstatus', ['jQuery', 'core/settings'], function ($, allsettings) {
|
modulejs.define('ext/folderstatus', ['_', 'core/settings'], function (_, allsettings) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/l10n', ['jQuery', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event'], function ($, allsettings, langs, format, store, event) {
|
modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event'], function (_, $, allsettings, langs, format, store, event) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/link-hover-states', ['jQuery', 'core/settings'], function ($, allsettings) {
|
modulejs.define('ext/link-hover-states', ['_', '$', 'core/settings'], function (_, $, allsettings) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/mode', ['jQuery', 'core/settings', 'core/parser'], function ($, allsettings, parser) {
|
modulejs.define('ext/mode', ['_', '$', 'core/settings', 'core/parser'], function (_, $, allsettings, parser) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/preview-img', ['jQuery', 'core/settings', 'core/resource', 'core/store', 'core/entry'], function ($, allsettings, resource, store, entry) {
|
modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/entry'], function (_, $, allsettings, resource, store, entry) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/qrcode', ['jQuery', 'core/settings', 'core/event'], function ($, allsettings, event) {
|
modulejs.define('ext/qrcode', ['_', '$', 'modernizr', 'core/settings', 'core/event'], function (_, $, modernizr, allsettings, event) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -15,7 +15,7 @@ modulejs.define('ext/qrcode', ['jQuery', 'core/settings', 'core/event'], functio
|
||||||
update = function (entry) {
|
update = function (entry) {
|
||||||
|
|
||||||
$context.find('.qrcode').empty().qrcode({
|
$context.find('.qrcode').empty().qrcode({
|
||||||
render: Modernizr.canvas ? 'canvas' : 'div',
|
render: modernizr.canvas ? 'canvas' : 'div',
|
||||||
width: settings.size,
|
width: settings.size,
|
||||||
height: settings.size,
|
height: settings.size,
|
||||||
color: '#333',
|
color: '#333',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/select', ['jQuery', 'core/settings', 'core/event'], function ($, allsettings, event) {
|
modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/event'], function (_, $, allsettings, event) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/sort', ['jQuery', 'core/settings', 'core/resource', 'core/store'], function ($, allsettings, resource, store) {
|
modulejs.define('ext/sort', ['_', '$', 'core/settings', 'core/resource', 'core/store'], function (_, $, allsettings, resource, store) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/statusbar', ['jQuery', 'core/settings', 'core/format', 'core/event', 'core/entry'], function ($, allsettings, format, event, entry) {
|
modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'core/event', 'core/entry'], function (_, $, allsettings, format, event, entry) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/thumbnails', ['jQuery', 'core/settings', 'core/resource', 'core/entry'], function ($, allsettings, resource, entry) {
|
modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/ajax'], function (_, allsettings, entry, ajax) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -11,46 +11,32 @@ modulejs.define('ext/thumbnails', ['jQuery', 'core/settings', 'core/resource', '
|
||||||
|
|
||||||
settings = _.extend({}, defaults, allsettings.thumbnails),
|
settings = _.extend({}, defaults, allsettings.thumbnails),
|
||||||
|
|
||||||
requestThumb = function ($img, data) {
|
|
||||||
|
|
||||||
$.getJSON(resource.api(), data, function (json) {
|
|
||||||
|
|
||||||
if (json.code === 0) {
|
|
||||||
$img.addClass('thumb').attr('src', json.absHref);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
checkEntry = function (entry) {
|
checkEntry = function (entry) {
|
||||||
|
|
||||||
if (entry.$extended) {
|
if (entry.$extended) {
|
||||||
|
|
||||||
var type = null;
|
var type = null;
|
||||||
|
|
||||||
if ($.inArray(entry.type, settings.img) >= 0) {
|
if (_.indexOf(settings.img, entry.type) >= 0) {
|
||||||
type = 'img';
|
type = 'img';
|
||||||
} else if ($.inArray(entry.type, settings.mov) >= 0) {
|
} else if (_.indexOf(settings.mov, entry.type) >= 0) {
|
||||||
type = 'mov';
|
type = 'mov';
|
||||||
} else if ($.inArray(entry.type, settings.doc) >= 0) {
|
} else if (_.indexOf(settings.doc, entry.type) >= 0) {
|
||||||
type = 'doc';
|
type = 'doc';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
requestThumb(entry.$extended.find('.icon.small img'), {
|
ajax.getThumbSrcSmall(type, entry.absHref, function (src) {
|
||||||
action: 'getthumbsrc',
|
|
||||||
type: type,
|
if (src) {
|
||||||
href: entry.absHref,
|
entry.$extended.find('.icon.small img').addClass('thumb').attr('src', src);
|
||||||
mode: 'square',
|
}
|
||||||
width: 16,
|
|
||||||
height: 16
|
|
||||||
});
|
});
|
||||||
requestThumb(entry.$extended.find('.icon.big img'), {
|
ajax.getThumbSrcBig(type, entry.absHref, function (src) {
|
||||||
action: 'getthumbsrc',
|
|
||||||
type: type,
|
if (src) {
|
||||||
href: entry.absHref,
|
entry.$extended.find('.icon.big img').addClass('thumb').attr('src', src);
|
||||||
mode: 'rational',
|
}
|
||||||
width: 100,
|
|
||||||
height: 48
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/title', ['jQuery', 'core/settings', 'core/entry'], function ($, allsettings, entry) {
|
modulejs.define('ext/title', ['_', 'core/settings', 'core/entry'], function (_, allsettings, entry) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/tree', ['jQuery', 'core/settings', 'core/resource', 'core/event', 'core/entry', 'core/parser'], function ($, allsettings, resource, event, entry, parser) {
|
modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry', 'core/parser'], function (_, $, allsettings, resource, event, entry, parser) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('h5ai-info', ['jQuery', 'core/resource'], function ($, resource) {
|
modulejs.define('h5ai-info', ['$', 'core/ajax'], function ($, ajax) {
|
||||||
|
|
||||||
var setCheckResult = function (id, result) {
|
var setCheckResult = function (id, result) {
|
||||||
|
|
||||||
|
@ -12,37 +12,17 @@ modulejs.define('h5ai-info', ['jQuery', 'core/resource'], function ($, resource)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleChecksResponse = function (response) {
|
|
||||||
|
|
||||||
$('.test').each(function () {
|
|
||||||
|
|
||||||
setCheckResult(this, response && response[$(this).data('id')]);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
checks = function () {
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: resource.api(),
|
|
||||||
data: {
|
|
||||||
action: 'getchecks'
|
|
||||||
},
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
success: function (response) {
|
|
||||||
|
|
||||||
handleChecksResponse(response);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
handleChecksResponse();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
init = function () {
|
init = function () {
|
||||||
|
|
||||||
checks();
|
ajax.getChecks(function (json) {
|
||||||
|
|
||||||
|
if (json) {
|
||||||
|
$('.test').each(function () {
|
||||||
|
|
||||||
|
setCheckResult(this, json[$(this).data('id')]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('h5ai-main', ['jQuery', 'core/event', 'core/settings'], function ($, event, settings) {
|
modulejs.define('h5ai-main', ['_', 'core/event', 'core/settings'], function (_, event, settings) {
|
||||||
|
|
||||||
event.pub('beforeView');
|
event.pub('beforeView');
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
// @include "core/ajax.js"
|
||||||
// @include "core/entry.js"
|
// @include "core/entry.js"
|
||||||
// @include "core/event.js"
|
// @include "core/event.js"
|
||||||
// @include "core/format.js"
|
// @include "core/format.js"
|
||||||
|
@ -42,21 +43,19 @@
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
/*global H5AI_CONFIG, amplify, Base64, jQuery, Modernizr, moment, _ */
|
||||||
|
|
||||||
// define it on doc ready, so the script order in the doc doesn't matter
|
// Register predefined globals on doc ready, so the script order inside
|
||||||
modulejs.define('H5AI_CONFIG', H5AI_CONFIG);
|
// the document doesn't matter. `jQuery`, `moment` and `underscore` are
|
||||||
|
// itself functions, so they have to be wrapped to not be handled as
|
||||||
|
// constructors.
|
||||||
|
modulejs.define('config', H5AI_CONFIG);
|
||||||
modulejs.define('amplify', amplify);
|
modulejs.define('amplify', amplify);
|
||||||
|
modulejs.define('base64', Base64);
|
||||||
// `jQuery` and `moment` are itself functions, so they have to be wrapped
|
modulejs.define('$', function () { return jQuery; });
|
||||||
// to not be taken as a constructor
|
modulejs.define('modernizr', Modernizr);
|
||||||
modulejs.define('jQuery', function () {
|
modulejs.define('moment', function () { return moment; });
|
||||||
|
modulejs.define('_', function () { return _; });
|
||||||
return jQuery;
|
|
||||||
});
|
|
||||||
modulejs.define('moment', function () {
|
|
||||||
|
|
||||||
return moment;
|
|
||||||
});
|
|
||||||
|
|
||||||
modulejs.require($('body').attr('id'));
|
modulejs.require($('body').attr('id'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('model/entry', ['jQuery', 'core/types'], function ($, types) {
|
modulejs.define('model/entry', ['_', 'core/types', 'core/ajax'], function (_, types, ajax) {
|
||||||
|
|
||||||
var domain = document.domain,
|
var domain = document.domain,
|
||||||
location = document.location.pathname.replace(/[^\/]*$/, ''),
|
location = document.location.pathname.replace(/[^\/]*$/, ''),
|
||||||
|
@ -56,25 +56,13 @@ modulejs.define('model/entry', ['jQuery', 'core/types'], function ($, types) {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
reContentType = /^text\/html;h5ai=/,
|
|
||||||
|
|
||||||
ajaxRequest = function (self, parser, callback) {
|
ajaxRequest = function (self, parser, callback) {
|
||||||
|
|
||||||
$.ajax({
|
ajax.getStatus(self.absHref, parser, function (response) {
|
||||||
url: self.absHref,
|
|
||||||
type: parser ? 'GET' : 'HEAD',
|
|
||||||
complete: function (xhr) {
|
|
||||||
|
|
||||||
if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
|
self.status = response.status;
|
||||||
self.status = 'h5ai';
|
if (parser && response.status === 'h5ai') {
|
||||||
if (parser) {
|
parser.parse(self.absHref, response.content);
|
||||||
parser.parse(self.absHref, xhr.responseText);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.status = xhr.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(self);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('parser/apache-autoindex', ['jQuery', 'core/settings', 'core/format', 'model/entry'], function ($, settings, format, Entry) {
|
modulejs.define('parser/apache-autoindex', ['_', '$', 'core/settings', 'core/format', 'model/entry'], function (_, $, settings, format, Entry) {
|
||||||
|
|
||||||
var parseTableRow = function (absHref, tr) {
|
var parseTableRow = function (absHref, tr) {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('parser/generic-json', ['jQuery', 'core/settings', 'model/entry'], function ($, settings, Entry) {
|
modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'], function (_, $, settings, Entry) {
|
||||||
|
|
||||||
var parser = {
|
var parser = {
|
||||||
id: 'generic-json',
|
id: 'generic-json',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('view/extended', ['jQuery', 'core/settings', 'core/resource', 'core/format', 'core/event', 'core/entry'], function ($, allsettings, resource, format, event, entry) {
|
modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'core/format', 'core/event', 'core/entry'], function (_, $, allsettings, resource, format, event, entry) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
modes: ['details', 'icons'],
|
modes: ['details', 'icons'],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('view/spacing', ['jQuery', 'core/settings', 'core/event'], function ($, allsettings, event) {
|
modulejs.define('view/spacing', ['_', '$', 'core/settings', 'core/event'], function (_, $, allsettings, event) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
maxWidth: 960,
|
maxWidth: 960,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('view/viewmode', ['jQuery', 'core/settings', 'core/resource', 'core/store'], function ($, allsettings, resource, store) {
|
modulejs.define('view/viewmode', ['_', '$', 'core/settings', 'core/resource', 'core/store'], function (_, $, allsettings, resource, store) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
modes: ['details', 'list', 'icons'],
|
modes: ['details', 'list', 'icons'],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue