Skip to content

Commit

Permalink
Hide datetime time field element by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Feb 4, 2023
1 parent ac72de7 commit c3f4412
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/core/ui/theme/css/datetime.css
@@ -0,0 +1,3 @@
a.toggle-time {
font-size: small;
}
9 changes: 9 additions & 0 deletions modules/core/ui/theme/farm_ui_theme.libraries.yml
Expand Up @@ -2,6 +2,15 @@ asset_map_popup:
css:
theme:
css/asset_map_popup.css: { }
datetime:
css:
theme:
css/datetime.css: { }
js:
js/datetime.js: { }
dependencies:
- core/drupal
- core/once
flag:
css:
theme:
Expand Down
3 changes: 3 additions & 0 deletions modules/core/ui/theme/farm_ui_theme.module
Expand Up @@ -25,6 +25,9 @@ function farm_ui_theme_theme($existing, $type, $theme, $path) {
* Implements hook_element_info_alter().
*/
function farm_ui_theme_element_info_alter(array &$info) {
if (isset($info['datetime'])) {
$info['datetime']['#attached']['library'][] = 'farm_ui_theme/datetime';
}
if (isset($info['farm_map'])) {
$info['farm_map']['#attached']['library'][] = 'farm_ui_theme/map';
}
Expand Down
23 changes: 23 additions & 0 deletions modules/core/ui/theme/js/datetime.js
@@ -0,0 +1,23 @@
(function (Drupal, once) {
Drupal.behaviors.farm_ui_datetime = {
attach: function (context, settings) {
var wrappers = once('toggle-time', '.form-datetime-wrapper', context);
wrappers.forEach(this.hideTime);
},
hideTime: function (wrapper) {
var link = document.createElement('a');
link.href = 'javascript: void(0)';
link.innerHTML = 'Show time';
link.classList.add('toggle-time');
link.addEventListener('click', Drupal.behaviors.farm_ui_datetime.showTime);
wrapper.querySelector('.form-type--date').appendChild(link);
wrapper.querySelector('input.form-time').style.display = 'none';
},
showTime: function (event) {
var wrapper = event.target.closest('.form-datetime-wrapper');
wrapper.querySelector('input.form-time').style.display = 'block';
var link = wrapper.querySelector('a.toggle-time');
link.parentNode.removeChild(link);
},
};
}(Drupal, once));

0 comments on commit c3f4412

Please sign in to comment.