-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from City-of-Helsinki/UHF-10341
UHF-10341 job page cache problem
- Loading branch information
Showing
6 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
public/themes/custom/hdbt_subtheme/dist/js/helfi_datetime_comparison.min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
public/themes/custom/hdbt_subtheme/src/js/helfi_datetime_comparison.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Turn datetime into text (for example "today"), used on a job page. | ||
((Drupal) => { | ||
// Look for all time-elements from all metadata-wrappers. | ||
const timeElements = Array.from(document.getElementsByClassName('job-listing__metadata-wrapper')) | ||
?.map(wrapper => wrapper.getElementsByTagName('time')) | ||
?.map(timeElementCollection => Array.from(timeElementCollection)) | ||
?.flat() | ||
if (!timeElements) return; | ||
|
||
const today = new Date(); | ||
Array.from(timeElements).forEach((element) => { | ||
const originalDate = new Date(element.getAttribute('datetime')); | ||
if (originalDate.toDateString() === today.toDateString()) { | ||
const minutes = originalDate.getUTCMinutes() < 10 ? `0${originalDate.getMinutes()}` : originalDate.getMinutes(); | ||
element.innerText = `${Drupal.t('today')} ${originalDate.getHours()}:${minutes}` | ||
} | ||
}); | ||
})(Drupal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters