Fixed tooltip for relative timestamps
authorAlexander Ebert <ebert@woltlab.com>
Sun, 7 Feb 2016 21:17:55 +0000 (22:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 7 Feb 2016 21:17:55 +0000 (22:17 +0100)
wcfsetup/install/files/js/WoltLab/WCF/Date/Time/Relative.js

index 58a4b0a507fb00eac0cb2162d19a84c4b4824133..eb64c2b952c738960760895d8b6d2bb4573c691a 100644 (file)
@@ -15,7 +15,7 @@ define(['Dom/ChangeListener', 'Language', 'WoltLab/WCF/Date/Util', 'WoltLab/WCF/
        /**
         * @exports     WoltLab/WCF/Date/Time/Relative
         */
-       var DateTimeRelative = {
+       return {
                /**
                 * Transforms <time> elements on init and binds event listeners.
                 */
@@ -37,13 +37,15 @@ define(['Dom/ChangeListener', 'Language', 'WoltLab/WCF/Date/Util', 'WoltLab/WCF/
                                
                                if (!element.classList.contains('datetime') || elData(element, 'is-future-date')) continue;
                                
-                               if (!element.getAttribute('title')) elAttr(element, 'title', element.textContent.trim());
-                               
                                var elTimestamp = ~~element.getAttribute('data-timestamp') + _offset;
                                var elDate = elData(element, 'date');
                                var elTime = elData(element, 'time');
                                var elOffset = elData(element, 'offset');
                                
+                               if (!element.getAttribute('title')) {
+                                       elAttr(element, 'title', Language.get('wcf.date.dateTimeFormat').replace(/%date%/, elDate).replace(/%time%/, elTime));
+                               }
+                               
                                // timestamp is less than 60 seconds ago
                                if (elTimestamp >= timestamp || timestamp < (elTimestamp + 60)) {
                                        element.textContent = Language.get('wcf.date.relative.now');
@@ -72,11 +74,9 @@ define(['Dom/ChangeListener', 'Language', 'WoltLab/WCF/Date/Util', 'WoltLab/WCF/
                                }
                                // timestamp is between ~700 million years BC and last week
                                else {
-                                       element.textContent = Language.get('wcf.date.shortDateTimeFormat').replace(/\%date\%/, elDate).replace(/\%time\%/, elTime);
+                                       element.textContent = Language.get('wcf.date.shortDateTimeFormat').replace(/%date%/, elDate).replace(/%time%/, elTime);
                                }
                        }
                }
        };
-       
-       return DateTimeRelative;
 });