gaining speed
[ReadingsJQM.git] / js / app / app.coffee
1
2 window.Readings = {}
3
4 # Readings jquery plugin dispatcher.
5 $.fn.Readings =  ->
6   meth = arguments[0]
7   args = []
8   for a in arguments
9     args.push a
10   args.shift()
11   $.fn.Readings[meth].apply(this, args)
12
13
14 Readings.init = ->
15   if Readings.initialized?
16     return
17   Readings.config = new Readings.Config
18     wlurl: 'http://readings.local'
19     categories:
20       'authors': 'autor',
21       'epochs': 'epoka',
22       'genres': 'gatunek',
23       'kinds': 'rodzaj',
24       'themes': 'motyw'
25     show_filter: [ 'authors', 'themes' ]
26     show_dividers: [ 'authors', 'themes']
27   Readings.initialized = true
28
29 $(document).on 'pageinit', '#page-categories' , (ev) ->
30   Readings.init()
31   $('#list-categories').Readings 'CategoryList'
32
33 rcategory = /category=(\w+)/
34 $(document).on 'pageinit', "#page-tags", (ev, ui) ->
35   category = rcategory.exec($(this).attr('data-url'))
36   if category? and category[1]?
37     $(this).Readings 'list',
38       category: category[1]
39       url: Readings.config.get('wlurl') + "/api/#{category[1]}"
40       filter: (Readings.config.get('show_filter').indexOf(category[1]) >= 0)
41       mapper: (rec) -> new Readings.Tag(rec, category[1])
42       dividers: (Readings.config.get('show_dividers').indexOf(category[1]) >= 0)
43   else
44     alert 'no category in query string'