synonyms-autocomplete.js 925 B

123456789101112131415161718192021222324
  1. (function ($) {
  2. /**
  3. * Fix the autocomplete core undesired behavior.
  4. *
  5. * The core autocomplete only allows 1 entry per suggestion, i.e. you can't have
  6. * 2 suggestion entries suggest the same key. Synonyms module very well needs
  7. * such ability, since multiple synonyms may point to the same entity. In order
  8. * to bypass this limitation Synonyms module pads the suggestion entries with
  9. * extra spaces on the right until it finds a "free" spot. This JavaScript
  10. * right-trims the entries in order to cancel out the effect.
  11. */
  12. Drupal.behaviors.synonymsAutocompleteWidget = {
  13. attach: function (context, settings) {
  14. $('input.form-autocomplete.synonyms-autocomplete', context).once('synonyms-autocomplete', function () {
  15. $(this).bind('autocompleteSelect', function() {
  16. var value = $(this).val();
  17. value = value.replace(/\s+$/, '');
  18. $(this).val(value);
  19. });
  20. });
  21. }
  22. };
  23. })(jQuery);