mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Refactored and lots of modification. See README.md.
This commit is contained in:
parent
859a680e19
commit
71ed41fa69
85 changed files with 3191 additions and 2969 deletions
48
src/_h5ai/js/inc/parser/generic-json.js
Normal file
48
src/_h5ai/js/inc/parser/generic-json.js
Normal 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
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue