-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace bootstrap-tagsinput with Tom Select
bootstrap-tagsinput is unsupported and out of date. Tom Select supports using a text input, has a similar method of loading remote data, and has both Bootstrap 4 and 5 assets. Vendoring the assets for now, but if we change the asset pipeline for Spotlight v4 perhaps we can remove that.
- Loading branch information
1 parent
ac477bc
commit 1e85361
Showing
32 changed files
with
12,124 additions
and
1,764 deletions.
There are no files selected for viewing
5,879 changes: 5,317 additions & 562 deletions
5,879
app/assets/javascripts/spotlight/spotlight.esm.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
@import "utilities"; | ||
@import "view_larger"; | ||
@import "accessibility"; | ||
@import "tom_select_fix"; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.