Started coding reader
[ReadingsJQM.git] / js / app / reader.js
1 (function() {
2
3   $.fn.Readings.reader = function(opts) {
4     this.each(function() {
5       var _this = this;
6       return Readings.catalogue.fetchBook(opts.book_id, true, function(book) {
7         return $(_this).find("#content-reader").empty().append(book.getText());
8       });
9     });
10     return {
11       load_book: function(slug) {
12         return this.each(function() {
13           var _this = this;
14           return $.ajax({
15             type: 'GET',
16             contentType: 'html',
17             url: '/fixtures/katalog_lektura_lord-jim.html',
18             error: function(e) {
19               return console.log("Error " + e);
20             },
21             success: function(page) {
22               var $page, $text, $toc;
23               $page = $(page);
24               $text = $page.find('#book-text');
25               $toc = $text.find('#toc');
26               _this.toc = $toc.find('a').map(function(_i, link) {
27                 return {
28                   anchor: link.href,
29                   label: $(link).text()
30                 };
31               });
32               $toc.remove();
33               _this.text = $text;
34               return $('[data-role=header] h1', _this).text(_this.text.find('h1 .title').text());
35             }
36           });
37         });
38       }
39     };
40   };
41
42 }).call(this);