Cleans code.

This commit is contained in:
Lars Jung 2012-10-17 00:17:22 +02:00
parent 70f4500232
commit 396bc6662f
7 changed files with 12 additions and 87 deletions

View file

@ -1,47 +1,12 @@
modulejs.define('core/entry', ['_', '$', 'core/format', 'model/entry'], function (_, $, format, Entry) {
modulejs.define('core/entry', ['_', 'config', 'model/entry'], function (_, config, Entry) {
var parseGenericJson = function (absHref, $container) {
_.each(config.entries || [], function (entry) {
return JSON.parse($.trim($container.text()) || '{}').entries;
},
Entry.get(entry.absHref, entry.time, entry.size, entry.status, entry.content);
});
parseApacheTable = function (absHref, $table) {
return _.compact(_.map($table.find('td').closest('tr'), function (tr) {
var $tds = $(tr).find('td'),
$a = $tds.eq(1).find('a');
return $a.text() === 'Parent Directory' ? null : {
absHref: absHref + $a.attr('href'),
time: format.parseDate($tds.eq(2).text(), ['YYYY-MM-DD HH:mm', 'DD-MMM-YYYY HH:mm']),
size: format.parseSize($tds.eq(3).text())
};
}));
},
parse = function (absHref, $html) {
var $generic = $html.find('#data-generic-json'),
$apache = $html.find('#data-apache-autoindex table'),
json = [];
if ($generic.length) {
json = parseGenericJson(absHref, $generic);
} else if ($apache.length) {
json = parseApacheTable(absHref, $apache);
}
return _.map(json, function (entry) {
return Entry.get(entry.absHref, entry.time, entry.size, entry.status, entry.content);
});
},
entry = Entry.get();
parse(entry.absHref, $('body'));
var entry = Entry.get();
entry.status = '=h5ai=';
return entry;

View file

@ -31,9 +31,7 @@
// @include "inc/**/*.js"
var $ = jQuery,
filename = 'client/js/scripts.js',
$script = $('script[src$="' + filename + '"]'),
mode = $script.data('mode');
mode = $('script[src$="scripts.js"]').data('mode');
if (mode === 'info') {
@ -41,7 +39,7 @@
} else {
$.getJSON('.', {action: 'get', options: true, types: true, langs: true, server: true}, function (config) {
$.getJSON('.', {action: 'get', options: true, types: true, langs: true, server: true, entries: true}, function (config) {
modulejs.define('config', config);
$(function () { modulejs.require('main'); });