]> git.p6c8.net - jirafeau_mojo42.git/blobdiff - lib/functions.js.php
tiny style fix of the upload_image_email
[jirafeau_mojo42.git] / lib / functions.js.php
index 1a561862e9a6852c112889f00968b476218b3e7f..7ac8c7696b754d6c49b45eb1835de798df1576f7 100644 (file)
@@ -72,6 +72,16 @@ Date.prototype.format = function(format) {
     });
 };
 
     });
 };
 
+function dateFromUtcString(datestring) {
+    // matches »YYYY-MM-DD hh:mm«
+    var m = datestring.match(/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)/);
+    return new Date(Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], 0));
+}
+
+function dateFromUtcTimestamp(datetimestamp) {
+    return new Date(parseInt(datetimestamp) * 1000)
+}
+
 function dateToUtcString(datelocal) {
     return new Date(
         datelocal.getUTCFullYear(),
 function dateToUtcString(datelocal) {
     return new Date(
         datelocal.getUTCFullYear(),
@@ -83,6 +93,26 @@ function dateToUtcString(datelocal) {
     ).format();
 }
 
     ).format();
 }
 
+function dateToUtcTimestamp(datelocal) {
+    return (Date.UTC(
+        datelocal.getUTCFullYear(),
+        datelocal.getUTCMonth(),
+        datelocal.getUTCDate(),
+        datelocal.getUTCHours(),
+        datelocal.getUTCMinutes(),
+        datelocal.getUTCSeconds()
+    ) / 1000);
+}
+
+function convertAllDatetimeFields() {
+    datefields = document.getElementsByClassName('datetime')
+    for(var i=0; i<datefields.length; i++) {
+        dateUTC = datefields[i].getAttribute('data-datetime');
+        datefields[i].setAttribute('title', dateUTC + ' (GMT)');
+        datefields[i].innerHTML = dateFromUtcString(dateUTC).format('YYYY-MM-DD hh:mm (GMT O)');
+    }
+}
+
 function show_link (url, reference, delete_code, crypt_key, date)
 {
     // Upload finished
 function show_link (url, reference, delete_code, crypt_key, date)
 {
     // Upload finished
@@ -111,7 +141,7 @@ function show_link (url, reference, delete_code, crypt_key, date)
     b += encodeURIComponent(download_link_href) + "%0D";
     if (false == isEmpty(date))
     {
     b += encodeURIComponent(download_link_href) + "%0D";
     if (false == isEmpty(date))
     {
-        b += "%0D" + encodeURIComponent("This file will be available until " + dateToUtcString(date)) + "%0D";
+        b += "%0D" + encodeURIComponent("This file will be available until " + date.format('YYYY-MM-DD hh:mm (GMT O)')) + "%0D";
         document.getElementById('upload_link_email').href = "mailto:?body=" + b + "&subject=" + encodeURIComponent(filename);
     }
 
         document.getElementById('upload_link_email').href = "mailto:?body=" + b + "&subject=" + encodeURIComponent(filename);
     }
 
@@ -124,13 +154,14 @@ function show_link (url, reference, delete_code, crypt_key, date)
     // Validity date
     if (isEmpty(date))
     {
     // Validity date
     if (isEmpty(date))
     {
-        document.getElementById('validity').style.display = 'none';
+        document.getElementById('date').style.display = 'none';
     }
     else {
     }
     else {
-        document.getElementById('date').innerHTML = '<span class="datetime">'
-            + dateToUtcString(date) + ' (GMT)'
+        document.getElementById('date').innerHTML = '<span class="datetime" title="'
+            + dateToUtcString(date) + ' (GMT)">'
+            + date.format('YYYY-MM-DD hh:mm (GMT O)')
             + '</span>';
             + '</span>';
-        document.getElementById('validity').style.display = '';
+        document.getElementById('date').style.display = '';
     }
 
     // Preview link (if allowed)
     }
 
     // Preview link (if allowed)
@@ -230,12 +261,13 @@ function control_selected_file_size(max_size, error_str)
     }
     else
     {
     }
     else
     {
-        document.getElementById('options').style.display = '';
-        document.getElementById('send').style.display = '';
+        // add class to restyle upload form in next step
+        document.getElementById('upload').setAttribute('class', 'file-selected');
+        // display options
+        document.getElementById('options').style.display = 'block';
+        document.getElementById('send').style.display = 'block';
         document.getElementById('error_pop').style.display = 'none';
         document.getElementById('error_pop').style.display = 'none';
-        document.getElementById('file_select').style.left = 'inherit';
-        document.getElementById('file_select').style.height = 'inherit';
-        document.getElementById('file_select').style.opacity = '1';
+        document.getElementById('send').focus();
     }
 }
 
     }
 }
 
@@ -686,3 +718,9 @@ function upload_speed_refresh_limiter(speed_str)
     }
     return upload_speed_refresh_limiter_last_value;
 }
     }
     return upload_speed_refresh_limiter_last_value;
 }
+
+// document.ready()
+document.addEventListener('DOMContentLoaded', function(event) {
+    // Search for all datetime fields and convert the time to local timezone
+    convertAllDatetimeFields();
+});

patrick-canterino.de