From d019a9b5e928dcf777852d0c8d5413fd3d69b4dd Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 31 Jan 2022 16:02:01 +0100 Subject: [PATCH] Experimental preview of 2022 book detail page. --- .../migrations/0033_auto_20220128_1409.py | 23 + src/catalogue/models/book.py | 25 +- src/catalogue/models/tag.py | 2 + src/catalogue/static/player/2022_player.js | 112 +++ .../templates/catalogue/2021/book_detail.html | 643 +++++++++--------- .../catalogue/snippets/2022_jplayer.html | 70 ++ src/social/templatetags/social_tags.py | 7 +- src/wolnelektury/settings/static.py | 15 +- .../static/2022/fonts/subset-Canela-Light.ttf | 0 .../2022/fonts/subset-Canela-Light.woff | 0 .../2022/fonts/subset-Canela-Light.woff2 | 0 .../2022/fonts/subset-Canela-LightItalic.ttf | 0 .../2022/fonts/subset-Canela-LightItalic.woff | 0 .../fonts/subset-Canela-LightItalic.woff2 | 0 .../2022/fonts/subset-FuturaPT-Book.ttf | 0 .../2022/fonts/subset-FuturaPT-Book.woff | 0 .../2022/fonts/subset-FuturaPT-Book.woff2 | 0 .../static/2022/images/arrow-left.png | 0 .../static/2022/images/arrow-right.png | 0 src/wolnelektury/static/2022/more.scss | 3 + .../static/2022/styles/ajax-loader.gif | 0 .../static/2022/styles/components/_media.scss | 4 + .../2022/styles/components/_player.scss | 28 +- .../static/2022/styles/fonts/slick.eot | 0 .../static/2022/styles/fonts/slick.svg | 0 .../static/2022/styles/fonts/slick.ttf | 0 .../static/2022/styles/fonts/slick.woff | 0 .../static/2022/styles/layout/_author.scss | 22 +- .../static/2022/styles/layout/_content.scss | 1 + src/wolnelektury/static/2022/styles/main.css | 44 -- 30 files changed, 620 insertions(+), 379 deletions(-) create mode 100644 src/catalogue/migrations/0033_auto_20220128_1409.py create mode 100644 src/catalogue/static/player/2022_player.js create mode 100644 src/catalogue/templates/catalogue/snippets/2022_jplayer.html create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-Light.ttf create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-Light.woff create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-Light.woff2 create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-LightItalic.ttf create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-LightItalic.woff create mode 100644 src/wolnelektury/static/2022/fonts/subset-Canela-LightItalic.woff2 create mode 100644 src/wolnelektury/static/2022/fonts/subset-FuturaPT-Book.ttf create mode 100644 src/wolnelektury/static/2022/fonts/subset-FuturaPT-Book.woff create mode 100644 src/wolnelektury/static/2022/fonts/subset-FuturaPT-Book.woff2 create mode 100644 src/wolnelektury/static/2022/images/arrow-left.png create mode 100644 src/wolnelektury/static/2022/images/arrow-right.png create mode 100644 src/wolnelektury/static/2022/more.scss create mode 100644 src/wolnelektury/static/2022/styles/ajax-loader.gif create mode 100644 src/wolnelektury/static/2022/styles/fonts/slick.eot create mode 100644 src/wolnelektury/static/2022/styles/fonts/slick.svg create mode 100644 src/wolnelektury/static/2022/styles/fonts/slick.ttf create mode 100644 src/wolnelektury/static/2022/styles/fonts/slick.woff delete mode 100644 src/wolnelektury/static/2022/styles/main.css diff --git a/src/catalogue/migrations/0033_auto_20220128_1409.py b/src/catalogue/migrations/0033_auto_20220128_1409.py new file mode 100644 index 000000000..b01de25e5 --- /dev/null +++ b/src/catalogue/migrations/0033_auto_20220128_1409.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.25 on 2022-01-28 13:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0032_collection_listed'), + ] + + operations = [ + migrations.AddField( + model_name='tag', + name='photo', + field=models.FileField(blank=True, null=True, upload_to='catalogue/tag/'), + ), + migrations.AddField( + model_name='tag', + name='photo_attribution', + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 1be9a9f3c..ab7a59106 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -751,6 +751,15 @@ class Book(models.Model): b.ancestor.add(parent) parent = parent.parent + @property + def ancestors(self): + if self.parent: + for anc in self.parent.ancestors: + yield anc + yield self.parent + else: + return [] + def clear_cache(self): clear_cached_renders(self.mini_box) clear_cached_renders(self.mini_box_nolink) @@ -896,19 +905,27 @@ class Book(models.Model): else: return None, None - def choose_fragment(self): + def choose_fragments(self, number): fragments = self.fragments.order_by() fragments_count = fragments.count() if not fragments_count and self.children.exists(): fragments = Fragment.objects.filter(book__ancestor=self).order_by() fragments_count = fragments.count() if fragments_count: - return fragments[randint(0, fragments_count - 1)] + offset = randint(0, fragments_count - number) + return fragments[offset : offset + number] elif self.parent: - return self.parent.choose_fragment() + return self.parent.choose_fragments(number) else: - return None + return [] + def choose_fragment(self): + fragments = self.choose_fragments(1) + if fragments: + return fragments[0] + else: + return None + def fragment_data(self): fragment = self.choose_fragment() if fragment: diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index 6aaa97c8e..3c2a53610 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -67,6 +67,8 @@ class Tag(models.Model): gazeta_link = models.CharField(blank=True, max_length=240) culturepl_link = models.CharField(blank=True, max_length=240) wiki_link = models.CharField(blank=True, max_length=240) + photo = models.FileField(blank=True, null=True, upload_to='catalogue/tag/') + photo_attribution = models.CharField(max_length=255, blank=True) created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True) changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True) diff --git a/src/catalogue/static/player/2022_player.js b/src/catalogue/static/player/2022_player.js new file mode 100644 index 000000000..da0ba9a32 --- /dev/null +++ b/src/catalogue/static/player/2022_player.js @@ -0,0 +1,112 @@ +(function($) { + $(function() { + + $(".jp-jplayer").each(function() { + console.log('starting player') + var $self = $(this); + var $root = $self.parent(); + + // // var $number = $('.number', $root); + $self.jPlayer({ + swfPath: "/static/jplayer/", + solution: "html,flash", + supplied: 'oga,mp3', + cssSelectorAncestor: "#" + $self.attr("data-player"), + + ready: function() { + var player = $(this); + console.log(1); + + var setMedia = function(elem, time=0) { + console.log('setMedia', elem, time); + var media = {} + + media['mp3'] = elem.attr('data-mp3'); + media['oga'] = elem.attr('data-ogg'); + media['id'] = elem.attr('data-media-id'); + + $(".c-player__title", $root).html($(".title", elem).html()); + $(".c-player__info", $root).html($(".attribution", elem).html()); + $(".c-media__caption .content", $root).html($(".project-description", elem).html()); + $(".c-media__caption .license", $root).html($(".license", elem).html()); + $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html()); + + player.jPlayer("setMedia", media); + player.jPlayer("pause", time); + return player; + }; + + $('.play-next', $root).click(function() { + var next = parseInt($number.text()) + 1; + var p = $('.jp-playlist .play:eq(' + (next - 1) + ')', $root); + if (p.length) { + setMedia(p).jPlayer("play"); + $number.text(next) + } + }); + $('.play-prev', $root).click(function() { + var next = parseInt($number.text()) - 1; + if (next < 1) + return; + var p = $('.jp-playlist .play:eq(' + (next - 1) + ')', $root); + setMedia(p).jPlayer("play"); + $number.text(next) + }); + + console.log(1); + + var initialElem = $('.jp-playlist li', $root).first(); + var initialTime = 0; + if (true || Modernizr.localstorage) { + try { + audiobooks = JSON.parse(localStorage["audiobook-history"]); + } catch { + audiobooks = {}; + } + last = audiobooks[$root.attr("data-book-slug")] + // Fallback for book id; + if (!last) { + last = audiobooks[$root.attr("data-book-id")] + } + + if (last) { + initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first(); + initialTime = last[2]; + $number.text($(".jp-playlist .play", $root).index(initialElem) + 1); + } + } + setMedia(initialElem, initialTime); + }, + + timeupdate: function(event) { + //event.jPlayer.status.currentTime + + + if (true || (event.jPlayer.status.currentTime && Modernizr.localstorage)) { + try { + audiobooks = JSON.parse(localStorage["audiobook-history"]); + } catch { + audiobooks = {}; + } + t = event.jPlayer.status.currentTime; + if (t && event.jPlayer.status.duration - t > 10) { + audiobooks[$root.attr("data-book-slug")] = [ + Date.now(), + event.jPlayer.status.media.id, + event.jPlayer.status.currentTime + ]; + } else { + delete audiobooks[$root.attr("data-book-slug")]; + } + // Remove old book id, if present. + delete audiobooks[$root.attr("data-book-id")]; + localStorage["audiobook-history"] = JSON.stringify(audiobooks); + } + } + }); + }); + + + + }); +})(jQuery) diff --git a/src/catalogue/templates/catalogue/2021/book_detail.html b/src/catalogue/templates/catalogue/2021/book_detail.html index 2e4f44181..c76510021 100644 --- a/src/catalogue/templates/catalogue/2021/book_detail.html +++ b/src/catalogue/templates/catalogue/2021/book_detail.html @@ -1,7 +1,7 @@ {% load pipeline %} {% load static %} -{% load choose_cite from social_tags %} +{% load choose_cites from social_tags %} {% load choose_fragment license_icon from catalogue_tags %} {% load catalogue_tags %} @@ -14,98 +14,90 @@ WolneLektury.pl - {% stylesheet '2021' %} - + {% stylesheet '2022' %} + - - - + + + - + +
-
- -
- {% choose_cite book as cite_promo %} - {% if cite_promo %} - {{ cite.promo_box }} - {% else %} - {% choose_fragment book as fragment_promo %} - {% if fragment_promo %} - {{ fragment_promo.get_short_text|safe }} - {% endif %} - {% endif %} -
- -
-
-
- {% if book.has_mp3_file %} - -
    -
  • mp3
  • - {% if book.has_ogg_file %} -
  • ogg
  • - {% endif %} - {% for dsy in book.media_daisy %} -
  • DAISY
  • - {% endfor %} -
+
+
- {% if book.has_mp3_file %} -
-

słuchaj audiobooka w naszym serwisie

-
- -
- - -
-
+
+
- {% endif %} -
-
-
-

Pobieranie e-booka

-

Wybierz wersję dla siebie:

-
-
- {% if book.pdf_file %} -
-
-

.pdf

-

Jeśli planujesz wydruk albo lekturę na urządzeniu mobilnym bez dodatkowych aplikacji.

-
-
- .pdf -
-
- {% endif %} - {% if book.epub_file %} -
-
-

.epub

-

Uniwersalny format e-booków, obsługiwany przez większość czytników sprzętowych i aplikacji na urządzenia mobilne.

-
-
- .epub -
-
- {% endif %} - {% if book.mobi_file %} -
-
-

.mobi

-

Natywny format dla czytnika Amazon Kindle.

-
-
- .mobi -
-
+ +
+
+
+
+ {% if book.has_mp3_file %} + {% endif %} - {% if book.synchrobook_file %} -
-
-

synchrobook (epub3)

-

Książka elektroniczna i audiobook w jednym. Wymaga aplikacji obsługującej format (np. ..., ..., ...).

-
- -
- {% endif %} -
-
-

inne formaty

- -
-
- +
+ +
+
+ {% with t=book.get_first_text %} + {% if t %} + czytaj online + {% endif %} + {% endwith %} +
-
- {% if book.has_mp3_file %} -
+ + + + {% if book.has_mp3_file %} + {% include 'catalogue/snippets/2022_jplayer.html' %} + {% endif %} + + + + +
-

Pobieranie audiobooka

+

Pobieranie e-booka

Wybierz wersję dla siebie:

-
-
-

.mp3

-

Uniwersalny format, obsługiwany przez wszystkie urządzenia.

-
-
- .mp3 -
-
- {% if book.has_ogg_file %} -
-
-

OggVorbis

-

Otwarty format plików audio, oferujący nagranie w najwyższej jakości dźwiękowej.

-
-
- .ogg + {% if book.pdf_file %} +
+
+

.pdf

+

Jeśli planujesz wydruk albo lekturę na urządzeniu mobilnym bez dodatkowych aplikacji.

+
+
+ .pdf +
-
{% endif %} - {% if book.has_daisy_file %} -
-
-

DAISY

-

Format dla osób z dysfunkcjami czytania.

+ {% if book.epub_file %} +
+
+

.epub

+

Uniwersalny format e-booków, obsługiwany przez większość czytników sprzętowych i aplikacji na urządzenia mobilne.

+
+
+ .epub +
-
- {% for dsy in book.media_daisy %} - DAISY - {% endfor %} + {% endif %} + {% if book.mobi_file %} +
+
+

.mobi

+

Natywny format dla czytnika Amazon Kindle.

+
+
+ .mobi +
-
{% endif %} - {% if book.synchrobook_file %} -
-
-

synchrobook

-

Książka elektroniczna i audiobook w jednym. Wymaga aplikacji obsługującej format.

+ {% if book.synchro_file %} +
+
+

synchrobook (epub3)

+

Książka elektroniczna i audiobook w jednym. Wymaga aplikacji obsługującej format (np. ..., ..., ...).

+
+
-
- synchrobook + {% endif %} + {% if book.txt_file or book.fb2_file %} +
+
+

inne formaty

+ +
-
{% endif %}
- {% endif %} -
- - {{ book.abstract|safe }} + {% if book.has_mp3_file %} +
+
+
+

Pobieranie audiobooka

+

Wybierz wersję dla siebie:

+
+
+
+
+

.mp3

+

Uniwersalny format, obsługiwany przez wszystkie urządzenia.

+
+
+ .mp3 +
+
+ {% if book.has_ogg_file %} +
+
+

OggVorbis

+

Otwarty format plików audio, oferujący nagranie w najwyższej jakości dźwiękowej.

+
+
+ .ogg +
+
+ {% endif %} + {% if book.has_daisy_file %} +
+
+

DAISY

+

Format dla osób z dysfunkcjami czytania.

+
+
+ {% for dsy in book.media_daisy %} + DAISY + {% endfor %} +
+
+ {% endif %} + {% if book.has_synchro_file %} +
+
+

synchrobook

+

Książka elektroniczna i audiobook w jednym. Wymaga aplikacji obsługującej format.

+
+ +
+ {% endif %} +
+ +
+
+ {% endif %} +
-
+

Opis

+ {{ book.abstract|safe }} +
+
- -

Ta książka jest dostępna dla tysięcy dzieciaków dzięki darowiznom od osób takich jak Ty!

- DORZUĆ SIĘ! +
+ Dorzuć się! + Dorzuć się! +
- {% for author in book.authors %}
-
-

- - {{ author.name }} - -

- - {{ author.description|safe }} +
+

O autorze

+
+ {% if author.photo %} +
+ {{ author.name }} +
+ {{ author.photo_attribution|safe }} +
+
+ {% endif %} +
+

{{ author.name }}

+ {{ author.description|safe }} +
+
+
-
- {% if HAVE_AUTHOR_PHOTO %} -
- {{ author.name }} -
-
-
- {% endif %} +
+
+
+ {% choose_cites book 3 as cites %} + {% for fragment in cites %} +
+ + {{ fragment.short_text|safe }} + +

{{ fragment.book.pretty_title }}

+
+ {% endfor %} +
+
+
-
+ + {% endfor %} - {% with book.related_themes as themes %} - {% if themes %} -
-
-

motywy występujące w tym utworze

+
+
+ {% with book.related_themes as themes %} + {% if themes %} +

Motywy występujące w tym utworze Wszystkie motywy

- zobacz wszystkie motywy
-
-
- {% endif %} - {% endwith %} + {% endif %} + {% endwith %} + +
+
+
+ -
-
-

inne tytuły w naszej bibliotece

-
+ +
+
+
+

Tytuły powiązane

+
{% if book.other_versions %} {% for rel in book.other_versions %} -
-
- +
+