copying info
[wl-mobile.git] / assets / www / js / links.js
1 /*
2  * This file is part of WolneLektury-Mobile, licensed under GNU Affero GPLv3 or later.
3  * Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4  */
5
6 var Links = new function() {
7         var self = this;
8
9         self.href = function(view, par) {
10                 return view+"/"+par;
11         };
12
13         self.button = function(view, par, text, offset) {
14                 offset = offset || 0;
15                 var html = "<div class='button button-"+view+"' onclick='History.visit(\"" + 
16                                         self.href(view, par).replace(/["']/g, "\\$&") + "\", "+offset+");'>";
17                 icon = view;
18                 if (icon != 'Book' && icon != 'Bookmarks' && icon != 'BookText' && 
19                         icon != 'Last' && icon != 'Tag') {
20                     icon = 'Tag';
21                 }
22                 html += "<img src='img/icon-" + icon + ".png' />";
23                 html += "<div class='label'>" + text + "</div>";
24                 html += "<div class='clr'></div>";
25                 html += "</div>\n";
26                 return html; 
27         };
28
29         self.bookLink = function(book) {
30                 var target = 'Book';
31                 var note = '';
32
33                 if (book.html_file) {
34                         // this assumes that either book has a html XOR it has children
35                         target = 'BookText';
36                         note = "<div class='note'>";
37                         if (book._local)
38                                 note += 'Pobrane';
39                         else {
40                                 note += book.pretty_size;
41                         }
42                         note += "</div>";
43                 }
44
45                 return self.button(target, book.id,
46                                 "<div class='sub'>" + book.authors + "</div>" +
47                                 book.title + note);
48         };
49
50         self.deleteButton = function(id) {
51                 return "<div class='delete' onClick='History.deleteBookmark(\""+id+"\");'>x</div>";
52         };
53 }