spotlight-frontend 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,9 +78,9 @@ See more detailed instructions for development environment setup at ["Contributi
78
78
  ## With Docker
79
79
 
80
80
  ```sh
81
- # because of how docker-compose handles named images, running `docker-compose up --build` will error when the Rails images have not been built locally
82
- docker-compose build
83
- docker-compose up
81
+ # because of how docker compose handles named images, running `docker compose up --build` will error when the Rails images have not been built locally
82
+ docker compose build
83
+ docker compose up
84
84
  ```
85
85
 
86
86
  ## Tests
@@ -5135,6 +5135,7 @@ jQuery.fn.scrollStop = function(callback) {
5135
5135
  };
5136
5136
 
5137
5137
  // Place all the behaviors and hooks related to the matching controller here.
5138
+ // All this logic will automatically be available in application.js.
5138
5139
 
5139
5140
  class Pages {
5140
5141
  connect(){
@@ -5601,6 +5602,8 @@ class CheckboxSubmit {
5601
5602
  }
5602
5603
 
5603
5604
  // Visibility toggle for items in an exhibit, based on Blacklight's bookmark toggle
5605
+ // See: https://github.com/projectblacklight/blacklight/blob/main/app/javascript/blacklight/bookmark_toggle.js
5606
+
5604
5607
 
5605
5608
  const VisibilityToggle = (e) => {
5606
5609
  if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) {
@@ -5927,10 +5930,24 @@ Spotlight$1.Block.Resources = (function(){
5927
5930
  formable: true,
5928
5931
  autocompleteable: true,
5929
5932
  show_heading: true,
5933
+ show_alt_text: true,
5930
5934
 
5931
5935
  title: function() { return i18n.t("blocks:" + this.type + ":title"); },
5932
5936
  description: function() { return i18n.t("blocks:" + this.type + ":description"); },
5933
-
5937
+ alt_text_guidelines: function() {
5938
+ if (this.show_alt_text) {
5939
+ return i18n.t("blocks:alt_text_guidelines:intro");
5940
+ }
5941
+ return "";
5942
+ },
5943
+ alt_text_guidelines_link: function() {
5944
+ if (this.show_alt_text) {
5945
+ var link_url = i18n.t("blocks:alt_text_guidelines:link_url");
5946
+ var link_label = i18n.t("blocks:alt_text_guidelines:link_label");
5947
+ return '<a target="_blank" href="' + link_url + '">' + link_label + '</a>';
5948
+ }
5949
+ return "";
5950
+ },
5934
5951
  icon_name: "resources",
5935
5952
  blockGroup: function() { return i18n.t("blocks:group:items") },
5936
5953
 
@@ -5940,6 +5957,8 @@ Spotlight$1.Block.Resources = (function(){
5940
5957
  show_secondary_field_key: "show-secondary-caption",
5941
5958
 
5942
5959
  display_checkbox: "display-checkbox",
5960
+ decorative_checkbox: "decorative-checkbox",
5961
+ alt_text_textarea: "alt-text-textarea",
5943
5962
 
5944
5963
  globalIndex: 0,
5945
5964
 
@@ -5947,6 +5966,13 @@ Spotlight$1.Block.Resources = (function(){
5947
5966
  return [];
5948
5967
  },
5949
5968
 
5969
+ _altTextFieldsHTML: function(index, data) {
5970
+ if (this.show_alt_text) {
5971
+ return this.altTextHTML(index, data);
5972
+ }
5973
+ return "";
5974
+ },
5975
+
5950
5976
  _itemPanel: function(data) {
5951
5977
  var index = "item_" + this.globalIndex++;
5952
5978
  var checked;
@@ -5977,6 +6003,7 @@ Spotlight$1.Block.Resources = (function(){
5977
6003
  <div class="main">
5978
6004
  <div class="title card-title">${data.title}</div>
5979
6005
  <div>${(data.slug || data.id)}</div>
6006
+ ${this._altTextFieldsHTML(index, data)}
5980
6007
  </div>
5981
6008
  <div class="remove float-right float-end">
5982
6009
  <a data-item-grid-panel-remove="true" href="#">${i18n.t("blocks:resources:panel:remove")}</a>
@@ -6013,6 +6040,7 @@ Spotlight$1.Block.Resources = (function(){
6013
6040
 
6014
6041
  createItemPanel: function(data) {
6015
6042
  var panel = this._itemPanel(data);
6043
+ this.attachAltTextHandlers(panel);
6016
6044
  $(panel).appendTo($('.panels > ol', this.inner));
6017
6045
  $('[data-behavior="nestable"]', this.inner).trigger('change');
6018
6046
  },
@@ -6045,11 +6073,67 @@ Spotlight$1.Block.Resources = (function(){
6045
6073
  return `<div class="form resources-admin clearfix">
6046
6074
  <div class="widget-header">
6047
6075
  ${this.description()}
6076
+ ${this.alt_text_guidelines()}
6077
+ ${this.alt_text_guidelines_link()}
6048
6078
  </div>
6049
6079
  ${this.content()}
6050
6080
  </div>`
6051
6081
  },
6052
6082
 
6083
+ _altTextData: function(data) {
6084
+ const isDecorative = data.decorative;
6085
+ const altText = isDecorative ? '' : (data.alt_text || '');
6086
+ const altTextBackup = data.alt_text_backup || '';
6087
+ const placeholderAttr = isDecorative ? '' : `placeholder="${i18n.t("blocks:resources:alt_text:placeholder")}"`;
6088
+ const disabledAttr = isDecorative ? 'disabled' : '';
6089
+
6090
+ return { isDecorative, altText, altTextBackup, placeholderAttr, disabledAttr };
6091
+ },
6092
+
6093
+ altTextHTML: function(index, data) {
6094
+ const { isDecorative, altText, altTextBackup, placeholderAttr, disabledAttr } = this._altTextData(data);
6095
+ return `<div class="mt-2 pt-2 d-flex">
6096
+ <div class="me-2 mr-2">
6097
+ <label class="col-form-label pb-0 pt-1" for="${this.formId(this.alt_text_textarea + '_' + data.id)}">${i18n.t("blocks:resources:alt_text:alternative_text")}</label>
6098
+ <div class="form-check mb-1 justify-content-end">
6099
+ <input class="form-check-input" type="checkbox"
6100
+ id="${this.formId(this.decorative_checkbox + '_' + data.id)}" name="item[${index}][decorative]" ${isDecorative ? 'checked' : ''}>
6101
+ <label class="form-check-label" for="${this.formId(this.decorative_checkbox + '_' + data.id)}">${i18n.t("blocks:resources:alt_text:decorative")}</label>
6102
+ </div>
6103
+ </div>
6104
+ <div class="flex-grow-1 flex-fill d-flex">
6105
+ <input type="hidden" name="item[${index}][alt_text_backup]" value="${altTextBackup}" />
6106
+ <textarea class="form-control w-100" rows="2" ${placeholderAttr}
6107
+ id="${this.formId(this.alt_text_textarea + '_' + data.id)}" name="item[${index}][alt_text]" ${disabledAttr}>${altText}</textarea>
6108
+ </div>
6109
+ </div>`
6110
+ },
6111
+
6112
+ attachAltTextHandlers: function(panel) {
6113
+ if (this.show_alt_text) {
6114
+ const decorativeCheckbox = $('input[name$="[decorative]"]', panel);
6115
+ const altTextInput = $('textarea[name$="[alt_text]"]', panel);
6116
+ const altTextBackupInput = $('input[name$="[alt_text_backup]"]', panel);
6117
+
6118
+ decorativeCheckbox.on('change', function() {
6119
+ const isDecorative = this.checked;
6120
+ if (isDecorative) {
6121
+ altTextBackupInput.val(altTextInput.val());
6122
+ altTextInput.val('');
6123
+ } else {
6124
+ altTextInput.val(altTextBackupInput.val());
6125
+ }
6126
+ altTextInput
6127
+ .prop('disabled', isDecorative)
6128
+ .attr('placeholder', isDecorative ? '' : i18n.t("blocks:resources:alt_text:placeholder"));
6129
+ });
6130
+
6131
+ altTextInput.on('input', function() {
6132
+ $(this).data('lastValue', $(this).val());
6133
+ });
6134
+ }
6135
+ },
6136
+
6053
6137
  onBlockRender: function() {
6054
6138
  Module.init($('[data-behavior="nestable"]', this.inner));
6055
6139
 
@@ -6239,7 +6323,7 @@ SirTrevor.Blocks.BrowseGroupCategories = (function(){
6239
6323
  },
6240
6324
 
6241
6325
  item_options: function() { return `
6242
- '<label>
6326
+ <label>
6243
6327
  <input type="hidden" name="display-item-counts" value="false" />
6244
6328
  <input type="checkbox" name="display-item-counts" value="true" checked />
6245
6329
  ${i18n.t("blocks:browse_group_categories:item_counts")}
@@ -6674,7 +6758,7 @@ SirTrevor.Blocks.SolrDocumentsEmbed = (function(){
6674
6758
 
6675
6759
  return SirTrevor.Blocks.SolrDocumentsBase.extend({
6676
6760
  type: "solr_documents_embed",
6677
-
6761
+ show_alt_text: false,
6678
6762
  icon_name: "item_embed",
6679
6763
 
6680
6764
  item_options: function() { return "" },
@@ -6838,6 +6922,7 @@ SirTrevor.Blocks.UploadedItems = (function(){
6838
6922
  <label for="${this.formId('link_' + dataId)}" class="col-form-label col-md-3">${i18n.t("blocks:uploaded_items:link")}</label>
6839
6923
  <input type="text" class="form-control col" id="${this.formId('link_' + dataId)}" name="item[${index}][link]" data-field="link"/>
6840
6924
  </div>
6925
+ ${this._altTextFieldsHTML(index, data)}
6841
6926
  </div>
6842
6927
  <div class="remove float-right float-end">
6843
6928
  <a data-item-grid-panel-remove="true" href="#">${i18n.t("blocks:resources:panel:remove")}</a>
@@ -6865,6 +6950,8 @@ SirTrevor.Blocks.UploadedItems = (function(){
6865
6950
  return `<div class="form oembed-text-admin clearfix">
6866
6951
  <div class="widget-header">
6867
6952
  ${this.description()}
6953
+ ${this.alt_text_guidelines()}
6954
+ ${this.alt_text_guidelines_link()}
6868
6955
  </div>
6869
6956
  <div class="row">
6870
6957
  <div class="form-group mb-3 col-md-8">
@@ -6884,6 +6971,24 @@ SirTrevor.Blocks.UploadedItems = (function(){
6884
6971
  </div>`
6885
6972
  },
6886
6973
 
6974
+ altTextHTML: function(index, data) {
6975
+ const { isDecorative, altText, altTextBackup, placeholderAttr, disabledAttr } = this._altTextData(data);
6976
+ return `
6977
+ <div class="field row mr-3 me-3">
6978
+ <div class="col-lg-3 ps-md-2 pl-md-2">
6979
+ <label class="col-form-label text-nowrap pb-0 pt-1 justify-content-md-start justify-content-lg-end d-flex" for="${this.formId(this.alt_text_textarea + '_' + data.id)}">${i18n.t("blocks:resources:alt_text:alternative_text")}</label>
6980
+ <div class="form-check d-flex justify-content-md-start justify-content-lg-end">
6981
+ <input class="form-check-input" type="checkbox"
6982
+ id="${this.formId(this.decorative_checkbox + '_' + data.id)}" name="item[${index}][decorative]" ${isDecorative ? 'checked' : ''}>
6983
+ <label class="form-check-label" for="${this.formId(this.decorative_checkbox + '_' + data.id)}">${i18n.t("blocks:resources:alt_text:decorative")}</label>
6984
+ </div>
6985
+ </div>
6986
+ <input type="hidden" name="item[${index}][alt_text_backup]" value="${altTextBackup}" />
6987
+ <textarea class="col-lg-9" rows="2" ${placeholderAttr}
6988
+ id="${this.formId(this.alt_text_textarea + '_' + data.id)}" name="item[${index}][alt_text]" ${disabledAttr}>${altText}</textarea>
6989
+ </div>`
6990
+ },
6991
+
6887
6992
  zpr_key: 'zpr_link'
6888
6993
  });
6889
6994
  })();
@@ -7094,6 +7199,11 @@ SirTrevor.Locales.en.blocks = $.extend(SirTrevor.Locales.en.blocks, {
7094
7199
  drag: "Drag",
7095
7200
  display: "Display?",
7096
7201
  remove: "Remove"
7202
+ },
7203
+ alt_text: {
7204
+ decorative: "Decorative",
7205
+ alternative_text: "Alternative text",
7206
+ placeholder: "Enter alt text for this item..."
7097
7207
  }
7098
7208
  },
7099
7209
 
@@ -7159,6 +7269,12 @@ SirTrevor.Locales.en.blocks = $.extend(SirTrevor.Locales.en.blocks, {
7159
7269
  group: {
7160
7270
  undefined: "Standard widgets",
7161
7271
  items: "Exhibit item widgets"
7272
+ },
7273
+
7274
+ alt_text_guidelines: {
7275
+ intro: 'For each item, please enter alternative text or appropriately check the decorative box. ',
7276
+ link_label: 'Guidelines for writing alt text.',
7277
+ link_url: 'https://www.w3.org/WAI/tutorials/images/'
7162
7278
  }
7163
7279
  });
7164
7280