diff --git a/core/core.libraries.yml b/core/core.libraries.yml index e21acf2..e34766c 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -146,6 +146,7 @@ drupal.date: - core/drupal - core/modernizr - core/jquery.once + - core/jquery.timepicker - core/jquery.ui.datepicker drupal.debounce: @@ -406,6 +407,21 @@ jquery.once: dependencies: - core/jquery +jquery.timepicker: + remote: https://github.com/jonthornton/jquery-timepicker + version: "1.11.1" + license: + name: MIT + url: https://raw.githubusercontent.com/jonthornton/jquery-timepicker/master/README.md + gpl-compatible: true + js: + assets/vendor/jquery-timepicker/jquery.timepicker.min.js: { minified: true } + css: + component: + assets/vendor/jquery-timepicker/jquery.timepicker.css: {} + dependencies: + - core/jquery + jquery.ui: remote: https://github.com/jquery/jquery-ui version: &jquery_ui_version 1.11.4 diff --git a/core/misc/date.js b/core/misc/date.js index 8b6b71c..2e54136 100644 --- a/core/misc/date.js +++ b/core/misc/date.js @@ -53,4 +53,29 @@ } }; + /** + * Attach datepicker fallback on time elements. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches the behavior to time elements. + */ + Drupal.behaviors.time = { + attach: function (context, settings) { + var $context = $(context); + // Skip if time inputs are supported by the browser. + if (Modernizr.inputtypes.time === true) { + return; + } + $context.find('input[type="time"]').once('timePicker').each(function () { + var $input = $(this); + var options = { + 'timeFormat': 'H:i:s' + }; + $input.timepicker(options); + }); + } + } + })(jQuery, Modernizr, Drupal);