Skip to content

Commit

Permalink
Merge pull request #8875 from noobCoderVP/8854/feature/add-share-moda…
Browse files Browse the repository at this point in the history
…l-on-my-books-page

8854/feature/add share modal on my books page
  • Loading branch information
jimchamp authored Mar 20, 2024
2 parents 45ed081 + 6526f82 commit a6f4af1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
33 changes: 17 additions & 16 deletions openlibrary/macros/ShareModal.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$def with (share_links, page_url, link_markup, classes='')
$def with (share_links, page_url, link_markup, classes='', show_embed=True)
$# :param list[dict] share_links:
$# :param str page_url: absolute url excluding params
$# :param str link_markup: Markup for element that triggers share modal
Expand Down Expand Up @@ -34,21 +34,22 @@
<div class="share-source">$share_link['text']</div>
</li>

<li>
$# rm special characters from url such as single quote which break js prompt/iframe
$ clean_url = page_url.replace("'", "\\'")
$ iframe_html = str(embed_iframe(clean_url)).strip()
<a class="embed-work-btn" title="$_('Embed this book in your website')" data-ol-link-track="Share|Embed"
onclick="prompt('Copy embed code to clipboard:', '$iframe_html');">
<img
alt="Embed icon"
class="share-link"
src="$static_url('images/embed.png')"
loading="lazy"
>
</a>
<div class="share-source">$_('Embed')</div>
</li>
$if show_embed:
<li>
$# rm special characters from url such as single quote which break js prompt/iframe
$ clean_url = page_url.replace("'", "\\'")
$ iframe_html = str(embed_iframe(clean_url)).strip()
<a class="embed-work-btn" title="$_('Embed this book in your website')" data-ol-link-track="Share|Embed"
onclick="prompt('Copy embed code to clipboard:', '$iframe_html');">
<img
alt="Embed icon"
class="share-link"
src="$static_url('images/embed.png')"
loading="lazy"
>
</a>
<div class="share-source">$_('Embed')</div>
</li>

<li>
<a class="copy-url-btn" title="$_('Copy url to clipboard')" data-ol-link-track="Share|CopyURL">
Expand Down
11 changes: 7 additions & 4 deletions openlibrary/templates/account/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

$var title: $header_title


<div class="mybooks">

$:mb.render_sidebar()
Expand Down Expand Up @@ -41,9 +40,13 @@ <h1 class="details-title">$header_title</h1>
$:macros.databarView(page)

$if mb.is_public and mb.key in mb.PUBLIC_KEYS:
<div>
<a class="cta-btn cta-btn--unstyled" onclick="prompt('Copy share link to clipboard:', window.location.protocol + '//' + window.location.hostname + '$(ctx.path)');"><img class="icon-link__image" src="/static/images/icons/share.svg" width="20"> Share</a>
</div>
$set_share_links(url=request.canonical_url, title=header_title, view_context=ctx)
$if ctx.get('share_links'):
$ share_str = _('Share')
$ share_content = '<a class="cta-btn cta-btn--unstyled share-modal-link icon-link" href="javascript:;" data-ol-link-track="MyBooksModalLinkClick|ShareIcon"><img class="icon-link__image" src="/static/images/icons/share.svg" width="20"> %s</a>' % share_str
$ page_url = request.home
$ share_links = ctx.get('share_links')
$:macros.ShareModal(share_links, page_url, share_content, "share-modal-wrapper", show_embed=False)
</header>

$ mb.component_times['Details header'] = time() - mb.component_times['Details header']
Expand Down

0 comments on commit a6f4af1

Please sign in to comment.