Refactored and lots of modification. See README.md.

This commit is contained in:
Lars Jung 2012-04-16 12:53:54 +02:00
parent 859a680e19
commit 71ed41fa69
85 changed files with 3191 additions and 2969 deletions

View file

@ -0,0 +1,48 @@
module.define('parser/generic-json', [jQuery, 'core/settings', 'model/entry'], function ($, settings, Entry) {
// expectes an hash of the form
// {
// entries: [
// {absHref: String, time: Number, size: Number, status: Number or "h5ai"}
// ]
// }
var parseJson = function (absHref, json) {
_.each(json.entries, function (jsonEntry) {
Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status);
});
if (json.hasOwnProperty('customHeader')) {
settings.custom.header = json.customHeader;
}
if (json.hasOwnProperty('customFooter')) {
settings.custom.footer = json.customFooter;
}
},
parseJsonStr = function (absHref, jsonStr) {
return parseJson(absHref, JSON.parse($.trim(jsonStr) || '{}'));
},
parse = function (absHref, html) {
var id = '#data-generic-json',
$html = $(html),
$id = $html.filter(id);
if (!$id.length) {
$id = $html.find(id);
}
return parseJsonStr(absHref, $id.text());
};
return {
id: 'generic-json',
parse: parse
};
});