From 359cef390a698f9a3e5d550d5bc14fd044054eb1 Mon Sep 17 00:00:00 2001
From: Jayaram R Pai
Date: Mon, 7 Jul 2014 13:19:45 +0530
Subject: added try/catch for .each()
---
custom.js | 56 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 26 deletions(-)
diff --git a/custom.js b/custom.js
index 7527d5b..5858829 100644
--- a/custom.js
+++ b/custom.js
@@ -37,33 +37,37 @@ $([IPython.events]).on('notebook_loaded.Notebook', function(){
console.log("Chapter:" + chapter_number);
$code_cell.each(function(index, element) {
- /* fetching example and page number */
- var $current_text_cell = $(this).prev();
- /* code headings can be h2 or h3 */
- var $heading;
- $heading = $current_text_cell.find("h2");
- if(!$heading.html()) {
- $heading = $current_text_cell.find("h3").first();
- console.log("################ Head" + $heading.html());
+ try {
+ /* fetching example and page number */
+ var $current_text_cell = $(this).prev();
+ /* code headings can be h2 or h3 */
+ var $heading;
+ $heading = $current_text_cell.find("h2");
+ if(!$heading.html()) {
+ $heading = $current_text_cell.find("h3").first();
+ console.log("########## Head" + $heading.html());
+ }
+ var heading_text = $heading.html();
+ var numbers = heading_text.match(regex).map(function(v) { return parseFloat(v); });
+ var example_no = Math.abs(numbers[0]);
+ var page_no = Math.abs(numbers[1]);
+ console.log("########## Exp:" + example_no + ", Pg:" + page_no);
+
+ /* creating the link */
+ var $link = $("");
+ $link.attr({
+ href: "#",
+ class: "question",
+ "data-book": book,
+ "data-chapter": chapter_number,
+ "data-example": example_no,
+ "data-page": page_no,
+ });
+ $(this).prepend($link);
+ count++;
+ } catch(e) {
+ return;
}
- var heading_text = $heading.html();
- var numbers = heading_text.match(regex).map(function(v) { return parseFloat(v); });
- var example_no = Math.abs(numbers[0]);
- var page_no = Math.abs(numbers[1]);
- console.log("Exp:" + example_no + ", Pg:" + page_no);
-
- /* creating the link */
- var $link = $("");
- $link.attr({
- href: "#",
- class: "question",
- "data-book": book,
- "data-chapter": chapter_number,
- "data-example": example_no,
- "data-page": page_no,
- });
- $(this).prepend($link);
- count++;
});
/* appending modal skeleton */
--
cgit