123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- /**
- * DO NOT EDIT THIS FILE.
- * See the following change record for more information,
- * https://www.drupal.org/node/2815083
- * @preserve
- **/
- (function ($, Drupal) {
- var autocomplete = void 0;
- function autocompleteSplitValues(value) {
- var result = [];
- var quote = false;
- var current = '';
- var valueLength = value.length;
- var character = void 0;
- for (var i = 0; i < valueLength; i++) {
- character = value.charAt(i);
- if (character === '"') {
- current += character;
- quote = !quote;
- } else if (character === ',' && !quote) {
- result.push(current.trim());
- current = '';
- } else {
- current += character;
- }
- }
- if (value.length > 0) {
- result.push($.trim(current));
- }
- return result;
- }
- function extractLastTerm(terms) {
- return autocomplete.splitValues(terms).pop();
- }
- function searchHandler(event) {
- var options = autocomplete.options;
- if (options.isComposing) {
- return false;
- }
- var term = autocomplete.extractLastTerm(event.target.value);
- if (term.length > 0 && options.firstCharacterBlacklist.indexOf(term[0]) !== -1) {
- return false;
- }
- return term.length >= options.minLength;
- }
- function sourceData(request, response) {
- var elementId = this.element.attr('id');
- if (!(elementId in autocomplete.cache)) {
- autocomplete.cache[elementId] = {};
- }
- function showSuggestions(suggestions) {
- var tagged = autocomplete.splitValues(request.term);
- var il = tagged.length;
- for (var i = 0; i < il; i++) {
- var index = suggestions.indexOf(tagged[i]);
- if (index >= 0) {
- suggestions.splice(index, 1);
- }
- }
- response(suggestions);
- }
- function sourceCallbackHandler(data) {
- autocomplete.cache[elementId][term] = data;
- showSuggestions(data);
- }
- var term = autocomplete.extractLastTerm(request.term);
- if (autocomplete.cache[elementId].hasOwnProperty(term)) {
- showSuggestions(autocomplete.cache[elementId][term]);
- } else {
- var options = $.extend({ success: sourceCallbackHandler, data: { q: term } }, autocomplete.ajax);
- $.ajax(this.element.attr('data-autocomplete-path'), options);
- }
- }
- function focusHandler() {
- return false;
- }
- function selectHandler(event, ui) {
- var terms = autocomplete.splitValues(event.target.value);
- terms.pop();
- terms.push(ui.item.value);
- event.target.value = terms.join(', ');
- return false;
- }
- function renderItem(ul, item) {
- return $('<li>').append($('<a>').html(item.label)).appendTo(ul);
- }
- Drupal.behaviors.autocomplete = {
- attach: function attach(context) {
- var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
- if ($autocomplete.length) {
- var blacklist = $autocomplete.attr('data-autocomplete-first-character-blacklist');
- $.extend(autocomplete.options, {
- firstCharacterBlacklist: blacklist || ''
- });
- $autocomplete.autocomplete(autocomplete.options).each(function () {
- $(this).data('ui-autocomplete')._renderItem = autocomplete.options.renderItem;
- });
- $autocomplete.on('compositionstart.autocomplete', function () {
- autocomplete.options.isComposing = true;
- });
- $autocomplete.on('compositionend.autocomplete', function () {
- autocomplete.options.isComposing = false;
- });
- }
- },
- detach: function detach(context, settings, trigger) {
- if (trigger === 'unload') {
- $(context).find('input.form-autocomplete').removeOnce('autocomplete').autocomplete('destroy');
- }
- }
- };
- autocomplete = {
- cache: {},
- splitValues: autocompleteSplitValues,
- extractLastTerm: extractLastTerm,
- options: {
- source: sourceData,
- focus: focusHandler,
- search: searchHandler,
- select: selectHandler,
- renderItem: renderItem,
- minLength: 1,
- firstCharacterBlacklist: '',
- isComposing: false
- },
- ajax: {
- dataType: 'json'
- }
- };
- Drupal.autocomplete = autocomplete;
- })(jQuery, Drupal);
|