From 9f5ad51777ac4e848c22da05bedff85b8350be4f Mon Sep 17 00:00:00 2001 From: Huda Khan Date: Fri, 20 Dec 2024 10:07:33 -0700 Subject: [PATCH] merging in main --- .../javascripts/spotlight/spotlight.esm.js | 60 +++++-------------- .../spotlight/spotlight.esm.js.map | 2 +- app/assets/javascripts/spotlight/spotlight.js | 60 +++++-------------- .../javascripts/spotlight/spotlight.js.map | 2 +- 4 files changed, 32 insertions(+), 92 deletions(-) diff --git a/app/assets/javascripts/spotlight/spotlight.esm.js b/app/assets/javascripts/spotlight/spotlight.esm.js index 06395b9d1..f9cd1b018 100644 --- a/app/assets/javascripts/spotlight/spotlight.esm.js +++ b/app/assets/javascripts/spotlight/spotlight.esm.js @@ -3679,10 +3679,10 @@ class Crop { // there should only one element with this data-cropper attribute value. this.cropSelector = '[data-cropper="' + cropArea.data('cropperKey') + '"]'; this.cropTool = $(this.cropSelector); - // Exhibit and masthead cropping preserves aspect ratio, while item - // and other widget related cropping does not preserve aspect ratio in the cropping area. + // Exhibit and masthead cropping requires the ratio between image width and height + // to be consistent, whereas item widget cropping allows any combination of + // image width and height. this.preserveAspectRatio = preserveAspectRatio; - this.formPrefix = this.cropTool.data('form-prefix'); // Get the IIIF input elements used to store/reference IIIF information this.inputPrefix = this.cropTool.data('input-prefix'); this.iiifUrlField = this.iiifInputElement(this.inputPrefix, 'iiif_tilesource', this.cropTool); @@ -3918,9 +3918,12 @@ class Crop { } var input = $('[data-behavior="autocomplete"]', this.cropTool); - var panel = $(input.data('target-panel')); - - addImageSelector(input, panel, this.iiifManifestField.val(), !this.iiifImageField.val()); + + // Not every page which uses this module has autocomplete linked directly to the cropping tool + if(input.length) { + var panel = $(input.data('target-panel')); + addImageSelector(input, panel, this.iiifManifestField.val(), !this.iiifImageField.val()); + } } invalidateMapSizeOnTabToggle() { @@ -3970,7 +3973,11 @@ class Crop { } setUploadId(id) { - $('#' + this.formPrefix + "_upload_id").val(id); + // This input is currently used for exhibit masthead or thumbnail image upload. + // The name should be sufficient in this case, as we don't use this part of the + // code for solr document widgets where we enable cropping. + // If we require more specificity, we can scope this to this.cropTool. + $('input[name="' + this.inputPrefix + '[upload_id]"]').val(id); } aspectRatioPreservingRectangleEditor(aspect) { @@ -4015,45 +4022,11 @@ class CroppableModal { var dataCropperDiv = $('#blacklight-modal [data-behavior="iiif-cropper"]'); if(dataCropperDiv) { - dataCropperDiv.data('cropper-key'); - dataCropperDiv.data('index-id'); - //var iiifFields = context.getIIIFObject(dataCropperKey, itemIndex); - // The region field is set separately within the modal div - //iiifFields['iiifRegionField'] = context.setRegionField(dataCropperKey, itemIndex); new Crop(dataCropperDiv, false).render(); - //context.attachModalSaveHandler(dataCropperKey); } }); } - setRegionField(dataCropperKey, itemIndex) { - var regionField = $('#blacklight-modal input[name="select_image_region'); - var itemElement = $('[data-cropper="' + dataCropperKey + '"]'); - var thumbnailUrl = this.iiifInputField(itemIndex, 'thumbnail_image_url', itemElement).val(); - var region = this.extractRegionField(thumbnailUrl); - regionField.val(region); - return regionField; - } - //When editing an existing/saved item, extract region values based on url - extractRegionField(iiifThumbnailUrl) { - if (iiifThumbnailUrl != null && iiifThumbnailUrl.length == 0) return null; - - var regex = /\/[0-9]+,[0-9]+,[0-9]+,[0-9]+\//; - var match = iiifThumbnailUrl.match(regex); - return match[0].replaceAll('/', ''); - } - - getIIIFObject(dataCropperKey, itemIndex) { - var iiifFields = {}; - //Retrieve the fields from the main page with the itemIndex - var itemElement = $('[data-cropper="' + dataCropperKey + '"]'); - iiifFields['iiifUrlField'] = this.iiifInputField(itemIndex, 'iiif_tilesource', itemElement); - iiifFields['iiifManifestField'] = this.iiifInputField(itemIndex, 'iiif_manifest_url', itemElement); - iiifFields['iiifCanvasField'] = this.iiifInputField(itemIndex, 'iiif_canvas_id', itemElement); - iiifFields['iiifImageField'] = this.iiifInputField(itemIndex, 'iiif_image_id', itemElement); - return iiifFields; - } - // Field names are of the format item[item_0][iiif_image_id] iiifInputField(itemIndex, fieldName, parentElement) { var itemPrefix = 'item[' + itemIndex + ']'; @@ -4086,14 +4059,11 @@ class CroppableModal { var thumbnailSaveField = context.iiifInputField(itemIndex, 'thumbnail_image_url', itemElement); var fullimageSaveField = context.iiifInputField(itemIndex, 'full_image_url', itemElement); var iiifTilesource = context.iiifInputField(itemIndex, 'iiif_tilesource', itemElement).val(); - // Get the region value saved in the modal for the selected area - //var regionElement = $('#blacklight-modal input[name="select_image_region"]'); - //var regionValue = regionElement.val(); var regionValue = context.iiifInputField(itemIndex, 'iiif_region', itemElement).val(); // Extract the region string to incorporate into the thumbnail URL var urlPrefix = iiifTilesource.substring(0, iiifTilesource.lastIndexOf('/info.json')); var thumbnailUrl = urlPrefix + '/' + regionValue + '/!400,400/0/default.jpg'; - // Set the hidden inpt value to the thumbnail URL + // Set the hidden input value to the thumbnail URL // Also set the full image - which is used by widgets like carousel or slideshow thumbnailSaveField.val(thumbnailUrl); fullimageSaveField.val(urlPrefix + '/' + regionValue + '/!800,800/0/default.jpg'); diff --git a/app/assets/javascripts/spotlight/spotlight.esm.js.map b/app/assets/javascripts/spotlight/spotlight.esm.js.map index 179a3fa0c..b858d0f80 100644 --- a/app/assets/javascripts/spotlight/spotlight.esm.js.map +++ b/app/assets/javascripts/spotlight/spotlight.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"spotlight.esm.js","sources":["../../../../vendor/assets/javascripts/tiny-slider.js","../../../javascript/spotlight/user/browse_group_categories.js","../../../javascript/spotlight/user/carousel.js","../../../javascript/spotlight/user/clear_form_button.js","../../../javascript/spotlight/user/report_a_problem.js","../../../javascript/spotlight/user/zpr_links.js","../../../javascript/spotlight/user/index.js","../../../javascript/spotlight/admin/add_another.js","../../../javascript/spotlight/admin/add_new_button.js","../../../javascript/spotlight/admin/blacklight_configuration.js","../../../javascript/spotlight/admin/copy_email_addresses.js","../../../javascript/spotlight/admin/iiif.js","../../../javascript/spotlight/admin/add_image_selector.js","../../../javascript/spotlight/core.js","../../../javascript/spotlight/admin/crop.js","../../../javascript/spotlight/admin/croppable_modal.js","../../../javascript/spotlight/admin/croppable.js","../../../javascript/spotlight/admin/edit_in_place.js","../../../javascript/spotlight/admin/exhibit_tag_autocomplete.js","../../../../vendor/assets/javascripts/parameterize.js","../../../javascript/spotlight/admin/exhibits.js","../../../javascript/spotlight/admin/form_observer.js","../../../javascript/spotlight/admin/locks.js","../../../javascript/spotlight/admin/multi_image_selector.js","../../../javascript/spotlight/admin/pages.js","../../../javascript/spotlight/admin/progress_monitor.js","../../../javascript/spotlight/admin/readonly_checkbox.js","../../../javascript/spotlight/admin/search_typeahead.js","../../../javascript/spotlight/admin/select_related_input.js","../../../javascript/spotlight/admin/spotlight_nestable.js","../../../javascript/spotlight/admin/tabs.js","../../../javascript/spotlight/admin/translation_progress.js","../../../javascript/spotlight/admin/visibility_toggle.js","../../../javascript/spotlight/admin/users.js","../../../javascript/spotlight/admin/block_mixins/autocompleteable.js","../../../javascript/spotlight/admin/block_mixins/formable.js","../../../javascript/spotlight/admin/block_mixins/plustextable.js","../../../javascript/spotlight/admin/blocks/block.js","../../../javascript/spotlight/admin/blocks/resources_block.js","../../../javascript/spotlight/admin/blocks/browse_block.js","../../../javascript/spotlight/admin/blocks/browse_group_categories_block.js","../../../javascript/spotlight/admin/blocks/iframe_block.js","../../../javascript/spotlight/admin/blocks/link_to_search_block.js","../../../javascript/spotlight/admin/blocks/oembed_block.js","../../../javascript/spotlight/admin/blocks/pages_block.js","../../../javascript/spotlight/admin/blocks/rule_block.js","../../../javascript/spotlight/admin/blocks/search_result_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_base_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_carousel_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_embed_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_features_block.js","../../../javascript/spotlight/admin/blocks/solr_documents_grid_block.js","../../../javascript/spotlight/admin/blocks/uploaded_items_block.js","../../../javascript/spotlight/admin/sir-trevor/block_controls.js","../../../javascript/spotlight/admin/sir-trevor/block_limits.js","../../../javascript/spotlight/admin/sir-trevor/locales.js","../../../javascript/spotlight/admin/index.js","../../../javascript/spotlight/index.js"],"sourcesContent":["// Includes an unreleased RTL support pull request: https://github.com/ganlanyuan/tiny-slider/pull/658\n// Includes \"export default tns\" at the end of the file for spotlight/user/browse_group_categories.js\nvar tns = (function (){\nvar win = window;\n\nvar raf = win.requestAnimationFrame\n || win.webkitRequestAnimationFrame\n || win.mozRequestAnimationFrame\n || win.msRequestAnimationFrame\n || function(cb) { return setTimeout(cb, 16); };\n\nvar win$1 = window;\n\nvar caf = win$1.cancelAnimationFrame\n || win$1.mozCancelAnimationFrame\n || function(id){ clearTimeout(id); };\n\nfunction extend() {\n var obj, name, copy,\n target = arguments[0] || {},\n i = 1,\n length = arguments.length;\n\n for (; i < length; i++) {\n if ((obj = arguments[i]) !== null) {\n for (name in obj) {\n copy = obj[name];\n\n if (target === copy) {\n continue;\n } else if (copy !== undefined) {\n target[name] = copy;\n }\n }\n }\n }\n return target;\n}\n\nfunction checkStorageValue (value) {\n return ['true', 'false'].indexOf(value) >= 0 ? JSON.parse(value) : value;\n}\n\nfunction setLocalStorage(storage, key, value, access) {\n if (access) {\n try { storage.setItem(key, value); } catch (e) {}\n }\n return value;\n}\n\nfunction getSlideId() {\n var id = window.tnsId;\n window.tnsId = !id ? 1 : id + 1;\n \n return 'tns' + window.tnsId;\n}\n\nfunction getBody () {\n var doc = document,\n body = doc.body;\n\n if (!body) {\n body = doc.createElement('body');\n body.fake = true;\n }\n\n return body;\n}\n\nvar docElement = document.documentElement;\n\nfunction setFakeBody (body) {\n var docOverflow = '';\n if (body.fake) {\n docOverflow = docElement.style.overflow;\n //avoid crashing IE8, if background image is used\n body.style.background = '';\n //Safari 5.13/5.1.4 OSX stops loading if ::-webkit-scrollbar is used and scrollbars are visible\n body.style.overflow = docElement.style.overflow = 'hidden';\n docElement.appendChild(body);\n }\n\n return docOverflow;\n}\n\nfunction resetFakeBody (body, docOverflow) {\n if (body.fake) {\n body.remove();\n docElement.style.overflow = docOverflow;\n // Trigger layout so kinetic scrolling isn't disabled in iOS6+\n // eslint-disable-next-line\n docElement.offsetHeight;\n }\n}\n\n// get css-calc \n\nfunction calc() {\n var doc = document, \n body = getBody(),\n docOverflow = setFakeBody(body),\n div = doc.createElement('div'), \n result = false;\n\n body.appendChild(div);\n try {\n var str = '(10px * 10)',\n vals = ['calc' + str, '-moz-calc' + str, '-webkit-calc' + str],\n val;\n for (var i = 0; i < 3; i++) {\n val = vals[i];\n div.style.width = val;\n if (div.offsetWidth === 100) { \n result = val.replace(str, ''); \n break;\n }\n }\n } catch (e) {}\n \n body.fake ? resetFakeBody(body, docOverflow) : div.remove();\n\n return result;\n}\n\n// get subpixel support value\n\nfunction percentageLayout() {\n // check subpixel layout supporting\n var doc = document,\n body = getBody(),\n docOverflow = setFakeBody(body),\n wrapper = doc.createElement('div'),\n outer = doc.createElement('div'),\n str = '',\n count = 70,\n perPage = 3,\n supported = false;\n\n wrapper.className = \"tns-t-subp2\";\n outer.className = \"tns-t-ct\";\n\n for (var i = 0; i < count; i++) {\n str += '
';\n }\n\n outer.innerHTML = str;\n wrapper.appendChild(outer);\n body.appendChild(wrapper);\n\n supported = Math.abs(wrapper.getBoundingClientRect().left - outer.children[count - perPage].getBoundingClientRect().left) < 2;\n\n body.fake ? resetFakeBody(body, docOverflow) : wrapper.remove();\n\n return supported;\n}\n\nfunction mediaquerySupport () {\n if (window.matchMedia || window.msMatchMedia) {\n return true;\n }\n \n var doc = document,\n body = getBody(),\n docOverflow = setFakeBody(body),\n div = doc.createElement('div'),\n style = doc.createElement('style'),\n rule = '@media all and (min-width:1px){.tns-mq-test{position:absolute}}',\n position;\n\n style.type = 'text/css';\n div.className = 'tns-mq-test';\n\n body.appendChild(style);\n body.appendChild(div);\n\n if (style.styleSheet) {\n style.styleSheet.cssText = rule;\n } else {\n style.appendChild(doc.createTextNode(rule));\n }\n\n position = window.getComputedStyle ? window.getComputedStyle(div).position : div.currentStyle['position'];\n\n body.fake ? resetFakeBody(body, docOverflow) : div.remove();\n\n return position === \"absolute\";\n}\n\n// create and append style sheet\nfunction createStyleSheet (media, nonce) {\n // Create the