Commit 1c7542d4 authored by Marc Egger's avatar Marc Egger
Browse files

for tags it works both for only static, only api and both together, now normal typeahead

parent 75918029
Pipeline #3296 passed with stages
in 3 minutes and 39 seconds
......@@ -29,20 +29,24 @@ var QfqNS = QfqNS || {};
var $element = $(this);
//bloodhound is used to get the remote data (suggestions)
bloodhoundConfiguration = {
// We need to be notified on success, so we need a promise
initialize: false,
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('key', 'value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function (obj) {
return obj.key;
},
remote: {
url: n.TypeAhead.makeUrl(typeahead_endpoint, $element),
wildcard: '%QUERY'
}
};
//if a API Sip is given, bloodhound is used to get the remote data (suggestions)
if (n.TypeAhead.getSip($element)) {
bloodhoundConfiguration = {
// We need to be notified on success, so we need a promise
initialize: false,
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('key', 'value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function (obj) {
return obj.key;
},
remote: {
url: n.TypeAhead.makeUrl(typeahead_endpoint, $element),
wildcard: '%QUERY'
}
};
} else {
bloodhoundConfiguration = null;
}
// initialize typeahead (either with or without tags)
if ($element.data('typeahead-tags')) {
......@@ -58,10 +62,6 @@ var QfqNS = QfqNS || {};
n.TypeAhead.installWithTags = function ($element, bloodhoundConfiguration) {
// initialize bloodhound (typeahead suggestion engine)
var suggestions = new Bloodhound(bloodhoundConfiguration);
suggestions.initialize();
// create actual input field
var $inputField = $('<input/>', {
type: 'text',
......@@ -158,8 +158,15 @@ var QfqNS = QfqNS || {};
});
tagApi.tagsManager('disableHiddenUpdate', false);
// add typahead
$inputField.typeahead({
var notFound = (function ($_) {
return function (obj) {
if (!!$element.data('typeahead-pedantic'))
return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found";
};
})($inputField);
var typeaheadConfig = [
{
// options
hint: n.TypeAhead.getHint($element),
highlight: n.TypeAhead.getHighlight($element),
......@@ -174,17 +181,19 @@ var QfqNS = QfqNS || {};
// header: '<h3 class="league-name">List</h3>',
suggestion: function (obj) {
return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>";
}// ,
// // No message if field is not set to pedantic.
// notFound: (function ($_) {
// return function (obj) {
// if (!!$element.data('typeahead-pedantic'))
// return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found";
// };
// })($inputField)
},
// No message if field is not set to pedantic.
notFound: bloodhoundConfiguration === null ? notFound : undefined
}
},
{
}
];
if (bloodhoundConfiguration !== null) {
// initialize bloodhound (typeahead suggestion engine)
var suggestions = new Bloodhound(bloodhoundConfiguration);
suggestions.initialize();
typeaheadConfig.push({
name: 'restApi',
display: 'value',
source: suggestions,
......@@ -203,6 +212,10 @@ var QfqNS = QfqNS || {};
})($inputField)
}
});
}
// add typahead
$inputField.typeahead.apply($inputField, typeaheadConfig);
// directly add tag when clicked on in typahead menu
$inputField.bind('typeahead:selected', function (event, sugg) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment