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