1 // Generated by CoffeeScript 1.3.3
4 Readings.Tag = (function() {
6 function Tag(record, category) {
7 this.category = category;
8 this.href = record.href;
9 this.name = record.name;
10 this.slug = $.grep(this.href.split('/'), function(e) {
15 Tag.prototype.render = function() {
16 return "<li><a href=\"#\">" + this.name + "</a></li>";
19 Tag.prototype.group = function() {
20 if (this.category === 'authors') {
21 return this.name.split(' ').slice(-1)[0][0].toUpperCase();
23 return this.name[0].toUpperCase();
31 $.fn.Readings.list = function(opts) {
32 return this.each(function() {
34 $('[data-role=header] h1').text(opts.title);
35 list = $('[data-role=listview]', this);
37 $(".ui-listview-filter").hide();
42 success: function(data) {
43 var divider, last_divider, obj, objs, _i, _len;
44 objs = $.map(data, opts.mapper);
47 for (_i = 0, _len = objs.length; _i < _len; _i++) {
50 divider = obj.group();
51 if (last_divider !== divider) {
52 list.append("<li data-role=\"list-divider\">" + divider + "</li>");
53 last_divider = divider;
56 list.append(obj.render());
58 return list.listview('refresh');
64 $.fn.Readings.TagList = function(category) {
65 return this.each(function() {
67 $('[data-role=header] h1').text(Readings.config.get('categories')[category]);
68 list = $('[data-role=listview]', this);
69 if (Readings.config.get('show_filter').indexOf(category) < 0) {
70 $(".ui-listview-filter").hide();
73 url: Readings.config.get('wlurl') + ("/api/" + category),
75 success: function(data) {
76 var last_separator, separator, show_separator, t, tags, _i, _len;
77 tags = $.map(data, function(rec) {
78 return new Readings.Tag(rec, category);
81 last_separator = null;
82 show_separator = Readings.config.get('show_dividers').indexOf(category) >= 0;
83 for (_i = 0, _len = tags.length; _i < _len; _i++) {
86 separator = t.group();
87 if (last_separator !== separator) {
88 list.append("<li data-role=\"list-divider\">" + separator + "</li>");
89 last_separator = separator;
92 list.append(t.render());
94 return list.listview('refresh');