b5e2ba248b7100354d272171f214e8e275382af5
[ReadingsJQM.git] / js / app / app.js
1 // Generated by CoffeeScript 1.3.3
2 (function() {
3   var rcategory;
4
5   window.Readings = {};
6
7   $.fn.Readings = function() {
8     var a, args, meth, _i, _len;
9     meth = arguments[0];
10     args = [];
11     for (_i = 0, _len = arguments.length; _i < _len; _i++) {
12       a = arguments[_i];
13       args.push(a);
14     }
15     args.shift();
16     return $.fn.Readings[meth].apply(this, args);
17   };
18
19   Readings.init = function() {
20     if (Readings.initialized != null) {
21       return;
22     }
23     Readings.config = new Readings.Config({
24       wlurl: 'http://readings.local',
25       categories: {
26         'authors': 'autor',
27         'epochs': 'epoka',
28         'genres': 'gatunek',
29         'kinds': 'rodzaj',
30         'themes': 'motyw'
31       },
32       show_filter: ['authors', 'themes'],
33       show_dividers: ['authors', 'themes']
34     });
35     return Readings.initialized = true;
36   };
37
38   $(document).on('pageinit', '#page-categories', function(ev) {
39     Readings.init();
40     return $('#list-categories').Readings('CategoryList');
41   });
42
43   rcategory = /category=(\w+)/;
44
45   $(document).on('pageinit', "#page-tags", function(ev, ui) {
46     var category;
47     category = rcategory.exec($(this).attr('data-url'));
48     if ((category != null) && (category[1] != null)) {
49       return $(this).Readings('list', {
50         category: category[1],
51         url: Readings.config.get('wlurl') + ("/api/" + category[1]),
52         filter: Readings.config.get('show_filter').indexOf(category[1]) >= 0,
53         mapper: function(rec) {
54           return new Readings.Tag(rec, category[1]);
55         },
56         dividers: Readings.config.get('show_dividers').indexOf(category[1]) >= 0
57       });
58     } else {
59       return alert('no category in query string');
60     }
61   });
62
63 }).call(this);