From 6c9ae44af1b54f5acf9f8cb87a588b9f65ba91c7 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Fri, 20 Nov 2020 16:45:27 -0400 Subject: [PATCH] Cdn change (#26) Changes code to use a CDN for the openseadragon JS and images --- README.md | 10 ++++------ openseadragon.libraries.yml | 17 ++++++++++++++--- openseadragon.module | 10 +++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4a8ed71..f0dc301 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,16 @@ Drupal 8 FieldFormatter to display an image or generic file using a IIIF Image s * [drupal/libraries](https://www.drupal.org/project/libraries) * [drupal/token](https://www.drupal.org/project/token) -* [OpenSeadragon library](https://github.com/openseadragon/openseadragon) ## Installation -As a Drupal module, this module can be installed via composer and enabled via Drush, like: +This module can be installed via composer and enabled via Drush, like: 1. `composer require islandora/openseadragon:dev-8.x-1.x` -2. download the version of OpenSeadragon that you want to install (i.e. download a release zip or tar from https://github.com/openseadragon/openseadragon/releases and unarchive it) -3. place the version of OpenSeadragon in your drupal install in a location such as `web/sites/all/assets/vendor/openseadragon` -4. `drush pm-en openseadragon` +1. `drush pm-en openseadragon` -If you are using the [islandora-playbook](https://github.com/Islandora-Devops/islandora-playbook), there is an [Ansible role](https://github.com/Islandora-Devops/ansible-role-drupal-openseadragon) already built for installing OpenSeadragon. +Downloading/deploying the openseadragon library itself is not neccessary, as it is referenced externally via a CDN. +If you are using the [islandora-playbook](https://github.com/Islandora-Devops/islandora-playbook), there is an [Ansible role](https://github.com/Islandora-Devops/ansible-role-drupal-openseadragon) already built for installing OpenSeadragon. ## Configuration diff --git a/openseadragon.libraries.yml b/openseadragon.libraries.yml index c62d11b..1954322 100644 --- a/openseadragon.libraries.yml +++ b/openseadragon.libraries.yml @@ -6,6 +6,17 @@ init: component: css/openseadragon.css: {} dependencies: - - core/jquery - - core/jquery.once - - core/drupalSettings + - core/jquery + - core/jquery.once + - core/drupalSettings + - openseadragon/openseadragon + +openseadragon: + remote: https://openseadragon.github.io + version: 2.4.2 + license: + name: New BSD + url: https://openseadragon.github.io/license/ + gpl-compatible: true + js: + https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/openseadragon.min.js: { type: external, minified: true } diff --git a/openseadragon.module b/openseadragon.module index 5919a77..4af8ce5 100644 --- a/openseadragon.module +++ b/openseadragon.module @@ -20,13 +20,12 @@ function openseadragon_libraries_info() { 'download url' => 'https://github.com/openseadragon/openseadragon/master/zipball', 'version arguments' => [ 'file' => 'openseadragon.js', - // //! openseadragon 2.2.1. 'pattern' => '@openseadragon ([0-9\.-]+)@', 'lines' => 1, 'columns' => 50, ], 'versions' => [ - '2.2.1' => [ + '2.4.2' => [ 'files' => [ 'js' => [ 'openseadragon.js', @@ -68,9 +67,6 @@ function template_preprocess_openseadragon_formatter(&$variables) { $config = \Drupal::service('openseadragon.config'); $fileinfo_service = \Drupal::service('openseadragon.fileinfo'); - // TODO: Once Libraries API is finished find a function for this. - $base_library_path = 'sites/all/assets/vendor'; - $classes_array = ['openseadragon-viewer']; $viewer_settings = $config->getSettings(TRUE); $iiif_address = $config->getIiifAddress(); @@ -106,7 +102,7 @@ function template_preprocess_openseadragon_formatter(&$variables) { 'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'], 'options' => [ 'id' => $openseadragon_viewer_id, - 'prefixUrl' => file_create_url("{$base_library_path}/openseadragon/images/"), + 'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/', 'tileSources' => $tile_sources, ] + $viewer_settings, ]; @@ -151,7 +147,7 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) { 'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'], 'options' => [ 'id' => $openseadragon_viewer_id, - 'prefixUrl' => file_create_url("{$base_library_path}/openseadragon/images/"), + 'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/', 'tileSources' => $tile_sources, ] + $viewer_settings, ];