1/** 2 * @file 3 * JavaScript behaviors for time integration. 4 */ 5 6(function ($, Drupal, once) { 7 // @see https://github.com/jonthornton/jquery-timepicker#options 8 Drupal.webform = Drupal.webform || {}; 9 Drupal.webform.timePicker = Drupal.webform.timePicker || {}; 10 Drupal.webform.timePicker.options = Drupal.webform.timePicker.options || {}; 11 12 /** 13 * Attach timepicker fallback on time elements. 14 * 15 * @type {Drupal~behavior} 16 * 17 * @prop {Drupal~behaviorAttach} attach 18 * Attaches the behavior to time elements. 19 */ 20 Drupal.behaviors.webformTime = { 21 attach: function (context, settings) { 22 if (!$.fn.timepicker) { 23 return; 24 } 25 26 $(once('webformTimePicker', 'input[type="text"][data-webform-time-format]', context)).each(function () { 27 var $input = $(this); 28 var options = {}; 29 options.timeFormat = $input.data('webformTimeFormat'); 30 if ($input.attr('min')) { 31 options.minTime = $input.attr('min'); 32 } 33 if ($input.attr('max')) { 34 options.maxTime = $input.attr('max'); 35 } 36 37 // HTML5 time element steps is in seconds but for the timepicker 38 // fallback it needs to be in minutes. 39 // Note: The 'datetime' element uses the #date_increment which defaults 40 // to 1 (second). 41 // @see \Drupal\Core\Datetime\Element\Datetime::processDatetime 42 // Only use step if it is greater than 60 seconds. 43 if ($input.attr('step') && ($input.attr('step') > 60)) { 44 options.step = Math.round($input.attr('step') / 60); 45 } 46 else { 47 options.step = 1; 48 } 49 50 // Set step to 'any' to prevent clientside validation issues. 51 // @see \Drupal\clientside_validation\Plugin\CvValidator\Step 52 // @see https://www.drupal.org/project/clientside_validation/issues/2941434 53 $input.attr('step', 'any'); 54 55 options = $.extend(options, Drupal.webform.timePicker.options); 56 57 // Allow custom options. 58 if ($input.attr('data-options')) { 59 options = $.extend(true, options, JSON.parse($input.attr('data-options'))); 60 } 61 62 $input.timepicker(options); 63 }); 64 } 65 }; 66 67})(jQuery, Drupal, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.