website_form.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Client code for the website_form template.
  3. *
  4. * - events
  5. */
  6. Template.website_form.events({
  7. "click .js-toggle-website-form": function () {
  8. $("#website_form").toggle("fast");
  9. },
  10. "click #site-lookup": function (event) {
  11. event.preventDefault();
  12. const url = $(event.target).parent().prev().val();
  13. Meteor.call("loadSite", url, function (error, result) {
  14. let $result = $("<root>" + result + "</root>");
  15. let titleElement = $($result.find("title")[0]).text();
  16. let metaTitle = $result.find("meta[name=\"title\"]").attr("content");
  17. let metaDescription = $result.find("meta[name=\"description\"]").attr("content");
  18. let title = [titleElement, metaTitle].join(" / ");
  19. $("#title").val(title);
  20. $("#description").val(metaDescription);
  21. });
  22. },
  23. "submit .js-save-website-form": function (event) {
  24. event.preventDefault();
  25. // here is an example of how to get the url out of the form:
  26. const url = event.target.url.value;
  27. const title = event.target.title.value;
  28. const description = event.target.description.value;
  29. let poster = {
  30. _id: Meteor.userId(),
  31. name: Meteor.user().username
  32. };
  33. const postDate = new Date();
  34. // put your website saving code in here!
  35. const doc = { url, title, description, poster, postDate };
  36. doc.words = toWords(doc);
  37. Meteor._debug("Client trying to insert", doc);
  38. Websites.insert(doc);
  39. }
  40. });