jspanel/dist/extensions/datepicker/jspanel.datepicker.js
// method to fill a month with data
method to fill a month with data
method to fill a month with data
function fillMonth(datepicker) {
      var startdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : moment();
      moment.locale(datepicker.options.locale); 
      var now = moment(startdate) || moment(datepicker.options.startdate);
      now.locale(datepicker.options.locale);
      var month = now.month(),
      firstDay = now.date(1).weekday(),
      localeData = now.localeData(); 
      var monthBox = datepicker.querySelector('.jsPanel-cal-month');
      monthBox.innerHTML = now.format('MMMM YYYY');
      monthBox.dataset.date = now.format('YYYY-MM-DD'); 
      var dayNames = datepicker.querySelectorAll('.jsPanel-cal-sub.day-name'),
          weekdays = localeData.weekdaysMin();
      if (localeData.firstDayOfWeek() === 1) {
        for (var i = 0, j = 1; i < 7; i++, j++) {
          dayNames[i].textContent = weekdays[j];
        }
        dayNames[6].textContent = weekdays[0];
        dayNames[5].classList.add('weekend');
        dayNames[6].classList.add('weekend');
      } else {
        for (var _i2 = 0; _i2 < 7; _i2++) {
          dayNames[_i2].textContent = weekdays[_i2];
        }
        dayNames[0].classList.add('weekend');
        dayNames[6].classList.add('weekend');
      } 
      var firstEntry = now.subtract(++firstDay, 'days');
      var days = datepicker.querySelectorAll('.jsPanel-cal-sub.day');
      var _iterator = _createForOfIteratorHelper(days),
          _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var day = _step.value;
          day.classList.remove('today', 'notInMonth', 'selected', 'range', 'remove-border-radius-right', 'remove-border-radius-left');
          var value = firstEntry.add(1, 'days');
          day.textContent = value.format('D');
          day.dataset.date = now.format('YYYY-MM-DD');
          if (value.month() !== month) {
            day.classList.add('notInMonth');
          } else if (day.dataset.date === moment().format('YYYY-MM-DD')) {
            day.classList.add('today');
          }
        } 
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
      if (datepicker.options.showWeekNumbers) {
        datepicker.querySelectorAll('.jsPanel-cal-sub.week').forEach(function (week, index) {
          week.textContent = moment(datepicker.querySelector(".jsPanel-cal-sub.day-".concat((index + 1) * 7)).dataset.date).week();
        });
      }
    }
function fillMonth ( datepicker ) { var startdate = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : moment ( ) ; moment . locale ( datepicker . options . locale ) ; var now = moment ( startdate ) || moment ( datepicker . options . startdate ) ; now . locale ( datepicker . options . locale ) ; var month = now . month ( ) , firstDay = now . date ( 1 ) . weekday ( ) , localeData = now . localeData ( ) ; var monthBox = datepicker . querySelector ( '.jsPanel-cal-month' ) ; monthBox . innerHTML = now . format ( 'MMMM YYYY' ) ; monthBox . dataset . date = now . format ( 'YYYY-MM-DD' ) ; var dayNames = datepicker . querySelectorAll ( '.jsPanel-cal-sub.day-name' ) , weekdays = localeData . weekdaysMin ( ) ; if ( localeData . firstDayOfWeek ( ) === 1 ) { for ( var i = 0 , j = 1 ; i < 7 ; i ++ , j ++ ) { dayNames [ i ] . textContent = weekdays [ j ] ; } dayNames [ 6 ] . textContent = weekdays [ 0 ] ; dayNames [ 5 ] . classList . add ( 'weekend' ) ; dayNames [ 6 ] . classList . add ( 'weekend' ) ; } else { for ( var _i2 = 0 ; _i2 < 7 ; _i2 ++ ) { dayNames [ _i2 ] . textContent = weekdays [ _i2 ] ; } dayNames [ 0 ] . classList . add ( 'weekend' ) ; dayNames [ 6 ] . classList . add ( 'weekend' ) ; } var firstEntry = now . subtract ( ++ firstDay , 'days' ) ; var days = datepicker . querySelectorAll ( '.jsPanel-cal-sub.day' ) ; var _iterator = _createForOfIteratorHelper ( days ) , _step ; try { for ( _iterator . s ( ) ; ! ( _step = _iterator . n ( ) ) . done ; ) { var day = _step . value ; day . classList . remove ( 'today' , 'notInMonth' , 'selected' , 'range' , 'remove-border-radius-right' , 'remove-border-radius-left' ) ; var value = firstEntry . add ( 1 , 'days' ) ; day . textContent = value . format ( 'D' ) ; day . dataset . date = now . format ( 'YYYY-MM-DD' ) ; if ( value . month ( ) !== month ) { day . classList . add ( 'notInMonth' ) ; } else if ( day . dataset . date === moment ( ) . format ( 'YYYY-MM-DD' ) ) { day . classList . add ( 'today' ) ; } } } catch ( err ) { _iterator . e ( err ) ; } finally { _iterator . f ( ) ; } if ( datepicker . options . showWeekNumbers ) { datepicker . querySelectorAll ( '.jsPanel-cal-sub.week' ) . forEach ( function ( week , index ) { week . textContent = moment ( datepicker . querySelector ( ".jsPanel-cal-sub.day-" . concat ( ( index + 1 ) * 7 ) ) . dataset . date ) . week ( ) ; } ) ; } }
method to fill a month with data
method to fill a month with data
// set locale globally // returns number 0 to 11 where 0 is January // returns locale aware number 0 to 6 where 0 is either Sunday or Monday // fill selected month incl. year // fill day names (Mo, Tu, etc.) considering used locale // week starts with Monday // fill dates // fill week numbers