Advertisement
Guest User

Untitled

a guest
May 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /**
  2. * Slug generator
  3. *
  4. */
  5. const name = document.getElementById('name');
  6. const slug = document.getElementById('slug');
  7. if (name && slug) {
  8.  
  9. // Init a timeout variable to be used below
  10. let timeout = null;
  11.  
  12. // Bind keyup event
  13. name.onkeyup = function (e) {
  14.  
  15. let self = this;
  16.  
  17. // Clear the timeout if it has already been set.
  18. // This will prevent the previous task from executing
  19. // if it has been less than <MILLISECONDS>
  20. clearTimeout(timeout);
  21.  
  22. // Make a new timeout set to go off in 300ms
  23. timeout = setTimeout(function (e) {
  24.  
  25. getSlug(self.value);
  26.  
  27. }, 300);
  28.  
  29. };
  30.  
  31. window.getSlug = (string) => {
  32.  
  33. // Set form data
  34. let data = new FormData();
  35. data.append('string', string);
  36.  
  37. // Make the call
  38. axios.post('/dashboard/products/createslug', data)
  39. .then(function (res) {
  40. slug.value = res.data;
  41. })
  42. }
  43.  
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement