All files / app/assets/javascripts/behaviors date_picker.js

53.85% Statements 7/13
100% Branches 0/0
33.33% Functions 2/6
53.85% Lines 7/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34          30x 2x 2x   2x                         2x   2x     30x            
import $ from 'jquery';
import Pikaday from 'pikaday';
import { parsePikadayDate, pikadayToString } from '~/lib/utils/datetime_utility';
 
export default function initDatePickers() {
  $('.datepicker').each(function initPikaday() {
    const $datePicker = $(this);
    const datePickerVal = $datePicker.val();
 
    const calendar = new Pikaday({
      field: $datePicker.get(0),
      theme: 'gitlab-theme animate-picker',
      format: 'yyyy-mm-dd',
      container: $datePicker.parent().get(0),
      parse: (dateString) => parsePikadayDate(dateString),
      toString: (date) => pikadayToString(date),
      onSelect(dateText) {
        $datePicker.val(calendar.toString(dateText));
      },
      firstDay: gon.first_day_of_week,
    });
 
    calendar.setDate(parsePikadayDate(datePickerVal));
 
    $datePicker.data('pikaday', calendar);
  });
 
  $('.js-clear-due-date,.js-clear-start-date').on('click', (e) => {
    e.preventDefault();
    const calendar = $(e.target).siblings('.datepicker').data('pikaday');
    calendar.setDate(null);
  });
}