Skip to content

Commit 708ce7a

Browse files
authored
Merge pull request internetarchive#666 from internetarchive/refactor/mobile-home2
Refactor/mobile home2
2 parents 7afe9d8 + b9d4776 commit 708ce7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3582
-403
lines changed

openlibrary/macros/RelatedWorksCarousel.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
$if work:
44
$ work_subjects_authors = cached_work_authors_and_subjects(work.key)
55
$ authors = ', '.join([author if isinstance(author, basestring) else author.name for author in work_subjects_authors.get('authors', [])])
6-
$:render_template("home/custom_ia_carousel", title="You might also like", key="related-subjects-carousel", work_id=work.key, _type="subjects", limit=42, min_books=1)
7-
$:render_template("home/custom_ia_carousel", title="More by %s" % (authors or "by this author"), key="related-authors-carousel", work_id=work.key, _type="authors", limit=42, min_books=1)
6+
$:render_template("home/custom_ia_carousel", title="You might also like", key="related-subjects-carousel", work_id=work.key, _type="subjects", limit=42, min_books=1, slick=False)
7+
$:render_template("home/custom_ia_carousel", title="More by %s" % (authors or "this author"), key="related-authors-carousel", work_id=work.key, _type="authors", limit=42, min_books=1, slick=False)

openlibrary/plugins/openlibrary/api.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,9 @@
88
import simplejson
99

1010
from infogami.utils import delegate
11-
from infogami.utils.view import render_template
12-
from openlibrary.plugins.worksearch.subjects import get_subject
1311
from openlibrary.core import ia, lending, cache, helpers as h
12+
from openlibrary.plugins.openlibrary import home
1413

15-
ONE_HOUR = 60 * 60
16-
BOOKS_PER_CAROUSEL = 6
17-
18-
class featured_subjects(delegate.page):
19-
path = "/home/subjects"
20-
21-
def GET(self):
22-
return delegate.RawText(simplejson.dumps(get_featured_subjects()),
23-
content_type="application/json")
24-
25-
def get_featured_subjects():
26-
# this function is memozied with background=True option.
27-
# web.ctx must be initialized as it won't be avaiable to the background thread.
28-
if 'env' not in web.ctx:
29-
delegate.fakeload()
30-
31-
subjects = {}
32-
FEATURED_SUBJECTS = [
33-
'art', 'science_fiction', 'fantasy', 'biographies', 'recipes',
34-
'romance', 'textbooks', 'children', 'history', 'medicine', 'religion',
35-
'mystery_and_detective_stories', 'plays', 'music', 'science'
36-
]
37-
for subject in FEATURED_SUBJECTS:
38-
subjects[subject] = get_subject('/subjects/' + subject, sort='edition_count')
39-
return subjects
40-
41-
# cache the results in memcache for 1 hour
42-
get_featured_subjects = cache.memcache_memoize(
43-
get_featured_subjects, "get_featured_subjects", timeout=ONE_HOUR)
4414

4515
class book_availability(delegate.page):
4616
path = "/availability/v2"

openlibrary/plugins/openlibrary/home.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
helpers as h
1616
from openlibrary.plugins.upstream import borrow
1717
from openlibrary.plugins.upstream.utils import get_blog_feeds
18-
from openlibrary.plugins.worksearch import search
18+
from openlibrary.plugins.worksearch import search, subjects
1919
from openlibrary.plugins.openlibrary import lists
2020

2121
DEFAULT_CACHE_LIFETIME = 120 # seconds
22+
ONE_HOUR = 60 * 60
2223

2324
logger = logging.getLogger("openlibrary.home")
2425

@@ -42,6 +43,7 @@ def GET(self):
4243
"home/index", stats=stats,
4344
blog_posts=blog_posts,
4445
)
46+
page.v2 = True
4547
return page
4648

4749
CAROUSELS_PRESETS = {
@@ -64,8 +66,27 @@ def get_ia_carousel_books(query=None, subject=None, work_id=None, sorts=None,
6466
formatted_books = [format_book_data(book) for book in books if book != 'error']
6567
return formatted_books
6668

69+
def get_featured_subjects():
70+
# web.ctx must be initialized as it won't be available to the background thread.
71+
if 'env' not in web.ctx:
72+
delegate.fakeload()
73+
74+
FEATURED_SUBJECTS = [
75+
'art', 'science_fiction', 'fantasy', 'biographies', 'recipes',
76+
'romance', 'textbooks', 'children', 'history', 'medicine', 'religion',
77+
'mystery_and_detective_stories', 'plays', 'music', 'science'
78+
]
79+
return dict([(subject_name, subjects.get_subject('/subjects/' + subject_name, sort='edition_count'))
80+
for subject_name in FEATURED_SUBJECTS])
81+
82+
@public
83+
def get_cached_featured_subjects():
84+
return cache.memcache_memoize(
85+
get_featured_subjects, "home.featured_subjects", timeout=ONE_HOUR)()
86+
87+
6788
@public
68-
def generic_carousel(key, query=None, subject=None, work_id=None, _type=None,
89+
def generic_carousel(query=None, subject=None, work_id=None, _type=None,
6990
sorts=None, limit=None, timeout=None):
7091
memcache_key = 'home.ia_carousel_books'
7192
cached_ia_carousel_books = cache.memcache_memoize(

openlibrary/plugins/openlibrary/js/automatic.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ jQuery(function($) {
2020
if($.support.opacity){
2121
options.fx = {"opacity": "toggle"};
2222
}
23-
$(".tabs:not(.ui-tabs)").tabs(options)
24-
$(".tabs.autohash")
25-
.bind("tabsselect", function(event, ui) {
26-
document.location.hash = ui.panel.id;
27-
});
2823

2924
// autocompletes
3025
$("input.author-autocomplete").author_autocomplete();
@@ -38,4 +33,4 @@ jQuery(function($) {
3833

3934
// hide all images in .no-img
4035
$(".no-img img").hide();
41-
});
36+
});

openlibrary/plugins/openlibrary/js/ol.js

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
1+
var Carousel = {
2+
add: function(selector, a, b, c, d, e, f) {
3+
var responsive_settings = [
4+
{
5+
breakpoint: 1200,
6+
settings: {
7+
slidesToShow: b,
8+
slidesToScroll: b,
9+
infinite: false,
10+
}
11+
},
12+
{
13+
breakpoint: 1024,
14+
settings: {
15+
slidesToShow: c,
16+
slidesToScroll: c,
17+
infinite: false,
18+
}
19+
},
20+
{
21+
breakpoint: 600,
22+
settings: {
23+
slidesToShow: d,
24+
slidesToScroll: d
25+
}
26+
},
27+
{
28+
breakpoint: 480,
29+
settings: {
30+
slidesToShow: e,
31+
slidesToScroll: e
32+
}
33+
}
34+
// You can unslick at a given breakpoint now by adding:
35+
// settings: "unslick"
36+
// instead of a settings object
37+
];
38+
if (f) {
39+
responsive_settings.push({
40+
breakpoint: 360,
41+
settings: {
42+
slidesToShow: f,
43+
slidesToScroll: f
44+
}
45+
});
46+
}
47+
48+
$(selector).slick({
49+
infinite: false,
50+
speed: 300,
51+
slidesToShow: a,
52+
slidesToScroll: a,
53+
responsive: responsive_settings
54+
});
55+
}
56+
};
57+
158
var Browser = {
259
getUrlParameter: function(key) {
360
var query = window.location.search.substring(1);
@@ -56,13 +113,6 @@ var Browser = {
56113
}
57114
}
58115

59-
60-
61-
function linkbuttons() {
62-
$(".linkButton").click(function(){
63-
window.location = $(this).attr("name");
64-
});
65-
};
66116
function twitterOn() {
67117
if ($(".twitter").is(":checked")) {$("#twitterName").show();} else {$("#twitterName").hide();};
68118
$("input[type=radio]").click(function(){
@@ -83,68 +133,6 @@ $(window).scroll(function(){
83133
var scroller = $("#formScroll");
84134
if(isScrolledIntoView(scroller)){$("#scrollBtm").show();}else{$("#scrollBtm").hide();};
85135
})
86-
function setupSearch() {
87-
$(".optionsNoScript").hide();
88-
$(".optionsScript").show();
89-
90-
var A = $("#topOptions");
91-
var B = A.parent().parent();
92-
var C = B.find("a#searchHead");
93-
var t1 = C.text();
94-
var t2 = "Hide Advanced";
95-
C.click(function(){
96-
var D = $(this);
97-
$('#footerSearch').toggle();
98-
A.toggle();
99-
B.toggleClass("darker");
100-
D.toggleClass("attn");
101-
D.toggleText(t1, t2);
102-
B.mouseup(function(){
103-
return false
104-
});
105-
$(document).mouseup(function(D){
106-
if($(D.target).parent("a").length==0){
107-
hideSearch()
108-
};
109-
});
110-
function hideSearch(){
111-
A.hide();
112-
B.removeClass("darker");
113-
C.removeClass("attn");
114-
C.text(t1);
115-
};
116-
});
117-
var E = $("#bottomOptions");
118-
var F = E.parent().parent();
119-
var G = F.find("a#searchFoot");
120-
var t3 = G.text();
121-
var t4 = "Hide Advanced";
122-
G.click(function(){
123-
var H = $(this);
124-
E.toggle();
125-
if($("#bottomOptions").is(":visible")){if($("#scrollBtm").is(":hidden")){$.scrollTo($("#formScroll"),800);};};
126-
F.toggleClass("darker");
127-
H.toggleClass("attn");
128-
$("#footerSearch").toggleClass("onTop");
129-
H.toggleText(t3, t4);
130-
$("#btmSrchLabel").toggle();
131-
F.mouseup(function(){
132-
return false
133-
});
134-
$(document).mouseup(function(H){
135-
if($(H.target).parent("a").length==0){
136-
hideSearch()
137-
};
138-
});
139-
function hideSearch(){
140-
E.hide();
141-
F.removeClass("darker");
142-
G.removeClass("attn");
143-
G.text(t3);
144-
};
145-
});
146-
147-
};
148136

149137
function flickrBuild(){$(".flickrs").flickr({callback:colorboxCallback});};
150138
function colorboxCallback(){$('a.flickrpic').colorbox({photo:true,preloading:true,opacity:'0.70'});};
@@ -429,7 +417,7 @@ $().ready(function(){
429417
var searchModeDefault = 'ebooks';
430418

431419
// Maps search facet label with value
432-
var defaultFacet = "title";
420+
var defaultFacet = "all";
433421
var searchFacets = {
434422
'title': 'books',
435423
'author': 'authors',

openlibrary/plugins/openlibrary/tests/test_home.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def test_read_template(self, render_template):
7878
# Empty list should be returned when there is error.
7979

8080
books = home.readonline_carousel()
81-
html = unicode(render_template("home/carousel", title="Classic Literature", url="/read",
82-
books=books, key="public_domain"))
81+
html = unicode(render_template("books/custom_carousel", books=books, title="Classic Literature", url="/read",
82+
key="public_domain", cta="Read"))
8383
assert html.strip() == ""
8484

8585
def test_home_template(self, render_template, mock_site, olconfig, monkeypatch):
@@ -119,9 +119,8 @@ def spoofed_generic_carousel(*args, **kwargs):
119119
monkeypatch.setattr(web.ctx, "library", {"name": "IA"}, raising=False)
120120
html = unicode(render_template("home/index", stats=stats, test=True))
121121

122-
headers = ["Books We Love", "Recently Returned", "Success",
123-
"Thrillers", "Romance", "Technical Books",
124-
"Classic Literature", "Textbooks"]
122+
headers = ["Books We Love", "Recently Returned", "Kids",
123+
"Thrillers", "Romance", "Classic Literature", "Textbooks"]
125124
for h in headers:
126125
assert h in html
127126

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$def with(books=None, title="", url="", key="", min_books=6, cta="Borrow", test=False)
2+
3+
$if test or (books and len(books) >= min_books):
4+
<div class="carousel-section">
5+
<div class="carousel-section-header">
6+
<h2 class="home-h2"><a href="$url">$title</a></h2>
7+
</div>
8+
<div class="carousel-container carousel-container-decorated">
9+
<div class="carousel carousel-$key">
10+
$for book in (books or []):
11+
$ byline = (' by ' + ', '.join([author.name for author in book.authors])) if book.get('authors') else ''
12+
$ byline_links = (' by ' + ', '.join(['<a href="%s">%s</a>' % (author.key, author.name) for author in book.authors])) if book.get('authors') else ''
13+
<div class="book">
14+
<div class="book-cover">
15+
<a href="$(book.get('key') or book.url)">
16+
<img class="bookcover" title="$book.title$(byline)" src="$book.get('cover_url', '')"/>
17+
</a>
18+
</div>
19+
$ cta_url = book.get('read_url') or '/borrow/ia/%s' % book.ocaid
20+
<div class="book-cta"><a href="$cta_url" data-ol-link-track="$key" title="$cta $book.title">$cta</a></div>
21+
</div>
22+
</div>
23+
<script type="text/javascript">
24+
\$().ready(function() {
25+
Carousel.add('.carousel-$key', 6, 5, 4, 3, 2, 1);
26+
});
27+
</script>
28+
</div>
29+
</div>
30+
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
$def with (blog_posts=None)
22

3-
<div class="head">
3+
<div id="home-resources">
4+
<div class="head">
45
<h2>About the Project</h2>
5-
</div>
6+
</div>
67

7-
<div class="contentHalf home collapse">
8-
<p class="collapse">
9-
<span class="largest collapse" style="line-height:1.5em;">
10-
$_("Open Library is an open, editable library catalog, building towards a web page for every book ever published.")
11-
</span>
8+
<div id="home-about">
9+
<div id="home-about-mission">
10+
<h3 id="home-about-mission-tldr">
11+
$_("Open Library is an open, editable library catalog, building towards a web page for every book ever published.")
1212
<a href="/about" class="small sansserif">$_("More")</a>
13-
</p>
14-
15-
<p>
13+
</h3>
14+
<p id="home-about-mission-desc">
1615
Just like Wikipedia, you can contribute new information or corrections to the catalog.
17-
You can browse by <a href="/subjects">subject</a>, <a href="/authors">author</a> or
16+
You can browse by <a href="/subjects">subjects</a>, <a href="/authors">authors</a> or
1817
<a href="/lists">lists</a> members have created. If you love books, why not help build a library?
19-
</p>
20-
</div>
21-
22-
<div class="contentSpacer"></div>
23-
24-
<div class="contentQuarter home collapse">
25-
<h3 class="collapse">Developers</h3>
26-
<p>If you’re even remotely interested in libraries or big data, we encourage you to have a look around the <a href="/developers/api">Open Library API</a>.</p>
27-
<p>We welcome any and all patches and data re-use.</p>
28-
</div>
29-
30-
<div class="contentSpacer"></div>
31-
32-
<div class="contentQuarter home collapse">
33-
<h3 class="collapse"><a href="http://blog.openlibrary.org/" class="header">Latest Blog Posts</a></h3>
34-
<ul id="olBlog">
18+
</p>
19+
</div>
20+
21+
<div class="home-resource-section">
22+
<h3 class="collapse">Developers</h3>
23+
<p>If you’re even remotely interested in libraries or big data, we encourage you to have a look around the <a href="/developers/api">Open Library API</a>.</p>
24+
<p>We welcome any and all patches and data re-use.</p>
25+
</div>
26+
27+
<div class="home-resource-section">
28+
<h3 class="collapse"><a href="http://blog.openlibrary.org/" class="header">Latest Blog Posts</a></h3>
29+
<ul id="olBlog">
3530
$if blog_posts:
36-
$for post in blog_posts[:3]:
37-
<li><a href="$post.link">$post.title</a> - <em>$datestr(post.pubdate)</em></li>
38-
</ul>
31+
$for post in blog_posts[:3]:
32+
<li><a href="$post.link">$post.title</a> - <em>$datestr(post.pubdate)</em></li>
33+
</ul>
34+
</div>
35+
</div>
3936
</div>
4037

0 commit comments

Comments
 (0)