do-post.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const xml_base_pub = document.documentElement.getAttribute("data-xml-base-pub");
  2. // Firefox 56+ doesn't fire that one in xslt situation: document.addEventListener("DOMContentLoaded", function(event) { console.log("DOM fully loaded and parsed"); });
  3. let tit;
  4. document.onreadystatechange = function () {
  5. if(tit !== undefined)
  6. return;
  7. // console.log('setup awesomeplete');
  8. tit = new Awesomplete('input[data-multiple]', {
  9. minChars: 3,
  10. maxItems: 15,
  11. filter: function(text, input) { const m = input.match(/#(\S*)$/); return m !== null && Awesomplete.FILTER_CONTAINS(text, m[1]); /* match */ },
  12. item: function(text, input) { const m = input.match(/#(\S*)$/); return m !== null && Awesomplete.ITEM(text, m[1]); /* highlight */ },
  13. replace: function(text) { const inp = this.input; inp.value = inp.value.replace(/#[^#]+$/, text) + " "; },
  14. });
  15. const txt = new Awesomplete('textarea[data-multiple]', {
  16. minChars: 3,
  17. maxItems: 15,
  18. filter: function(text, input) { const m = input.match(/#(\S*)$/); return m !== null && Awesomplete.FILTER_CONTAINS(text, m[1]); /* match */ },
  19. item: function(text, input) { const m = input.match(/#(\S*)$/); return m !== null && Awesomplete.ITEM(text, m[1]); /* highlight */ },
  20. replace: function(text) { const inp = this.input; inp.value = inp.value.replace(/#[^#]+$/, text) + " "; },
  21. });
  22. const xhr = new XMLHttpRequest()
  23. xhr.onreadystatechange = function() {
  24. if (xhr.readyState > 3 && xhr.status == 200) {
  25. txt.list = tit.list = JSON.parse(xhr.response);
  26. }
  27. };
  28. xhr.open('GET', xml_base_pub + '/t/index.json');
  29. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  30. xhr.send();
  31. };