123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- ///// !!! GLOBAL FUNCTIONS !!! /////
-
-
-
- // CHECKS THAT STRINGS ARE JSON
- function isJSON(item) {
-
- // item = (typeof item !== "string")
- // ? JSON.stringify(item)
- // : item;
-
- try {
- item = JSON.parse(item);
- } catch (e) {
- return false;
- }
-
- return (typeof item === "object" && item !== null);
-
- }
-
-
-
- // MODAL SWITCHING FUNCTION (home.php & viewExperience.php)
- function nextModal(name) {
- // $('[data-toggle="tooltip"]').tooltip('hide');
- setTimeout(() => $(name).modal('show'), 100);
- }
-
-
-
- // Disable 'enter' key from submitting forms
- // $('form').keypress(function(event){ if (event.which == '13') { event.preventDefault(); } } );
- // $('[form]:not(button[form])').keypress(function(event){ if (event.which == '13') { event.preventDefault(); } } );
-
-
-
- // NUMBER INPUT SANITIZATION (home.php & viewExperience.php)
- $('input[type="number"]').on('change keyup', () => {
-
- // Remove invalid characters
- var sanitized = $(this).val().replace(/[^0-9]/g, '');
-
- // Update value
- $(this).val(sanitized);
-
- });
-
-
-
- // DATE INPUT DATEPICKER (home.php & viewExperience.php)
- // Taken from: http://www.javascriptkit.com/javatutors/createelementcheck2.shtml
- // If browser doesn't support input type="date", load files for jQuery UI Date Picker
- let testDateField = document.createElement("input");
-
- testDateField.setAttribute("type", "date");
-
- if(testDateField.type != "date") {
-
- // console.log('Browser does not support input of type date, loading jQuery UI...');
-
- // First load the CSS ("base" theme) for the calendar
- document.write('<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">\n');
- // let objectContainer = document.createElement('div');
- // objectContainer.innerHTML = '<link href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet">';
- // document.body.appendChild(objectContainer);
- //<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">
-
- // Then load the calendar functionality
- document.write('<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>\n');
- // objectContainer = document.createElement('div');
- // objectContainer.innerHTML = '<script src="//code.jquery.com/jquery-1.12.4.js"></script><script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>';
- // document.body.appendChild(objectContainer);
- //<script src="https://code.jquery.com/jquery-1.12.4.js"></script><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
-
- // Initialize date picker widget (on document.ready)
- // Help: https://jqueryui.com/datepicker/#min-max
- window.onload = () => {
- if($('input[type="date"]').length !== 0) {
- // jQuery(($) => $('input[type="date"]').datepicker({ minDate: 0, maxDate: "+1Y"}));
- // console.log('Done!');
- }
- }
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- // !!! FROM HERE ON DOWN, THERE'S ONLY OLD CODE !!! //
-
-
-
- // Declaration and initialization of the "naming counter"
- var selectionCounter = 2;
-
- // WHEN WANTING TO ADD MULTIPLE QUESTIONNAIRES TO AN EXPERIENCE (newExperience.php and editExperience.php)
- function AddQuestionnaire() {
-
- // We add two linebreaks so that there is space between each dropdown list
- var br = document.createElement('br');
- document.getElementById('addQuestionnaires').appendChild(br);
- br = document.createElement('br');
- document.getElementById('addQuestionnaires').appendChild(br);
-
- // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time
- var select = document.getElementById('questionnaire');
- var clone = select.cloneNode(true);
-
- // The clones will have the same name as the original but with a number that will distinguish them
- var name = select.getAttribute('name') + selectionCounter++;
- clone.id = name;
- clone.setAttribute('name', name);
- document.getElementById('addQuestionnaires').appendChild(clone);
- //document.getElementById("demo").innerHTML = selectionCounter;
- }
-
- // Reinitialization of the "naming counter"
- selectionCounter = 2;
-
- // WHEN WANTING TO ADD MULTIPLE QUESTIONS TO A QUESTIONNAIRE (newQuestionnaire.php and editQuestionnaire.php)
- function AddQuestion() {
-
- // We add a linebreak so that there is space between each dropdown list
- var br = document.createElement("br");
- document.getElementById("addQuestions").appendChild(br)
- var br2 = document.createElement("br");
- document.getElementById("addQuestions").appendChild(br2)
-
- // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time.
- var select = document.getElementById("question");
- var clone = select.cloneNode(true);
-
- // The clones will have the same name as the original but with a number that will distinguish them
- var name = select.getAttribute("name") + selectionCounter++;
- clone.id = name;
- clone.setAttribute("name", name)
- document.getElementById("addQuestions").appendChild(clone)
- //document.getElementById("demo").innerHTML = selectionCounter;
- }
|