4960176adc204581296c47486b3802d55f0a0c68
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Resources / Public / JavaScript / Modules / Preview.js
1
2 function initializePreviewModule() {
3 var dateField = document.getElementById('preview_simulateDate-date-hr');
4 var timeField = document.getElementById('preview_simulateDate-time-hr');
5 var targetField = document.getElementById(dateField.dataset.target);
6 if (targetField.value) {
7 var cd = new Date(targetField.value);
8 document.getElementById('preview_simulateDate-date-hr').value = cd.getFullYear() + "-" + ((cd.getMonth()+1) < 10 ? '0' : '') + (cd.getMonth()+1) + "-" + (cd.getDate() < 10 ? '0' : '') + cd.getDate();
9 document.getElementById('preview_simulateDate-time-hr').value = (cd.getHours() < 10 ? '0' : '') + cd.getHours() + ":" + (cd.getMinutes() < 10 ? '0' : '') + cd.getMinutes();
10 }
11
12 var updateDateField = function () {
13 var dateVal = document.getElementById('preview_simulateDate-date-hr').value;
14 var timeVal = document.getElementById('preview_simulateDate-time-hr').value;
15 if (!dateVal && timeVal) {
16 var tempDate = new Date();
17 dateVal = tempDate.getFullYear() + "-" + (tempDate.getMonth() + 1) + "-" + tempDate.getDate();
18 }
19 if (dateVal && !timeVal) {
20 timeVal = "00:00";
21 }
22
23 if(!dateVal && !timeVal) {
24 targetField.value = "";
25 } else {
26 var stringDate = dateVal + " " + timeVal;
27 var date = new Date(stringDate);
28 targetField.value = date.toISOString();
29 }
30 };
31 dateField.addEventListener('change', updateDateField);
32 timeField.addEventListener('change', updateDateField);
33 }
34
35 window.addEventListener('load', initializePreviewModule, false);