diff options
author | Jayaram R Pai | 2014-07-07 13:19:45 +0530 |
---|---|---|
committer | Jayaram R Pai | 2014-07-07 13:19:45 +0530 |
commit | 359cef390a698f9a3e5d550d5bc14fd044054eb1 (patch) | |
tree | 99122b36c70f9c9351dd500cbe07e8cae2dd45b8 | |
parent | c1a5ab94ddfe4050e9840a3ebe85e39427ec581a (diff) | |
download | custom-359cef390a698f9a3e5d550d5bc14fd044054eb1.tar.gz custom-359cef390a698f9a3e5d550d5bc14fd044054eb1.tar.bz2 custom-359cef390a698f9a3e5d550d5bc14fd044054eb1.zip |
added try/catch for .each()
-rw-r--r-- | custom.js | 56 |
1 files changed, 30 insertions, 26 deletions
@@ -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 = $("<a></a>"); + $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 = $("<a></a>"); - $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 */ |