autoComplete.ts 1002 B

123456789101112131415161718192021222324252627282930313233343536
  1. Macro.add('autocomplete', {
  2. skipArgs : false,
  3. tags: [],
  4. handler : function () {
  5. try{
  6. const varname = this.args[0];
  7. const domID = `autoComplete_${varname.replaceAll("$","--")}`;
  8. const tags = this.args[1];
  9. const innerCode = this.payload[0].contents;
  10. $(this.output).wiki(`<<id '${domID}'>><<textbox "${varname}" "">><</id>>`);
  11. $(document).one(':passagedisplay', function (ev) {
  12. setup.externalCodePromise('jQueryUI').then(function () {
  13. $(`#${domID}`).autocomplete({
  14. source: tags,
  15. select: (event, ui) => {
  16. const v = ui.item.value;
  17. State.setVar(varname,v);
  18. $.wiki(innerCode);
  19. }
  20. });
  21. });
  22. });
  23. }
  24. catch (ex) {
  25. return this.error('ERROR in gt-widget: ' + ex.message);
  26. }
  27. }
  28. });