4 url_to_slug = function(url) {
6 slug_in_url = /([a-z0-9-]+)[/]?$/;
7 return slug_in_url.exec(url)[1];
10 Readings.Book = (function() {
12 function Book(record) {
13 $.extend(this, record);
16 Book.prototype.render = function() {
18 wlurl = Readings.config.get('wlurl');
19 return "<li> <a href=\"reader.html?book_id=" + this.id + "\"> <img src=\"" + wlurl + this.cover + "\"> <h3>" + this.title + "</h3> </a> </li>";
22 Book.prototype.group = function() {
26 Book.prototype.is_local = function() {
28 html = localStorage.getItem("html:" + this.id);
29 return !(html === null);
32 Book.prototype.get_text = function() {
35 html = localStorage.getItem("html:" + this.id);
36 if (html) return $(html);
41 Book.prototype.fetch = function(cb) {
43 return $.ajax(Readings.config.get("wlurl" + ("/katalog/lektura/" + this.slug + ".html"), {
46 success: function(text) {
47 text = _this.mobilize_html(text);
48 localStorage.setItem("html:" + _this.id, text);
50 return _this.db.transaction(function(tx) {
51 return tx.executeSql("UPDATE _local = 1 WHERE id=?", [_this.id], function(tx, rs) {
57 throw Error("Error fetching book text slug=" + this.slug + ", " + er);
62 Book.prototype.mobilize_html = function(html) {
65 book_text = html.find("#book-id");
66 html.find("#download, #header, #themes")["delete"]();
74 Readings.Tag = (function() {
76 function Tag(record, category) {
77 this.category = category;
78 $.extend(this, record);
81 Tag.prototype.render = function() {
82 return "<li><a href=\"books.html?tag_id=" + this.id + "\">" + this.name + "</a></li>";
85 Tag.prototype.group = function() {
86 return this.sort_key[0].toUpperCase();