app/assets/javascripts/spotlight/spotlight.js in blacklight-spotlight-3.6.0.beta4 vs app/assets/javascripts/spotlight/spotlight.js in blacklight-spotlight-3.6.0.beta5
- old
+ new
@@ -5097,11 +5097,11 @@
// Place all the behaviors and hooks related to the matching controller here.
class Pages {
connect(){
SirTrevor.setDefaults({
- iconUrl: Spotlight$1.sirTrevorIcon,
+ iconUrl: Spotlight.sirTrevorIcon,
uploadUrl: $('[data-attachment-endpoint]').data('attachment-endpoint'),
ajaxOptions: {
headers: {
'X-CSRF-Token': Spotlight$1.csrfToken() || ''
},
@@ -5301,16 +5301,15 @@
minLength: 0,
highlight: (typeAheadInput.data('autocomplete-highlight') || true),
hint: (typeAheadInput.data('autocomplete-hint') || false),
autoselect: (typeAheadInput.data('autocomplete-autoselect') || true)
}, options);
-
typeAheadInput.typeahead(settings, {
displayKey: settings.displayKey,
source: settings.bloodhound.ttAdapter(),
templates: {
- suggestion: Handlebars.compile(settings.template)
+ suggestion: settings.template
}
});
}
return this;
};
@@ -5333,17 +5332,19 @@
}
});
results.initialize();
return results;
}
- function itemsTemplate() {
- return '<div class="autocomplete-item{{#if private}} blacklight-private{{/if}}">{{#if thumbnail}}<div class="document-thumbnail"><img class="img-thumbnail" src="{{thumbnail}}" /></div>{{/if}}<span class="autocomplete-title">{{title}}</span><br/><small> {{description}}</small></div>';
+ function templateFunc(obj) {
+ const thumbnail = obj.thumbnail ? `<div class="document-thumbnail"><img class="img-thumbnail" src="${obj.thumbnail}" /></div>` : '';
+ return $(`<div class="autocomplete-item${obj.private ? ' blacklight-private' : ''}">${thumbnail}
+ <span class="autocomplete-title">${obj.title}</span><br/><small> ${obj.description}</small></div>`)
}
function addAutocompletetoFeaturedImage(){
if($('[data-featured-image-typeahead]').length > 0) {
- $('[data-featured-image-typeahead]').spotlightSearchTypeAhead({bloodhound: itemsBloodhound(), template: itemsTemplate()}).on('click', function() {
+ $('[data-featured-image-typeahead]').spotlightSearchTypeAhead({bloodhound: itemsBloodhound(), template: templateFunc}).on('click', function() {
$(this).select();
}).on('typeahead:selected typeahead:autocompleted', function(e, data) {
var panel = $($(this).data('target-panel'));
addImageSelector($(this), panel, data.iiif_manifest, true);
$($(this).data('id-field')).val(data['global_id']);
@@ -5658,14 +5659,10 @@
if (this['autocomplete_url'] === undefined) {
this.autocomplete_url = function() { return $('form[data-autocomplete-url]').data('autocomplete-url').replace("%25QUERY", "%QUERY"); };
}
- if (this['autocomplete_template'] === undefined) {
- this.autocomplete_url = function() { return '<div class="autocomplete-item{{#if private}} blacklight-private{{/if}}">{{#if thumbnail}}<div class="document-thumbnail"><img class="img-thumbnail" src="{{thumbnail}}" /></div>{{/if}}<span class="autocomplete-title">{{title}}</span><br/><small> {{description}}</small></div>' };
- }
-
if (this['transform_autocomplete_results'] === undefined) {
this.transform_autocomplete_results = (val) => val;
}
if (this['autocomplete_control'] === undefined) {
@@ -5683,11 +5680,11 @@
};
}
},
addAutocompletetoSirTrevorForm: function() {
- $('[data-twitter-typeahead]', this.inner).spotlightSearchTypeAhead({bloodhound: this.bloodhound(), template: this.autocomplete_template()}).on('typeahead:selected typeahead:autocompleted', this.autocompletedHandler()).on( 'focus', function() {
+ $('[data-twitter-typeahead]', this.inner).spotlightSearchTypeAhead({bloodhound: this.bloodhound(), template: this.autocomplete_template}).on('typeahead:selected typeahead:autocompleted', this.autocompletedHandler()).on( 'focus', function() {
if($(this).val() === '') {
$(this).data().ttTypeahead.input.trigger('queryChanged', '');
}
});
},
@@ -6037,12 +6034,17 @@
icon_name: "browse",
autocomplete_url: function() {
return $(this.inner).closest('form[data-autocomplete-exhibit-searches-path]').data('autocomplete-exhibit-searches-path').replace("%25QUERY", "%QUERY");
},
- autocomplete_template: function() { return '<div class="autocomplete-item{{#unless published}} blacklight-private{{/unless}}">{{#if thumbnail_image_url}}<div class="document-thumbnail"><img class="img-thumbnail" src="{{thumbnail_image_url}}" /></div>{{/if}}<span class="autocomplete-title">{{full_title}}</span><br/><small> {{description}}</small></div>' },
+ autocomplete_template: function(obj) {
+ const thumbnail = obj.thumbnail_image_url ? `<div class="document-thumbnail"><img class="img-thumbnail" src="${obj.thumbnail_image_url}" /></div>` : '';
+ return `<div class="autocomplete-item${!obj.published ? ' blacklight-private' : ''}">${thumbnail}
+ <span class="autocomplete-title">${obj.full_title}</span><br/><small> ${obj.description}</small></div>`
+ },
+
bloodhoundOptions: function() {
return {
prefetch: {
url: this.autocomplete_url(),
ttl: 0
@@ -6139,11 +6141,15 @@
},
autocomplete_control: function() {
return `<input type="text" class="st-input-string form-control item-input-field" data-twitter-typeahead="true" placeholder="${i18n.t("blocks:browse_group_categories:autocomplete")}"/>`
},
- autocomplete_template: function() { return '<div class="autocomplete-item{{#unless published}} blacklight-private{{/unless}}"><span class="autocomplete-title">{{title}}</span><br/></div>' },
+ autocomplete_template: function(obj) {
+ return `<div class="autocomplete-item${!obj.published ? ' blacklight-private' : ''}">
+ <span class="autocomplete-title">${obj.title}</span><br/></div>`
+ },
+
autocomplete_url: function() { return $(this.inner).closest('form[data-autocomplete-exhibit-browse-groups-path]').data('autocomplete-exhibit-browse-groups-path').replace("%25QUERY", "%QUERY"); },
_itemPanel: function(data) {
var index = "item_" + this.globalIndex++;
var checked;
if (data.display == "true") {
@@ -6295,11 +6301,15 @@
type: "featured_pages",
icon_name: "pages",
autocomplete_url: function() { return $(this.inner).closest('form[data-autocomplete-exhibit-pages-path]').data('autocomplete-exhibit-pages-path').replace("%25QUERY", "%QUERY"); },
- autocomplete_template: function() { return '<div class="autocomplete-item{{#unless published}} blacklight-private{{/unless}}">{{#if thumbnail_image_url}}<div class="document-thumbnail"><img class="img-thumbnail" src="{{thumbnail_image_url}}" /></div>{{/if}}<span class="autocomplete-title">{{title}}</span><br/><small> {{description}}</small></div>' },
+ autocomplete_template: function(obj) {
+ const thumbnail = obj.thumbnail_image_url ? `<div class="document-thumbnail"><img class="img-thumbnail" src="${obj.thumbnail_image_url}" /></div>` : '';
+ return `<div class="autocomplete-item${!obj.published ? ' blacklight-private' : ''}">${thumbnail}
+ <span class="autocomplete-title">${obj.title}</span><br/><small> ${obj.description}</small></div>`
+ },
bloodhoundOptions: function() {
return {
prefetch: {
url: this.autocomplete_url(),
ttl: 0
@@ -6380,12 +6390,15 @@
SirTrevor.Blocks.SolrDocumentsBase = (function(){
return Spotlight$1.Block.Resources.extend({
plustextable: true,
autocomplete_url: function() { return this.$instance().closest('form[data-autocomplete-exhibit-catalog-path]').data('autocomplete-exhibit-catalog-path').replace("%25QUERY", "%QUERY"); },
- autocomplete_template: function() { return '<div class="autocomplete-item{{#if private}} blacklight-private{{/if}}">{{#if thumbnail}}<div class="document-thumbnail"><img class="img-thumbnail" src="{{thumbnail}}" /></div>{{/if}}<span class="autocomplete-title">{{title}}</span><br/><small> {{description}}</small></div>' },
-
+ autocomplete_template: function(obj) {
+ const thumbnail = obj.thumbnail ? `<div class="document-thumbnail"><img class="img-thumbnail" src="${obj.thumbnail}" /></div>` : '';
+ return `<div class="autocomplete-item${obj.private ? ' blacklight-private' : ''}">${thumbnail}
+ <span class="autocomplete-title">${obj.title}</span><br/><small> ${obj.description}</small></div>`
+ },
transform_autocomplete_results: function(response) {
return $.map(response['docs'], function(doc) {
return doc;
})
},
@@ -7104,10 +7117,10 @@
undefined: "Standard widgets",
items: "Exhibit item widgets"
}
});
- // import '../../../../vendor/assets/javascripts/sir-trevor'
+ // These scripts are in the vendor directory
class AdminIndex {
connect() {
new AddAnother().connect();