diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 1ff0eff0bdbd0c65b76592d707602cafddb67fcb..41c1108a4572b99f6b77cb6f09a24a34b3110c93 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -694,6 +694,12 @@ authors = Wikipedia ; http://code.google.com/apis/books/branding.html before using Google Book Search. ;previews = Google,OpenLibrary,HathiTrust +; This setting controls whether or not cover images are linked to previews when +; available. Legal settings are false (never link), * (always link; default), or +; a comma-separated list of templates in which linking should occur (see coversize +; above for a list of legal values). +;linkPreviewsToCovers = * + ; Possible HathiRights options = pd,ic,op,orph,und,umall,ic-world,nobody,pdus,cc-by,cc-by-nd, ; cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,orphcand,cc-zero,und-world,icus ; Default is "pd,ic-world" if unset here. diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index 7f351e2551d7fbd3698dcf029047afabd3eb1c4d..c87816b479e80543ac425a4a5c556afd5c627eb6 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -441,6 +441,28 @@ class Record extends AbstractHelper return $details['html']; } + /** + * Should cover images be linked to previews (when applicable) in the provided + * template context? + * + * @param string $context Context of code being generated + * + * @return bool + */ + protected function getPreviewCoverLinkSetting($context) + { + static $previewContexts = false; + if (false === $previewContexts) { + $previewContexts = isset($this->config->Content->linkPreviewsToCovers) + ? array_map( + 'trim', + explode(',', $this->config->Content->linkPreviewsToCovers) + ) : ['*']; + } + return in_array('*', $previewContexts) + || in_array($context, $previewContexts); + } + /** * Get the rendered cover plus some useful parameters. * @@ -453,7 +475,8 @@ class Record extends AbstractHelper public function getCoverDetails($context, $default, $link = false) { $details = compact('link', 'context') + [ - 'driver' => $this->driver, 'cover' => false, 'size' => false + 'driver' => $this->driver, 'cover' => false, 'size' => false, + 'linkPreview' => $this->getPreviewCoverLinkSetting($context), ]; $preferredSize = $this->getCoverSize($context, $default); if (empty($preferredSize)) { // covers disabled entirely diff --git a/themes/bootstrap3/js/preview.js b/themes/bootstrap3/js/preview.js index e7faf989ac1b0df9bca998040b7cacbacc794051..a94d594462efb87fc4c6bbdf565a76f6a91b579f 100644 --- a/themes/bootstrap3/js/preview.js +++ b/themes/bootstrap3/js/preview.js @@ -43,7 +43,7 @@ function applyPreviewUrl($link, url) { // Update associated record thumbnail, if any: $link.parents('.result,.record') - .find('.recordcover').parents('a').attr('href', url); + .find('.recordcover[data-linkpreview="true"]').parents('a').attr('href', url); } function processBookInfo(booksInfo, previewClass, viewOptions) { diff --git a/themes/bootstrap3/templates/record/cover.phtml b/themes/bootstrap3/templates/record/cover.phtml index 69295273c65b4ead89e78b5f1973b295151ba545..435cb53795041383fc3d79210076705b1f28c906 100644 --- a/themes/bootstrap3/templates/record/cover.phtml +++ b/themes/bootstrap3/templates/record/cover.phtml @@ -1,8 +1,8 @@ <? /* Display thumbnail if appropriate: */ ?> <? if ($cover): ?> <? if ($this->link): ?><a href="<?=$this->escapeHtmlAttr($this->link)?>"><? endif; ?> - <img alt="<?=$this->transEsc('Cover Image')?>" class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>"/> + <img alt="<?=$this->transEsc('Cover Image')?>" <? if ($linkPreview): ?>data-linkpreview="true" <? endif; ?>class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>"/> <? if ($this->link): ?></a><? endif; ?> <? else: ?> - <img src="<?=$this->url('cover-unavailable')?>" class="recordcover" alt="<?=$this->transEsc('No Cover Image')?>"/> + <img src="<?=$this->url('cover-unavailable')?>" <? if ($linkPreview): ?>data-linkpreview="true" <? endif; ?>class="recordcover" alt="<?=$this->transEsc('No Cover Image')?>"/> <? endif; ?>