mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Content server: When browsing random books, add a button to the book page to get another random book. Fixes #1134958 (Request: Add random button to random results)
This commit is contained in:
parent
bbeebd1c1d
commit
ff33a74a44
@ -482,5 +482,10 @@ h2.library_name {
|
|||||||
border: none
|
border: none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.details #random_button {
|
||||||
|
display:block
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -324,9 +324,15 @@ function show_details(a_dom) {
|
|||||||
function book() {
|
function book() {
|
||||||
hidesort();
|
hidesort();
|
||||||
$('.details .left img').load(function() {
|
$('.details .left img').load(function() {
|
||||||
|
var rb = $('#random_button');
|
||||||
|
rb.button();
|
||||||
var img = $('.details .left img');
|
var img = $('.details .left img');
|
||||||
var height = $('#main').height();
|
var height = $('#main').height();
|
||||||
height = Math.max(height, img.height() + 100);
|
var bh = 0;
|
||||||
|
if (rb.length > 0) {
|
||||||
|
bh = rb.height();
|
||||||
|
}
|
||||||
|
height = Math.max(height, img.height() + bh + 100);
|
||||||
$('#main').height(height);
|
$('#main').height(height);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<div id="details_{id}" class="details">
|
<div id="details_{id}" class="details">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<a href="{get_url}" title="Click to read {title} in the {fmt} format" class="details_thumb"><img alt="Cover of {title}" src="{prefix}/get/cover/{id}" /></a>
|
<a href="{get_url}" title="Click to read {title} in the {fmt} format" class="details_thumb"><img alt="Cover of {title}" src="{prefix}/get/cover/{id}" /></a>
|
||||||
|
{random}
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<div class="field formats">{formats}</div>
|
<div class="field formats">{formats}</div>
|
||||||
|
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import operator, os, json, re
|
import operator, os, json, re, time
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
@ -819,7 +819,7 @@ class BrowseServer(object):
|
|||||||
raw = json.dumps('\n'.join(summs), ensure_ascii=True)
|
raw = json.dumps('\n'.join(summs), ensure_ascii=True)
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
def browse_render_details(self, id_):
|
def browse_render_details(self, id_, add_random_button=False):
|
||||||
try:
|
try:
|
||||||
mi = self.db.get_metadata(id_, index_is_id=True)
|
mi = self.db.get_metadata(id_, index_is_id=True)
|
||||||
except:
|
except:
|
||||||
@ -886,11 +886,18 @@ class BrowseServer(object):
|
|||||||
u'<div class="comment">%s</div></div>') % (xml(c[0]),
|
u'<div class="comment">%s</div></div>') % (xml(c[0]),
|
||||||
c[1]) for c in comments]
|
c[1]) for c in comments]
|
||||||
comments = u'<div class="comments">%s</div>'%('\n\n'.join(comments))
|
comments = u'<div class="comments">%s</div>'%('\n\n'.join(comments))
|
||||||
|
random = ''
|
||||||
|
if add_random_button:
|
||||||
|
href = '%s/browse/random?v=%s'%(
|
||||||
|
self.opts.url_prefix, time.time())
|
||||||
|
random = '<a href="%s" id="random_button" title="%s">%s</a>' % (
|
||||||
|
xml(href, True), xml(_('Choose another random book'), True),
|
||||||
|
xml(_('Another random book')))
|
||||||
|
|
||||||
return self.browse_details_template.format(
|
return self.browse_details_template.format(
|
||||||
id=id_, title=xml(mi.title, True), fields=fields,
|
id=id_, title=xml(mi.title, True), fields=fields,
|
||||||
get_url=args['get_url'], fmt=args['fmt'],
|
get_url=args['get_url'], fmt=args['fmt'],
|
||||||
formats=args['formats'], comments=comments)
|
formats=args['formats'], comments=comments, random=random)
|
||||||
|
|
||||||
@Endpoint(mimetype='application/json; charset=utf-8')
|
@Endpoint(mimetype='application/json; charset=utf-8')
|
||||||
def browse_details(self, id=None):
|
def browse_details(self, id=None):
|
||||||
@ -908,7 +915,7 @@ class BrowseServer(object):
|
|||||||
import random
|
import random
|
||||||
book_id = random.choice(self.db.search_getting_ids(
|
book_id = random.choice(self.db.search_getting_ids(
|
||||||
'', self.search_restriction))
|
'', self.search_restriction))
|
||||||
ans = self.browse_render_details(book_id)
|
ans = self.browse_render_details(book_id, add_random_button=True)
|
||||||
return self.browse_template('').format(
|
return self.browse_template('').format(
|
||||||
title='', script='book();', main=ans)
|
title='', script='book();', main=ans)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user