Sha256: ac2f26bbc08fd151cffecaeecd8f082750f9b8e37bb29d9d75f9633971f4fc98

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

//= require thredded/components/user_textcomplete

const ThreddedMentionAutocompletion = {
  MATCH_RE: /(^@|\s@)"?([\w.,\- ()]+)$/,
  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

8 entries across 8 versions & 1 rubygems

Version Path
thredded-0.13.7 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.6 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.5 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.4 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.3 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.2 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.1 app/assets/javascripts/thredded/components/mention_autocompletion.es6
thredded-0.13.0 app/assets/javascripts/thredded/components/mention_autocompletion.es6