Skip to content

Commit

Permalink
feat: indicate when a subscription is required (resolves #218) (#223)
Browse files Browse the repository at this point in the history
* feat: indicate when a subscription is required (resolves #218)

* fix: add screen reader text

* fix: use aria-hidden
  • Loading branch information
Ned Zimmerman authored Mar 12, 2020
1 parent 4d3c100 commit bb8315f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/Controllers/Partials/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,15 @@ public static function isFavorited()
}
return false;
}

public static function requiresSubscription()
{
global $post;

if ($post->post_type == 'lc_resource') {
return (get_post_meta($post->ID, 'lc_resource_has_paywall', true) === 'on');
}

return false;
}
}
1 change: 1 addition & 0 deletions resources/assets/images/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions resources/assets/styles/layouts/_resources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@
list-style: none;
padding-left: 0;
}

.card__meta.card__subscription,
.resource__meta.resource__subscription {
color: var(--red-500);

svg {
color: inherit;
}
}
3 changes: 3 additions & 0 deletions resources/views/partials/content-lc_resource.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<article @php post_class('card card--resource') @endphp>
<header>
<h3 class="card__title"><a class="card__link" href="{{ get_permalink() }}">{!! Archive::getShortTitle() !!}</a></h3>
@if(Archive::requiresSubscription())
<p class="card__meta card__subscription">@svg('lock', 'icon--lock', ['focusable' => 'false', 'aria-hidden' => 'true']) <span aria-hidden="true">{{ __('Subscription required', 'coop-library') }}</span><span class="screen-reader-text">{{ __('Subscription required to access this resource', 'coop-library') }}</span></p>
@endif
@if(Archive::getAuthors())
<p class="card__byline">
@svg('author', 'icon--author', ['focusable' => 'false', 'aria-hidden' => 'true'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<article @php post_class() @endphp>
<div class="page-header resource__header">
<h1 class="resource__title">{!! get_the_title() !!}</h1>
@if(Single::requiresSubscription())
<p class="resource__meta resource__subscription">@svg('lock', 'icon--lock', ['focusable' => 'false', 'aria-hidden' => 'true']) <span aria-hidden="true">{{ __('Subscription required', 'coop-library') }}</span><span class="screen-reader-text">{{ __('Subscription required to access this resource', 'coop-library') }}</span></p>
@endif
@if(Single::getAuthors())
<div class="resource__meta resource__byline">@svg('author', 'icon--author', ['focusable' => 'false', 'aria-hidden' => 'true']) {{ sprintf(__('By %s', 'coop-library'), Single::getAuthors()) }}</div>
@endif
Expand All @@ -20,6 +23,8 @@
@svg('info', 'icon--info', ['focusable' => 'false', 'aria-hidden' => 'true'])
@if($current_language !== Single::getLanguage())
<span class="resource__language"><span class="screen-reader-text">{{ __('language', 'coop-library') }}: </span>{{ $languages[Single::getLanguage()] }}</span>
@endif
@if($current_language !== Single::getLanguage() && Single::getPublicationDate())
<span class="separator">.</span>
@endif
@if(Single::getPublicationDate())
Expand Down Expand Up @@ -47,7 +52,7 @@
</div>
@endif
<div class="resource__cta">
<p><a rel="external" class="cta" href="{{ Single::getPermanentLink() }}">{{ __('Visit full resource', 'coop-library') }} @svg('external', 'icon--external', ['focusable' => 'false', 'aria-hidden' => 'true'])</a></p>
<p><a rel="external" class="cta" href="{{ Single::getPermanentLink() }}">@if(Single::requiresSubscription()){{ __('Visit full resource (subscription required)', 'coop-library') }}@else{{ __('Visit full resource', 'coop-library') }}@endif @svg('external', 'icon--external', ['focusable' => 'false', 'aria-hidden' => 'true'])</a></p>
</div>
<div class="resource__actions">
<button id="favorite" type="button" class="button button--borderless" data-id="{{ get_the_id() }}" data-favorite="false">
Expand Down

0 comments on commit bb8315f

Please sign in to comment.