Skip to content

Commit

Permalink
Attach the JS libraries using the preprocess and not in the template. (
Browse files Browse the repository at this point in the history
…#39)

* Attach the JS libraries using the preprocess and not in the template.

* Don't need to add openseadragon/openseadragon as init has a depdenecy on it.

* closes Islandora/documentation#1975
  • Loading branch information
jordandukart authored Oct 26, 2021
1 parent 6ffd810 commit 19eb94e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 6 additions & 4 deletions openseadragon.module
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function template_preprocess_openseadragon_formatter(&$variables) {
if (!empty($tile_sources)) {

$viewer_settings['sequenceMode'] = count($tile_sources) > 1 && !$viewer_settings['collectionMode'];

$variables['#attached']['library'] = [
'openseadragon/init',
];
$variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [
'basePath' => Url::fromUri($iiif_address),
'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'],
Expand All @@ -93,9 +95,6 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {
// Load the global settings.
$config = \Drupal::service('openseadragon.config');

// @todo Once Libraries API is finished find a function for this.
$base_library_path = 'sites/all/assets/vendor';

// Build the gallery id.
$openseadragon_viewer_id = Html::getUniqueId('openseadragon-viewer-iiif-manifest-block');

Expand All @@ -115,6 +114,9 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {

// Attach the viewer, using the image urls obtained from the manifest.
if (!is_null($iiif_address) && !empty($iiif_address) && !empty($tile_sources)) {
$variables['#attached']['library'] = [
'openseadragon/init',
];
$variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [
'basePath' => Url::fromUri($iiif_address),
'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'],
Expand Down
2 changes: 0 additions & 2 deletions templates/openseadragon-formatter.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
* @ingroup themeable
*/
#}
{{ attach_library('libraries/openseadragon') }}
{{ attach_library('openseadragon/init') }}
<div {{ attributes }}></div>
2 changes: 0 additions & 2 deletions templates/openseadragon-iiif-manifest-block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
* @ingroup themeable
*/
#}
{{ attach_library('libraries/openseadragon') }}
{{ attach_library('openseadragon/init') }}
<div {{ attributes }}></div>

0 comments on commit 19eb94e

Please sign in to comment.