Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ///// !!! GLOBAL FUNCTIONS !!! /////
  2. // CHECKS THAT STRINGS ARE JSON
  3. function isJSON(item) {
  4. // item = (typeof item !== "string")
  5. // ? JSON.stringify(item)
  6. // : item;
  7. try {
  8. item = JSON.parse(item);
  9. } catch (e) {
  10. return false;
  11. }
  12. return (typeof item === "object" && item !== null);
  13. }
  14. // MODAL SWITCHING FUNCTION (home.php & viewExperience.php)
  15. function nextModal(name) {
  16. $('[data-toggle="tooltip"]').tooltip('hide');
  17. setTimeout(() => $(name).modal('show'), 100);
  18. }
  19. // Disable 'enter' key from submitting forms
  20. // $('form').keypress(function(event){ if (event.which == '13') { event.preventDefault(); } } );
  21. // $('[form]:not(button[form])').keypress(function(event){ if (event.which == '13') { event.preventDefault(); } } );
  22. // NUMBER INPUT SANITIZATION (home.php & viewExperience.php)
  23. $('input[type="number"]').on('change keyup', () => {
  24. // Remove invalid characters
  25. var sanitized = $(this).val().replace(/[^0-9]/g, '');
  26. // Update value
  27. $(this).val(sanitized);
  28. });
  29. // DATE INPUT DATEPICKER (home.php & viewExperience.php)
  30. // Taken from: http://www.javascriptkit.com/javatutors/createelementcheck2.shtml
  31. // If browser doesn't support input type="date", load files for jQuery UI Date Picker
  32. let testDateField = document.createElement("input");
  33. testDateField.setAttribute("type", "date");
  34. if(testDateField.type != "date") {
  35. // First load the CSS ("base" theme) for the calendar
  36. document.write('<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n');
  37. // Then load the calendar functionality
  38. document.write('<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>\n');
  39. // Initialize date picker widget (on document.ready)
  40. // Help: https://jqueryui.com/datepicker/#min-max
  41. window.onload = () => {
  42. if($('input[type="date"]').length !== 0) {
  43. jQuery(($) => $('input[type="date"]').datepicker({ minDate: 0, maxDate: "+1Y"}));
  44. }
  45. }
  46. }
  47. // FOOTER COPYRIGHT YEAR
  48. let date = new Date().getFullYear();
  49. document.getElementById('copyrightDate').innerHTML = date;
  50. // !!! FROM HERE ON DOWN, THERE'S ONLY OLD CODE !!! //
  51. // Declaration and initialization of the "naming counter"
  52. var selectionCounter = 2;
  53. // WHEN WANTING TO ADD MULTIPLE QUESTIONNAIRES TO AN EXPERIENCE (newExperience.php and editExperience.php)
  54. function AddQuestionnaire() {
  55. // We add two linebreaks so that there is space between each dropdown list
  56. var br = document.createElement('br');
  57. document.getElementById('addQuestionnaires').appendChild(br);
  58. br = document.createElement('br');
  59. document.getElementById('addQuestionnaires').appendChild(br);
  60. // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time
  61. var select = document.getElementById('questionnaire');
  62. var clone = select.cloneNode(true);
  63. // The clones will have the same name as the original but with a number that will distinguish them
  64. var name = select.getAttribute('name') + selectionCounter++;
  65. clone.id = name;
  66. clone.setAttribute('name', name);
  67. document.getElementById('addQuestionnaires').appendChild(clone);
  68. //document.getElementById("demo").innerHTML = selectionCounter;
  69. }
  70. // Reinitialization of the "naming counter"
  71. selectionCounter = 2;
  72. // WHEN WANTING TO ADD MULTIPLE QUESTIONS TO A QUESTIONNAIRE (newQuestionnaire.php and editQuestionnaire.php)
  73. function AddQuestion() {
  74. // We add a linebreak so that there is space between each dropdown list
  75. var br = document.createElement("br");
  76. document.getElementById("addQuestions").appendChild(br)
  77. var br2 = document.createElement("br");
  78. document.getElementById("addQuestions").appendChild(br2)
  79. // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time.
  80. var select = document.getElementById("question");
  81. var clone = select.cloneNode(true);
  82. // The clones will have the same name as the original but with a number that will distinguish them
  83. var name = select.getAttribute("name") + selectionCounter++;
  84. clone.id = name;
  85. clone.setAttribute("name", name)
  86. document.getElementById("addQuestions").appendChild(clone)
  87. //document.getElementById("demo").innerHTML = selectionCounter;
  88. }