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