From 4e63148bb05d7313baeea9f1327059d6a65e4962 Mon Sep 17 00:00:00 2001 From: Martin Wind Date: Thu, 15 Jan 2015 15:35:24 +0100 Subject: [PATCH 1/2] fix toc parser --- epub.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/epub.js b/epub.js index 3d9aafa..4daa54b 100644 --- a/epub.js +++ b/epub.js @@ -509,20 +509,25 @@ EPub.prototype.walkNavMap = function (branch, path, id_list, level) { return []; } - var i, len, output = [], element, title, order, href; + var output = []; if (!Array.isArray(branch)) { branch = [branch]; } - for (i = 0, len = branch.length; i < len; i++) { + for (var i = 0; i < branch.length; i++) { if (branch[i].navLabel) { - title = (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim(); - order = Number(branch[i]["@"] && branch[i]["@"].playOrder || 0); - href = (branch[i].content && branch[i].content["@"] && branch[i].content["@"].src || "").trim(); + var title = ''; + if (branch[i].navLabel && typeof branch[i].navLabel.text == 'string') + title = branch[i].navLabel.text.trim(); + var order = Number(branch[i]["@"] && branch[i]["@"].playOrder || 0); + if (isNaN(order)) order = 0; + var href = ''; + if (branch[i].content && branch[i].content["@"] && typeof branch[i].content["@"].src == 'string') + href = branch[i].content["@"].src.trim(); - element = { + var element = { level: level, order: order, title: title From a026e72082e79f36bd655ff714223c14a8849c25 Mon Sep 17 00:00:00 2001 From: Martin Wind Date: Thu, 15 Jan 2015 16:20:11 +0100 Subject: [PATCH 2/2] fix coding style --- epub.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/epub.js b/epub.js index 4daa54b..15e7767 100644 --- a/epub.js +++ b/epub.js @@ -519,13 +519,17 @@ EPub.prototype.walkNavMap = function (branch, path, id_list, level) { if (branch[i].navLabel) { var title = ''; - if (branch[i].navLabel && typeof branch[i].navLabel.text == 'string') + if (branch[i].navLabel && typeof branch[i].navLabel.text == 'string') { title = branch[i].navLabel.text.trim(); + } var order = Number(branch[i]["@"] && branch[i]["@"].playOrder || 0); - if (isNaN(order)) order = 0; + if (isNaN(order)) { + order = 0; + } var href = ''; - if (branch[i].content && branch[i].content["@"] && typeof branch[i].content["@"].src == 'string') + if (branch[i].content && branch[i].content["@"] && typeof branch[i].content["@"].src == 'string') { href = branch[i].content["@"].src.trim(); + } var element = { level: level,