Sha256: f65f91f30be74d0212daadb3270e019b626f8913527bc029c4ab2c139940f7d4

Contents?: true

Size: 1.33 KB

Versions: 31

Compression:

Stored size: 1.33 KB

Contents

//= require thredded/components/user_textcomplete

const ThreddedMentionAutocompletion = {
  MATCH_RE: /(^@|\s@)"?([\w., \-()]+[\w.,\-()])$/,
  // the last letter has to not be a space so it doesn't match after replacement
  DROPDOWN_MAX_COUNT: 6,

  init(form, textarea) {
    const editor = new Textcomplete.editors.Textarea(textarea);
    const textcomplete = new Textcomplete(editor, {
      dropdown: {
        className: Thredded.UserTextcomplete.DROPDOWN_CLASS_NAME,
        maxCount: ThreddedMentionAutocompletion.DROPDOWN_MAX_COUNT
      },
    });
    textcomplete.on('rendered', function() {
      if (textcomplete.dropdown.items.length) {
        textcomplete.dropdown.items[0].activate();
      }
    });
    textcomplete.register([{
      match: ThreddedMentionAutocompletion.MATCH_RE,
      search: Thredded.UserTextcomplete.searchFn({
        url: form.getAttribute('data-autocomplete-url'),
        autocompleteMinLength: parseInt(form.getAttribute('data-autocomplete-min-length'), 10)
      }),
      template: Thredded.UserTextcomplete.formatUser,
      replace  ({name, match}) {
        let prefix = match[1];
        if (/[., ()]/.test(name)) {
          return `${prefix}"${name}" `
        } else {
          return `${prefix}${name} `
        }
      }
    }]);
  }
};

window.ThreddedMentionAutocompletion = ThreddedMentionAutocompletion;

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
thredded-1.1.0 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-1.0.1 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-1.0.0 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.16 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.15 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.14 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.13 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.12 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.11 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.10 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.9 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.8 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.7 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.6 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.5 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.4 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.3 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.1 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.16.0 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.15.5 app/assets/javascripts/thredded/components/mention_autocompletion.es6