Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Replace bootstrap-tagsinput with Tom Select #3074

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,879 changes: 5,317 additions & 562 deletions app/assets/javascripts/spotlight/spotlight.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.esm.js.map

Large diffs are not rendered by default.

5,879 changes: 5,317 additions & 562 deletions app/assets/javascripts/spotlight/spotlight.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.js.map

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions app/assets/stylesheets/spotlight/_catalog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,12 @@
}

form.edit_solr_document {
.bootstrap-tagsinput {
@extend .clearfix;
cursor: text;
}
.bg-warning.form-text {
font-size: 0.9em;
padding: 3px 6px;
}
}

.bootstrap-tagsinput {
display: block;
.twitter-typeahead {
width: auto;
}

.tt-input {
vertical-align: baseline !important;
}
}

.blacklight-catalog-edit, .blacklight-catalog-show {
.img-thumbnail {
@extend .col-md-6;
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/spotlight/_spotlight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@import "utilities";
@import "view_larger";
@import "accessibility";
@import "tom_select_fix";



Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/spotlight/_tom_select_fix.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Remove when this is fixed or we switch from sassc-rails: https://github.com/orchidjs/tom-select/issues/656
@function max($value, $value2) {
@return unquote('max(#{$value}, #{$value2})');
}
67 changes: 33 additions & 34 deletions app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import TomSelect from 'tom-select';

export default class {
connect() {
$('[data-autocomplete-tag="true"]').each(function(_i, el) {
var $el = $(el);
// By default tags input binds on page ready to [data-role=tagsinput],
// however, that doesn't work with Turbolinks. So we init manually:
$el.tagsinput();

var tags = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 100,
prefetch: {
url: $el.data('autocomplete-url'),
ttl: 1,
filter: function(list) {
// Let the dom know that the response has been returned
$el.attr('data-autocomplete-fetched', true);
return $.map(list, function(tag) { return { name: tag }; });
}
}
});

tags.initialize();
const tagOptions = {
closeAfterSelect: true,
create: true,
createOnBlur: true,
duplicates: false,
hideSelected: true,
labelField: 'name',
loadThrottle: 300,
maxOptions: 100,
persist: false,
plugins: ['remove_button'],
preload: true,
searchField: 'name',
valueField: 'name',
onItemAdd: function(value, item) {
this.control_input.value = '';
},
load: function(query, callback) {
fetch(this.input.dataset.autocompleteUrl)
.then(response => response.json())
.then(json => {
callback(json.map(tag => ({name: tag.trim()})));
}).catch(() => callback());
}
}

$el.tagsinput('input').typeahead({highlight: true, hint: false}, {
name: 'tags',
displayKey: 'name',
source: tags.ttAdapter()
}).bind('typeahead:selected', $.proxy(function (obj, datum) {
$el.tagsinput('add', datum.name);
$el.tagsinput('input').typeahead('val', '');
})).bind('blur', function() {
$el.tagsinput('add', $el.tagsinput('input').typeahead('val'));
$el.tagsinput('input').typeahead('val', '');
})
})
document.querySelectorAll('[data-autocomplete-tag="true"]').forEach(tagElement => {
// Handle leading spaces (e.g., 'Tag 1, Tag 2') or else the user can add what appear to be duplicate tags.
const items = tagElement.value.split(',').map(item => item.trim()).filter(Boolean);
const options = items.map(item => ({name: item}));
new TomSelect(tagElement, { ...tagOptions, items, options });
});
}
}
1 change: 0 additions & 1 deletion app/javascript/spotlight/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// These scripts are in the vendor directory
import 'nestable'
import 'parameterize'
import 'bootstrap-tagsinput'
import 'jquery.serializejson'
import 'leaflet-iiif'
import 'Leaflet.Editable'
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/spotlight/templates/spotlight.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import 'bootstrap-tagsinput';
@import 'spotlight/variables_bootstrap';
@import 'bootstrap';
@import 'sir-trevor/main';
@import 'leaflet';
@import 'spotlight/spotlight';
@import 'tom-select/tom-select.bootstrap4.min';
245 changes: 244 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading