You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

new-Postv2.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. document.addEventListener("DOMContentLoaded", function(){
  2. const editorButtons = document.getElementsByClassName('editor-button');
  3. const setAttribute = (element) => {
  4. document.execCommand(element.dataset.attribute, false);
  5. };
  6. for(let i = 0; i <editorButtons.length; i++) {
  7. editorButtons[i].addEventListener('click', function(){
  8. setAttribute(this);
  9. });
  10. }
  11. document.getElementById("cancelBtn").onclick = function(){
  12. window.location = "/main";
  13. }
  14. document.getElementById("add").onclick = function(){
  15. document.execCommand("insertImage", false, document.getElementById("url").value);
  16. }
  17. document.getElementById("forecolor").onchange = function(){setColor(this);}
  18. const setColor = (element) => {
  19. console.log(element);
  20. document.execCommand(element.dataset.attribute, false, element.value);
  21. };
  22. const backColor = document.getElementById("backcolor");
  23. const helo = document.getElementsByClassName("canvas");
  24. backColor.addEventListener('change', function(){
  25. console.log(this);
  26. for(let i = 0; i <helo.length; i++) {
  27. helo[i].style.backgroundColor = backColor.value;
  28. };
  29. });
  30. document.getElementById("submit-post").onclick = function(){
  31. if(document.getElementById('title-canvas').innerHTML && document.getElementById('editor-canvas').innerHTML)
  32. {
  33. const title = document.getElementById('title-canvas').innerHTML;
  34. const content = document.getElementById('editor-canvas').innerHTML;
  35. const date_begin = document.getElementById('startDate').value;
  36. const date_end = document.getElementById('endDate').value;
  37. const bcolor = document.getElementById('backcolor').value;
  38. var bodyContent = {title:title, text:content, startDate:date_begin, endDate:date_end, bcolor:bcolor};
  39. send(bodyContent);
  40. }
  41. };
  42. async function send(bodyContent){
  43. console.log(bodyContent);
  44. var response = await fetch("/newpost", {
  45. method: "POST",
  46. headers: {
  47. "Accept":"application/json",
  48. "Content-Type":"application/json"
  49. },
  50. body:JSON.stringify(bodyContent)
  51. });
  52. var data = await response.json();
  53. console.log(data);
  54. console.log(helo);
  55. window.location = "/main";
  56. }
  57. /*-----New User Popup-----*/
  58. const openPopupBtns = document.querySelectorAll("[data-popup-target]");
  59. const closePopupBtns = document.querySelectorAll("[data-close-btn]");
  60. const overlay = document.getElementById("overlay");
  61. openPopupBtns.forEach(btn => {
  62. btn.addEventListener("click", () => {
  63. const popup = document.querySelector(btn.dataset.popupTarget);
  64. openPopup(popup);
  65. })
  66. });
  67. closePopupBtns.forEach(btn => {
  68. btn.addEventListener("click", () => {
  69. const popup = btn.closest(".popup")
  70. closePopup(popup);
  71. })
  72. });
  73. function openPopup(popup) {
  74. if (popup == null) return
  75. popup.classList.add("active");
  76. overlay.classList.add("active");
  77. }
  78. function closePopup(popup) {
  79. if (popup == null) return
  80. popup.classList.remove("active");
  81. overlay.classList.remove("active");
  82. }
  83. document.getElementById("startDate").onchange = function(){
  84. document.getElementById("endDate").min = document.getElementById("startDate").value;
  85. var end = new Date(document.getElementById("startDate").value);
  86. end.setDate(end.getDate() +7);
  87. var endDate = end.toISOString().slice(0,10);
  88. document.getElementById("endDate").value = endDate;
  89. }
  90. function date(){
  91. var today = new Date().toISOString().slice(0,10);
  92. var end = new Date();
  93. end.setDate(end.getDate() + 7)
  94. var endDate = end.toISOString().slice(0,10);
  95. document.getElementById("startDate").value = today;
  96. document.getElementById("startDate").min = today;
  97. document.getElementById("endDate").value = endDate;
  98. document.getElementById("endDate").min = today;
  99. };
  100. date()
  101. });