From 2f65c4b5652291961ee0c3148a9d5a81774c3f12 Mon Sep 17 00:00:00 2001 From: Fabian Scheidt Date: Sat, 24 Mar 2018 16:07:06 +0100 Subject: [PATCH] Added option to emphasize some featured dates --- README.md | 21 ++++++++ dist/datepicker.common.js | 92 +++++++++++++++++++++++++++++--- dist/datepicker.css | 8 ++- dist/datepicker.esm.js | 92 +++++++++++++++++++++++++++++--- dist/datepicker.js | 92 +++++++++++++++++++++++++++++--- dist/datepicker.min.css | 6 +-- dist/datepicker.min.js | 6 +-- docs/css/datepicker.css | 8 ++- docs/css/main.css | 2 +- docs/index.html | 4 ++ docs/js/datepicker.js | 92 +++++++++++++++++++++++++++++--- src/css/datepicker.css | 4 ++ src/js/datepicker.js | 14 ++++- src/js/defaults.js | 3 ++ src/js/methods.js | 14 +++++ src/js/render.js | 42 +++++++++++++++ test/index.html | 2 + test/methods/setFeaturedDates.js | 8 +++ test/options/featuredDates.js | 22 ++++++++ 19 files changed, 492 insertions(+), 40 deletions(-) create mode 100644 test/methods/setFeaturedDates.js create mode 100644 test/options/featuredDates.js diff --git a/README.md b/README.md index 9fee79e..3a54472 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,13 @@ A class (CSS) for disabled item. A class (CSS) for highlight date item. +### featuredClass + +- Type: `String` +- Default: `'featured'` + +A class (CSS) for featured date item. + ### template - Type: `String` @@ -371,6 +378,13 @@ $().datepicker({ }); ``` +### featuredDates + +- Type: `Array` +- Default: `[]` + +A list of dates that will be emphasized in the calendar. + ### show - Type: `Function` @@ -518,6 +532,13 @@ Set the start view date with a new date. Set the end view date with a new date. +### setFeaturedDates(dates) + +- **dates**: + - Type: `Array` of `Date` or `String` + +Set the list of featured dates with a new list. + ### parseDate(date) - **date**: diff --git a/dist/datepicker.common.js b/dist/datepicker.common.js index da19517..0b65a5d 100644 --- a/dist/datepicker.common.js +++ b/dist/datepicker.common.js @@ -2,10 +2,10 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:23.820Z + * Date: 2018-03-24T14:57:50.457Z */ 'use strict'; @@ -92,6 +92,9 @@ var DEFAULTS = { // A class (CSS) for highlight date item highlightedClass: 'highlighted', + // A class (CSS) for featured date item + featuredClass: 'featured', + // The template of the datepicker template: '
' + '
' + '
    ' + '
  • ' + '
  • ' + '
  • ' + '
' + '
    ' + '
    ' + '
    ' + '
      ' + '
    • ' + '
    • ' + '
    • ' + '
    ' + '
      ' + '
      ' + '
      ' + '
        ' + '
      • ' + '
      • ' + '
      • ' + '
      ' + '
        ' + '
          ' + '
          ' + '
          ', @@ -469,6 +472,25 @@ var methods = { }, + /** + * Sets the list of featured dates with a new list + * + * @param dates + */ + setFeaturedDates: function setFeaturedDates(dates) { + var _this = this; + + dates = Array.isArray(dates) ? dates : [dates]; + this.featuredDates = dates.map(function (date) { + return _this.parseDate(date); + }); + + if (this.built) { + this.render(); + } + }, + + /** * Parse a date string with the set date format * @@ -777,7 +799,8 @@ var render = { renderYears: function renderYears() { var options = this.options, startDate = this.startDate, - endDate = this.endDate; + endDate = this.endDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; @@ -796,6 +819,7 @@ var render = { for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); var disabled = false; + var featured = false; if (startDate) { disabled = date.getFullYear() < startDate.getFullYear(); @@ -817,6 +841,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear + i + 1, 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; @@ -824,6 +858,7 @@ var render = { picked: picked, disabled: disabled, muted: i === start || i === end, + featured: featured, text: viewYear + i, view: disabled ? 'year disabled' : view, highlighted: date.getFullYear() === thisYear @@ -839,7 +874,8 @@ var render = { var options = this.options, startDate = this.startDate, endDate = this.endDate, - viewDate = this.viewDate; + viewDate = this.viewDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass || ''; var months = options.monthsShort; @@ -858,6 +894,7 @@ var render = { for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); var disabled = false; + var featured = false; if (startDate) { prevDisabled = date.getFullYear() === startDate.getFullYear(); @@ -873,6 +910,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, i + 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; @@ -880,6 +927,7 @@ var render = { disabled: disabled, picked: picked, highlighted: viewYear === thisYear && date.getMonth() === thisMonth, + featured: featured, index: i, text: months[i], view: disabled ? 'month disabled' : view @@ -897,7 +945,8 @@ var render = { startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate, - currentDate = this.date; + currentDate = this.date, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, monthsShort = options.monthsShort, @@ -1032,6 +1081,7 @@ var render = { for (i = 1; i <= length; i += 1) { var _date = new Date(viewYear, viewMonth, i); var _disabled2 = false; + var featured = false; if (startDate) { _disabled2 = _date.getTime() < startDate.getTime(); @@ -1045,6 +1095,16 @@ var render = { _disabled2 = filter.call($element, _date) === false; } + var featuredDateLowerLimit = _date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, viewMonth, i + 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var _picked = viewYear === year && viewMonth === month && i === day; var view = _picked ? 'day picked' : 'day'; @@ -1052,6 +1112,7 @@ var render = { disabled: _disabled2, picked: _picked, highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay, + featured: featured, text: i, view: _disabled2 ? 'day disabled' : view })); @@ -1095,17 +1156,21 @@ var Datepicker = function () { this.initialDate = null; this.startDate = null; this.endDate = null; + this.featuredDates = []; this.init(); } _createClass(Datepicker, [{ key: 'init', value: function init() { + var _this = this; + var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, - date = options.date; + date = options.date, + featuredDates = options.featuredDates; this.$trigger = $(options.trigger); @@ -1143,6 +1208,14 @@ var Datepicker = function () { this.endDate = endDate; } + if (featuredDates) { + featuredDates = Array.isArray(featuredDates) ? featuredDates : [featuredDates]; + featuredDates = featuredDates.map(function (featuredDate) { + return _this.parseDate(featuredDate); + }); + this.featuredDates = featuredDates; + } + this.date = date; this.viewDate = new Date(date); this.initialDate = new Date(this.date); @@ -1411,7 +1484,8 @@ var Datepicker = function () { muted: false, picked: false, disabled: false, - highlighted: false + highlighted: false, + featured: false }; var classes = []; @@ -1433,6 +1507,10 @@ var Datepicker = function () { classes.push(options.disabledClass); } + if (item.featured) { + classes.push(options.featuredClass); + } + return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; } }, { diff --git a/dist/datepicker.css b/dist/datepicker.css index 7cfd195..fdd4f66 100644 --- a/dist/datepicker.css +++ b/dist/datepicker.css @@ -2,10 +2,10 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:19.628Z + * Date: 2018-03-24T14:57:47.353Z */ .datepicker-container { @@ -172,6 +172,10 @@ background-color: rgb(229, 242, 255); } +.datepicker-panel > ul > li.featured { + font-weight: bold; +} + .datepicker-panel > ul > li[data-view="years prev"], .datepicker-panel > ul > li[data-view="year prev"], .datepicker-panel > ul > li[data-view="month prev"], diff --git a/dist/datepicker.esm.js b/dist/datepicker.esm.js index a2a12ec..a766222 100644 --- a/dist/datepicker.esm.js +++ b/dist/datepicker.esm.js @@ -2,10 +2,10 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:23.820Z + * Date: 2018-03-24T14:57:50.457Z */ import $ from 'jquery'; @@ -88,6 +88,9 @@ var DEFAULTS = { // A class (CSS) for highlight date item highlightedClass: 'highlighted', + // A class (CSS) for featured date item + featuredClass: 'featured', + // The template of the datepicker template: '
          ' + '
          ' + '
            ' + '
          • ' + '
          • ' + '
          • ' + '
          ' + '
            ' + '
            ' + '
            ' + '
              ' + '
            • ' + '
            • ' + '
            • ' + '
            ' + '
              ' + '
              ' + '
              ' + '
                ' + '
              • ' + '
              • ' + '
              • ' + '
              ' + '
                ' + '
                  ' + '
                  ' + '
                  ', @@ -465,6 +468,25 @@ var methods = { }, + /** + * Sets the list of featured dates with a new list + * + * @param dates + */ + setFeaturedDates: function setFeaturedDates(dates) { + var _this = this; + + dates = Array.isArray(dates) ? dates : [dates]; + this.featuredDates = dates.map(function (date) { + return _this.parseDate(date); + }); + + if (this.built) { + this.render(); + } + }, + + /** * Parse a date string with the set date format * @@ -773,7 +795,8 @@ var render = { renderYears: function renderYears() { var options = this.options, startDate = this.startDate, - endDate = this.endDate; + endDate = this.endDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; @@ -792,6 +815,7 @@ var render = { for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); var disabled = false; + var featured = false; if (startDate) { disabled = date.getFullYear() < startDate.getFullYear(); @@ -813,6 +837,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear + i + 1, 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; @@ -820,6 +854,7 @@ var render = { picked: picked, disabled: disabled, muted: i === start || i === end, + featured: featured, text: viewYear + i, view: disabled ? 'year disabled' : view, highlighted: date.getFullYear() === thisYear @@ -835,7 +870,8 @@ var render = { var options = this.options, startDate = this.startDate, endDate = this.endDate, - viewDate = this.viewDate; + viewDate = this.viewDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass || ''; var months = options.monthsShort; @@ -854,6 +890,7 @@ var render = { for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); var disabled = false; + var featured = false; if (startDate) { prevDisabled = date.getFullYear() === startDate.getFullYear(); @@ -869,6 +906,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, i + 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; @@ -876,6 +923,7 @@ var render = { disabled: disabled, picked: picked, highlighted: viewYear === thisYear && date.getMonth() === thisMonth, + featured: featured, index: i, text: months[i], view: disabled ? 'month disabled' : view @@ -893,7 +941,8 @@ var render = { startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate, - currentDate = this.date; + currentDate = this.date, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, monthsShort = options.monthsShort, @@ -1028,6 +1077,7 @@ var render = { for (i = 1; i <= length; i += 1) { var _date = new Date(viewYear, viewMonth, i); var _disabled2 = false; + var featured = false; if (startDate) { _disabled2 = _date.getTime() < startDate.getTime(); @@ -1041,6 +1091,16 @@ var render = { _disabled2 = filter.call($element, _date) === false; } + var featuredDateLowerLimit = _date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, viewMonth, i + 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var _picked = viewYear === year && viewMonth === month && i === day; var view = _picked ? 'day picked' : 'day'; @@ -1048,6 +1108,7 @@ var render = { disabled: _disabled2, picked: _picked, highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay, + featured: featured, text: i, view: _disabled2 ? 'day disabled' : view })); @@ -1091,17 +1152,21 @@ var Datepicker = function () { this.initialDate = null; this.startDate = null; this.endDate = null; + this.featuredDates = []; this.init(); } _createClass(Datepicker, [{ key: 'init', value: function init() { + var _this = this; + var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, - date = options.date; + date = options.date, + featuredDates = options.featuredDates; this.$trigger = $(options.trigger); @@ -1139,6 +1204,14 @@ var Datepicker = function () { this.endDate = endDate; } + if (featuredDates) { + featuredDates = Array.isArray(featuredDates) ? featuredDates : [featuredDates]; + featuredDates = featuredDates.map(function (featuredDate) { + return _this.parseDate(featuredDate); + }); + this.featuredDates = featuredDates; + } + this.date = date; this.viewDate = new Date(date); this.initialDate = new Date(this.date); @@ -1407,7 +1480,8 @@ var Datepicker = function () { muted: false, picked: false, disabled: false, - highlighted: false + highlighted: false, + featured: false }; var classes = []; @@ -1429,6 +1503,10 @@ var Datepicker = function () { classes.push(options.disabledClass); } + if (item.featured) { + classes.push(options.featuredClass); + } + return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; } }, { diff --git a/dist/datepicker.js b/dist/datepicker.js index 69ee847..fcc3765 100644 --- a/dist/datepicker.js +++ b/dist/datepicker.js @@ -2,10 +2,10 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:23.820Z + * Date: 2018-03-24T14:57:50.457Z */ (function (global, factory) { @@ -94,6 +94,9 @@ var DEFAULTS = { // A class (CSS) for highlight date item highlightedClass: 'highlighted', + // A class (CSS) for featured date item + featuredClass: 'featured', + // The template of the datepicker template: '
                  ' + '
                  ' + '
                    ' + '
                  • ' + '
                  • ' + '
                  • ' + '
                  ' + '
                    ' + '
                    ' + '
                    ' + '
                      ' + '
                    • ' + '
                    • ' + '
                    • ' + '
                    ' + '
                      ' + '
                      ' + '
                      ' + '
                        ' + '
                      • ' + '
                      • ' + '
                      • ' + '
                      ' + '
                        ' + '
                          ' + '
                          ' + '
                          ', @@ -471,6 +474,25 @@ var methods = { }, + /** + * Sets the list of featured dates with a new list + * + * @param dates + */ + setFeaturedDates: function setFeaturedDates(dates) { + var _this = this; + + dates = Array.isArray(dates) ? dates : [dates]; + this.featuredDates = dates.map(function (date) { + return _this.parseDate(date); + }); + + if (this.built) { + this.render(); + } + }, + + /** * Parse a date string with the set date format * @@ -779,7 +801,8 @@ var render = { renderYears: function renderYears() { var options = this.options, startDate = this.startDate, - endDate = this.endDate; + endDate = this.endDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; @@ -798,6 +821,7 @@ var render = { for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); var disabled = false; + var featured = false; if (startDate) { disabled = date.getFullYear() < startDate.getFullYear(); @@ -819,6 +843,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear + i + 1, 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; @@ -826,6 +860,7 @@ var render = { picked: picked, disabled: disabled, muted: i === start || i === end, + featured: featured, text: viewYear + i, view: disabled ? 'year disabled' : view, highlighted: date.getFullYear() === thisYear @@ -841,7 +876,8 @@ var render = { var options = this.options, startDate = this.startDate, endDate = this.endDate, - viewDate = this.viewDate; + viewDate = this.viewDate, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass || ''; var months = options.monthsShort; @@ -860,6 +896,7 @@ var render = { for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); var disabled = false; + var featured = false; if (startDate) { prevDisabled = date.getFullYear() === startDate.getFullYear(); @@ -875,6 +912,16 @@ var render = { disabled = filter.call(this.$element, date) === false; } + var featuredDateLowerLimit = date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, i + 1, 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; @@ -882,6 +929,7 @@ var render = { disabled: disabled, picked: picked, highlighted: viewYear === thisYear && date.getMonth() === thisMonth, + featured: featured, index: i, text: months[i], view: disabled ? 'month disabled' : view @@ -899,7 +947,8 @@ var render = { startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate, - currentDate = this.date; + currentDate = this.date, + featuredDates = this.featuredDates; var disabledClass = options.disabledClass, filter = options.filter, monthsShort = options.monthsShort, @@ -1034,6 +1083,7 @@ var render = { for (i = 1; i <= length; i += 1) { var _date = new Date(viewYear, viewMonth, i); var _disabled2 = false; + var featured = false; if (startDate) { _disabled2 = _date.getTime() < startDate.getTime(); @@ -1047,6 +1097,16 @@ var render = { _disabled2 = filter.call($element, _date) === false; } + var featuredDateLowerLimit = _date.getTime(); + var featuredDateUpperLimit = new Date(viewYear, viewMonth, i + 1).getTime(); + for (var j = 0; j < featuredDates.length; j++) { + var featuredDate = featuredDates[j]; + if (featuredDate.getTime() >= featuredDateLowerLimit && featuredDate.getTime() < featuredDateUpperLimit) { + featured = true; + break; + } + } + var _picked = viewYear === year && viewMonth === month && i === day; var view = _picked ? 'day picked' : 'day'; @@ -1054,6 +1114,7 @@ var render = { disabled: _disabled2, picked: _picked, highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay, + featured: featured, text: i, view: _disabled2 ? 'day disabled' : view })); @@ -1097,17 +1158,21 @@ var Datepicker = function () { this.initialDate = null; this.startDate = null; this.endDate = null; + this.featuredDates = []; this.init(); } _createClass(Datepicker, [{ key: 'init', value: function init() { + var _this = this; + var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, - date = options.date; + date = options.date, + featuredDates = options.featuredDates; this.$trigger = $(options.trigger); @@ -1145,6 +1210,14 @@ var Datepicker = function () { this.endDate = endDate; } + if (featuredDates) { + featuredDates = Array.isArray(featuredDates) ? featuredDates : [featuredDates]; + featuredDates = featuredDates.map(function (featuredDate) { + return _this.parseDate(featuredDate); + }); + this.featuredDates = featuredDates; + } + this.date = date; this.viewDate = new Date(date); this.initialDate = new Date(this.date); @@ -1413,7 +1486,8 @@ var Datepicker = function () { muted: false, picked: false, disabled: false, - highlighted: false + highlighted: false, + featured: false }; var classes = []; @@ -1435,6 +1509,10 @@ var Datepicker = function () { classes.push(options.disabledClass); } + if (item.featured) { + classes.push(options.featuredClass); + } + return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; } }, { diff --git a/dist/datepicker.min.css b/dist/datepicker.min.css index 4694c0e..c7a15d6 100644 --- a/dist/datepicker.min.css +++ b/dist/datepicker.min.css @@ -2,8 +2,8 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:19.628Z - */.datepicker-container{background-color:#fff;direction:ltr;font-size:12px;left:0;line-height:30px;position:fixed;top:0;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:210px;z-index:-1;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}.datepicker-container:after,.datepicker-container:before{border:5px solid transparent;content:" ";display:block;height:0;position:absolute;width:0}.datepicker-dropdown{border:1px solid #ccc;box-shadow:0 3px 6px #ccc;box-sizing:content-box;position:absolute;z-index:1}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{border-top:0;left:10px;top:-5px}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{border-bottom-color:#fff;top:-4px}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{border-bottom:0;bottom:-5px;left:10px}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{border-top-color:#fff;bottom:-4px}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{left:auto;right:10px}.datepicker-panel>ul{margin:0;padding:0;width:102%}.datepicker-panel>ul:after,.datepicker-panel>ul:before{content:" ";display:table}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul>li{background-color:#fff;cursor:pointer;float:left;height:30px;list-style:none;margin:0;padding:0;text-align:center;width:30px}.datepicker-panel>ul>li:hover{background-color:#e5f2ff}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li.highlighted:hover{background-color:#cce5ff}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{background-color:#fff;color:#ccc;cursor:default}.datepicker-panel>ul>li.disabled.highlighted,.datepicker-panel>ul>li.disabled:hover.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li[data-view="month next"],.datepicker-panel>ul>li[data-view="month prev"],.datepicker-panel>ul>li[data-view="year next"],.datepicker-panel>ul>li[data-view="year prev"],.datepicker-panel>ul>li[data-view="years next"],.datepicker-panel>ul>li[data-view="years prev"],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view="month current"],.datepicker-panel>ul>li[data-view="year current"],.datepicker-panel>ul>li[data-view="years current"]{width:150px}.datepicker-panel>ul[data-view=months]>li,.datepicker-panel>ul[data-view=years]>li{height:52.5px;line-height:52.5px;width:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{background-color:#fff;cursor:default}.datepicker-hide{display:none} \ No newline at end of file + * Date: 2018-03-24T14:57:47.353Z + */.datepicker-container{background-color:#fff;direction:ltr;font-size:12px;left:0;line-height:30px;position:fixed;top:0;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:210px;z-index:-1;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}.datepicker-container:after,.datepicker-container:before{border:5px solid transparent;content:" ";display:block;height:0;position:absolute;width:0}.datepicker-dropdown{border:1px solid #ccc;box-shadow:0 3px 6px #ccc;box-sizing:content-box;position:absolute;z-index:1}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{border-top:0;left:10px;top:-5px}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{border-bottom-color:#fff;top:-4px}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{border-bottom:0;bottom:-5px;left:10px}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{border-top-color:#fff;bottom:-4px}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{left:auto;right:10px}.datepicker-panel>ul{margin:0;padding:0;width:102%}.datepicker-panel>ul:after,.datepicker-panel>ul:before{content:" ";display:table}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul>li{background-color:#fff;cursor:pointer;float:left;height:30px;list-style:none;margin:0;padding:0;text-align:center;width:30px}.datepicker-panel>ul>li:hover{background-color:#e5f2ff}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li.highlighted:hover{background-color:#cce5ff}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{background-color:#fff;color:#ccc;cursor:default}.datepicker-panel>ul>li.disabled.highlighted,.datepicker-panel>ul>li.disabled:hover.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li.featured{font-weight:700}.datepicker-panel>ul>li[data-view="month next"],.datepicker-panel>ul>li[data-view="month prev"],.datepicker-panel>ul>li[data-view="year next"],.datepicker-panel>ul>li[data-view="year prev"],.datepicker-panel>ul>li[data-view="years next"],.datepicker-panel>ul>li[data-view="years prev"],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view="month current"],.datepicker-panel>ul>li[data-view="year current"],.datepicker-panel>ul>li[data-view="years current"]{width:150px}.datepicker-panel>ul[data-view=months]>li,.datepicker-panel>ul[data-view=years]>li{height:52.5px;line-height:52.5px;width:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{background-color:#fff;cursor:default}.datepicker-hide{display:none} \ No newline at end of file diff --git a/dist/datepicker.min.js b/dist/datepicker.min.js index 948b595..1997c6d 100644 --- a/dist/datepicker.min.js +++ b/dist/datepicker.min.js @@ -2,9 +2,9 @@ * Datepicker v0.6.4 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2017 Chen Fengyuan + * Copyright (c) 2014-2018 Chen Fengyuan * Released under the MIT license * - * Date: 2017-11-24T14:38:23.820Z + * Date: 2018-03-24T14:57:50.457Z */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(e.jQuery)}(this,function(e){"use strict";function t(e){return"string"==typeof e}function i(e){return"number"==typeof e&&!v(e)}function a(e){return void 0===e}function s(e){return"date"===function(e){return y.call(e).slice(8,-1).toLowerCase()}(e)}function n(e,t){for(var i=arguments.length,a=Array(i>2?i-2:0),s=2;s
                                  ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},d="undefined"!=typeof window?window:{},u="datepicker",c="click.datepicker",p="datepicker-hide",f={},g={DAYS:0,MONTHS:1,YEARS:2},y=Object.prototype.toString,v=Number.isNaN||d.isNaN,m=/(y|m|d)+/g,w=/\d+/g,k={show:function(){this.built||this.build(),this.shown||this.trigger("show.datepicker").isDefaultPrevented()||(this.shown=!0,this.$picker.removeClass(p).on(c,e.proxy(this.click,this)),this.showView(this.options.startView),this.inline||(e(window).on("resize.datepicker",this.onResize=n(this.place,this)),e(document).on(c,this.onGlobalClick=n(this.globalClick,this)),e(document).on("keyup.datepicker",this.onGlobalKeyup=n(this.globalKeyup,this)),this.place()))},hide:function(){this.shown&&(this.trigger("hide.datepicker").isDefaultPrevented()||(this.shown=!1,this.$picker.addClass(p).off(c,this.click),this.inline||(e(window).off("resize.datepicker",this.onResize),e(document).off(c,this.onGlobalClick),e(document).off("keyup.datepicker",this.onGlobalKeyup))))},toggle:function(){this.shown?this.hide():this.show()},update:function(){var e=this.getValue();e!==this.oldValue&&(this.setDate(e,!0),this.oldValue=e)},pick:function(e){var t=this.$element,i=this.date;this.trigger("pick.datepicker",{view:e||"",date:i}).isDefaultPrevented()||(i=this.formatDate(this.date),this.setValue(i),this.isInput&&(t.trigger("input"),t.trigger("change")))},reset:function(){this.setDate(this.initialDate,!0),this.setValue(this.initialValue),this.shown&&this.showView(this.options.startView)},getMonthName:function(t,s){var n=this.options,r=n.monthsShort,h=n.months;return e.isNumeric(t)?t=Number(t):a(s)&&(s=t),!0===s&&(h=r),h[i(t)?t:this.date.getMonth()]},getDayName:function(t,s,n){var r=this.options,h=r.days;return e.isNumeric(t)?t=Number(t):(a(n)&&(n=s),a(s)&&(s=t)),n?h=r.daysMin:s&&(h=r.daysShort),h[i(t)?t:this.date.getDay()]},getDate:function(e){var t=this.date;return e?this.formatDate(t):new Date(t)},setDate:function(i,a){var n=this.options.filter;if(s(i)||t(i)){if(i=this.parseDate(i),e.isFunction(n)&&!1===n.call(this.$element,i))return;this.date=i,this.viewDate=new Date(i),a||this.pick(),this.built&&this.render()}},setStartDate:function(e){(s(e)||t(e))&&(this.startDate=this.parseDate(e),this.built&&this.render())},setEndDate:function(e){(s(e)||t(e))&&(this.endDate=this.parseDate(e),this.built&&this.render())},parseDate:function(i){var a=this.format,n=[];if(s(i))return new Date(i.getFullYear(),i.getMonth(),i.getDate());t(i)&&(n=i.match(w)||[]),i=new Date;var r=a.parts.length,h=i.getFullYear(),o=i.getDate(),l=i.getMonth();return n.length===r&&e.each(n,function(e,t){var i=parseInt(t,10)||1;switch(a.parts[e]){case"dd":case"d":o=i;break;case"mm":case"m":l=i-1;break;case"yy":h=2e3+i;break;case"yyyy":h=i}}),new Date(h,l,o)},formatDate:function(t){var i=this.format,a="";if(s(t)){var n=t.getFullYear(),r={d:t.getDate(),m:t.getMonth()+1,yy:n.toString().substring(2),yyyy:n};r.dd=(r.d<10?"0":"")+r.d,r.mm=(r.m<10?"0":"")+r.m,a=i.source,e.each(i.parts,function(e,t){a=a.replace(t,r[t])})}return a},destroy:function(){this.unbind(),this.unbuild(),this.$element.removeData(u)}},D={click:function(t){var i=e(t.target),a=this.options,s=this.viewDate,n=this.format;if(t.stopPropagation(),t.preventDefault(),!i.hasClass("disabled")){var r=i.data("view"),h=s.getFullYear(),l=s.getMonth(),d=s.getDate();switch(r){case"years prev":case"years next":h="years prev"===r?h-10:h+10,this.viewDate=new Date(h,l,o(h,l,d)),this.renderYears();break;case"year prev":case"year next":h="year prev"===r?h-1:h+1,this.viewDate=new Date(h,l,o(h,l,d)),this.renderMonths();break;case"year current":n.hasYear&&this.showView(g.YEARS);break;case"year picked":n.hasMonth?this.showView(g.MONTHS):(i.addClass(a.pickedClass).siblings().removeClass(a.pickedClass),this.hideView()),this.pick("year");break;case"year":h=parseInt(i.text(),10),this.date=new Date(h,l,o(h,l,d)),n.hasMonth?(this.viewDate=new Date(this.date),this.showView(g.MONTHS)):(i.addClass(a.pickedClass).siblings().removeClass(a.pickedClass),this.hideView()),this.pick("year");break;case"month prev":case"month next":(l="month prev"===r?l-1:l+1)<0?(h-=1,l+=12):l>11&&(h+=1,l-=12),this.viewDate=new Date(h,l,o(h,l,d)),this.renderDays();break;case"month current":n.hasMonth&&this.showView(g.MONTHS);break;case"month picked":n.hasDay?this.showView(g.DAYS):(i.addClass(a.pickedClass).siblings().removeClass(a.pickedClass),this.hideView()),this.pick("month");break;case"month":l=e.inArray(i.text(),a.monthsShort),this.date=new Date(h,l,o(h,l,d)),n.hasDay?(this.viewDate=new Date(h,l,o(h,l,d)),this.showView(g.DAYS)):(i.addClass(a.pickedClass).siblings().removeClass(a.pickedClass),this.hideView()),this.pick("month");break;case"day prev":case"day next":case"day":"day prev"===r?l-=1:"day next"===r&&(l+=1),d=parseInt(i.text(),10),this.date=new Date(h,l,d),this.viewDate=new Date(h,l,d),this.renderDays(),"day"===r&&this.hideView(),this.pick("day");break;case"day picked":this.hideView(),this.pick("day")}}},globalClick:function(e){for(var t=e.target,i=this.element,a=this.$trigger[0],s=!0;t!==document;){if(t===a||t===i){s=!1;break}t=t.parentNode}s&&this.hide()},keyup:function(){this.update()},globalKeyup:function(e){var t=e.target,i=e.key,a=e.keyCode;this.isInput&&t!==this.element&&this.shown&&("Tab"===i||9===a)&&this.hide()}},b={render:function(){this.renderYears(),this.renderMonths(),this.renderDays()},renderWeek:function(){var t=this,i=[],a=this.options,s=a.weekStart,n=a.daysMin;s=parseInt(s,10)%7,n=n.slice(s).concat(n.slice(0,s)),e.each(n,function(e,a){i.push(t.createItem({text:a}))}),this.$week.html(i.join(""))},renderYears:function(){var e=this.options,t=this.startDate,i=this.endDate,a=e.disabledClass,s=e.filter,n=e.yearSuffix,r=this.viewDate.getFullYear(),h=(new Date).getFullYear(),o=this.date.getFullYear(),l=[],d=!1,u=!1,c=void 0;for(c=-5;c<=6;c+=1){var p=new Date(r+c,1,1),f=!1;t&&(f=p.getFullYear()i.getFullYear(),6===c&&(u=f)),!f&&s&&(f=!1===s.call(this.$element,p));var g=r+c===o,y=g?"year picked":"year";l.push(this.createItem({picked:g,disabled:f,muted:-5===c||6===c,text:r+c,view:f?"year disabled":y,highlighted:p.getFullYear()===h}))}this.$yearsPrev.toggleClass(a,d),this.$yearsNext.toggleClass(a,u),this.$yearsCurrent.toggleClass(a,!0).html(r+-5+n+" - "+(r+6)+n),this.$years.html(l.join(""))},renderMonths:function(){var t=this.options,i=this.startDate,a=this.endDate,s=this.viewDate,n=t.disabledClass||"",r=t.monthsShort,h=e.isFunction(t.filter)&&t.filter,o=s.getFullYear(),l=new Date,d=l.getFullYear(),u=l.getMonth(),c=this.date.getFullYear(),p=this.date.getMonth(),f=[],g=!1,y=!1,v=void 0;for(v=0;v<=11;v+=1){var m=new Date(o,v,1),w=!1;i&&(w=(g=m.getFullYear()===i.getFullYear())&&m.getMonth()a.getMonth()),!w&&h&&(w=!1===h.call(this.$element,m));var k=o===c&&v===p,D=k?"month picked":"month";f.push(this.createItem({disabled:w,picked:k,highlighted:o===d&&m.getMonth()===u,index:v,text:r[v],view:w?"month disabled":D}))}this.$yearPrev.toggleClass(n,g),this.$yearNext.toggleClass(n,y),this.$yearCurrent.toggleClass(n,g&&y).html(o+t.yearSuffix||""),this.$months.html(f.join(""))},renderDays:function(){var e=this.$element,t=this.options,i=this.startDate,a=this.endDate,s=this.viewDate,n=this.date,r=t.disabledClass,o=t.filter,l=t.monthsShort,d=t.weekStart,u=t.yearSuffix,c=s.getFullYear(),p=s.getMonth(),f=new Date,g=f.getFullYear(),y=f.getMonth(),v=f.getDate(),m=n.getFullYear(),w=n.getMonth(),k=n.getDate(),D=void 0,b=void 0,C=void 0,$=[],x=c,M=p,S=!1;0===p?(x-=1,M=11):M-=1,D=h(x,M);var F=new Date(c,p,1);for((C=F.getDay()-parseInt(d,10)%7)<=0&&(C+=7),i&&(S=F.getTime()<=i.getTime()),b=D-(C-1);b<=D;b+=1){var Y=new Date(x,M,b),T=!1;i&&(T=Y.getTime()=a.getTime()),b=1;b<=C;b+=1){var j=new Date(I,N,b),O=I===m&&N===w&&b===k,H=!1;a&&(H=j.getTime()>a.getTime()),!H&&o&&(H=!1===o.call(e,j)),V.push(this.createItem({disabled:H,picked:O,highlighted:I===g&&N===y&&j.getDate()===v,muted:!0,text:b,view:"day next"}))}var q=[];for(b=1;b<=D;b+=1){var E=new Date(c,p,b),z=!1;i&&(z=E.getTime()a.getTime()),!z&&o&&(z=!1===o.call(e,E));var W=c===m&&p===w&&b===k,J=W?"day picked":"day";q.push(this.createItem({disabled:z,picked:W,highlighted:c===g&&p===y&&E.getDate()===v,text:b,view:z?"day disabled":J}))}this.$monthPrev.toggleClass(r,S),this.$monthNext.toggleClass(r,P),this.$monthCurrent.toggleClass(r,S&&P).html(t.yearFirst?c+u+" "+l[p]:l[p]+" "+c+u),this.$days.html($.join("")+q.join("")+V.join(""))}},C=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.$element=e(i),this.element=i,this.options=e.extend({},l,f[a.language],a),this.built=!1,this.shown=!1,this.isInput=!1,this.inline=!1,this.initialValue="",this.initialDate=null,this.startDate=null,this.endDate=null,this.init()}return C(t,[{key:"init",value:function(){var t=this.$element,i=this.options,a=i.startDate,s=i.endDate,n=i.date;this.$trigger=e(i.trigger),this.isInput=t.is("input")||t.is("textarea"),this.inline=i.inline&&(i.container||!this.isInput),this.format=function(t){var i=String(t).toLowerCase(),a=i.match(m);if(!a||0===a.length)throw new Error("Invalid date format.");return t={source:i,parts:a},e.each(a,function(e,i){switch(i){case"dd":case"d":t.hasDay=!0;break;case"mm":case"m":t.hasMonth=!0;break;case"yyyy":case"yy":t.hasYear=!0}}),t}(i.format);var r=this.getValue();this.initialValue=r,this.oldValue=r,n=this.parseDate(n||r),a&&(a=this.parseDate(a),n.getTime()s.getTime()&&(n=new Date(s)),this.endDate=s),this.date=n,this.viewDate=new Date(n),this.initialDate=new Date(this.date),this.bind(),(i.autoShow||this.inline)&&this.show(),i.autoPick&&this.pick()}},{key:"build",value:function(){if(!this.built){this.built=!0;var t=this.$element,i=this.options,a=e(i.template);this.$picker=a,this.$week=a.find(r("week")),this.$yearsPicker=a.find(r("years picker")),this.$yearsPrev=a.find(r("years prev")),this.$yearsNext=a.find(r("years next")),this.$yearsCurrent=a.find(r("years current")),this.$years=a.find(r("years")),this.$monthsPicker=a.find(r("months picker")),this.$yearPrev=a.find(r("year prev")),this.$yearNext=a.find(r("year next")),this.$yearCurrent=a.find(r("year current")),this.$months=a.find(r("months")),this.$daysPicker=a.find(r("days picker")),this.$monthPrev=a.find(r("month prev")),this.$monthNext=a.find(r("month next")),this.$monthCurrent=a.find(r("month current")),this.$days=a.find(r("days")),this.inline?e(i.container||t).append(a.addClass("datepicker-inline")):(e(document.body).append(a.addClass("datepicker-dropdown")),a.addClass(p)),this.renderWeek()}}},{key:"unbuild",value:function(){this.built&&(this.built=!1,this.$picker.remove())}},{key:"bind",value:function(){var t=this.options,i=this.$element;e.isFunction(t.show)&&i.on("show.datepicker",t.show),e.isFunction(t.hide)&&i.on("hide.datepicker",t.hide),e.isFunction(t.pick)&&i.on("pick.datepicker",t.pick),this.isInput&&i.on("keyup.datepicker",e.proxy(this.keyup,this)),this.inline||(t.trigger?this.$trigger.on(c,e.proxy(this.toggle,this)):this.isInput?i.on("focus.datepicker",e.proxy(this.show,this)):i.on(c,e.proxy(this.show,this)))}},{key:"unbind",value:function(){var t=this.$element,i=this.options;e.isFunction(i.show)&&t.off("show.datepicker",i.show),e.isFunction(i.hide)&&t.off("hide.datepicker",i.hide),e.isFunction(i.pick)&&t.off("pick.datepicker",i.pick),this.isInput&&t.off("keyup.datepicker",this.keyup),this.inline||(i.trigger?this.$trigger.off(c,this.toggle):this.isInput?t.off("focus.datepicker",this.show):t.off(c,this.show))}},{key:"showView",value:function(e){var t=this.$yearsPicker,i=this.$monthsPicker,a=this.$daysPicker,s=this.format;if(s.hasYear||s.hasMonth||s.hasDay)switch(Number(e)){case g.YEARS:i.addClass(p),a.addClass(p),s.hasYear?(this.renderYears(),t.removeClass(p),this.place()):this.showView(g.DAYS);break;case g.MONTHS:t.addClass(p),a.addClass(p),s.hasMonth?(this.renderMonths(),i.removeClass(p),this.place()):this.showView(g.YEARS);break;default:t.addClass(p),i.addClass(p),s.hasDay?(this.renderDays(),a.removeClass(p),this.place()):this.showView(g.MONTHS)}}},{key:"hideView",value:function(){!this.inline&&this.options.autoHide&&this.hide()}},{key:"place",value:function(){if(!this.inline){var t=this.$element,i=this.options,a=this.$picker,s=e(document).outerWidth(),n=e(document).outerHeight(),r=t.outerWidth(),h=t.outerHeight(),o=a.width(),l=a.height(),d=t.offset(),u=d.left,c=d.top,p=parseFloat(i.offset),f=$;v(p)&&(p=10),c>l&&c+h+l>n?(c-=l+p,f=x):c+=h+p,u+o>s&&(u+=r-o,f=f.replace("left","right")),a.removeClass(M).addClass(f).css({top:c,left:u,zIndex:parseInt(i.zIndex,10)})}}},{key:"trigger",value:function(t,i){var a=e.Event(t,i);return this.$element.trigger(a),a}},{key:"createItem",value:function(t){var i=this.options,a=i.itemTag,s={text:"",view:"",muted:!1,picked:!1,disabled:!1,highlighted:!1},n=[];return e.extend(s,t),s.muted&&n.push(i.mutedClass),s.highlighted&&n.push(i.highlightedClass),s.picked&&n.push(i.pickedClass),s.disabled&&n.push(i.disabledClass),"<"+a+' class="'+n.join(" ")+'" data-view="'+s.view+'">'+s.text+""}},{key:"getValue",value:function(){var e=this.$element;return this.isInput?e.val():e.text()}},{key:"setValue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=this.$element;this.isInput?t.val(e):t.text(e)}}],[{key:"setDefaults",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.extend(l,f[t.language],t)}}]),t}();if(e.extend&&e.extend(S.prototype,b,D,k),e.fn){var F=e.fn.datepicker;e.fn.datepicker=function(i){for(var s=arguments.length,n=Array(s>1?s-1:0),r=1;r
                                          ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},e="undefined"!=typeof window?window:{},l="datepicker",s="click."+l,n="focus."+l,r="hide."+l,h="keyup."+l,o="pick."+l,t="resize."+l,d="show."+l,u=l+"-hide",c={},f=0,g=1,p=2,i=Object.prototype.toString;function y(e){return"string"==typeof e}var v=Number.isNaN||e.isNaN;function m(e){return"number"==typeof e&&!v(e)}function w(e){return void 0===e}function k(e){return"date"===(t=e,i.call(t).slice(8,-1).toLowerCase());var t}function D(a,s){for(var e=arguments.length,n=Array(2i.getFullYear(),6===f&&(c=p)),!p&&n&&(p=!1===n.call(this.$element,g));for(var v=g.getTime(),m=new Date(h+f+1,1,1).getTime(),w=0;w=v&&k.getTime()i.getMonth()),!w&&h&&(w=!1===h.call(this.$element,m));for(var D=m.getTime(),b=new Date(o,v+1,1).getTime(),C=0;C=D&&$.getTime()=a.getTime()),b=1;b<=C;b+=1){var A=new Date(S,N,b),q=S===m&&N===w&&b===k,W=!1;a&&(W=A.getTime()>a.getTime()),!W&&o&&(W=!1===o.call(e,A)),I.push(this.createItem({disabled:W,picked:q,highlighted:S===p&&N===y&&A.getDate()===v,muted:!0,text:b,view:"day next"}))}var z=[];for(b=1;b<=D;b+=1){var J=new Date(c,f,b),O=!1,E=!1;i&&(O=J.getTime()a.getTime()),!O&&o&&(O=!1===o.call(e,J));for(var G=J.getTime(),H=new Date(c,f,b+1).getTime(),K=0;K=G&&L.getTime()s.getTime()&&(n=new Date(s)),this.endDate=s),r&&(r=(r=Array.isArray(r)?r:[r]).map(function(e){return t.parseDate(e)}),this.featuredDates=r),this.date=n,this.viewDate=new Date(n),this.initialDate=new Date(this.date),this.bind(),(i.autoShow||this.inline)&&this.show(),i.autoPick&&this.pick()}},{key:"build",value:function(){if(!this.built){this.built=!0;var e=this.$element,t=this.options,i=T(t.template);this.$picker=i,this.$week=i.find(b("week")),this.$yearsPicker=i.find(b("years picker")),this.$yearsPrev=i.find(b("years prev")),this.$yearsNext=i.find(b("years next")),this.$yearsCurrent=i.find(b("years current")),this.$years=i.find(b("years")),this.$monthsPicker=i.find(b("months picker")),this.$yearPrev=i.find(b("year prev")),this.$yearNext=i.find(b("year next")),this.$yearCurrent=i.find(b("year current")),this.$months=i.find(b("months")),this.$daysPicker=i.find(b("days picker")),this.$monthPrev=i.find(b("month prev")),this.$monthNext=i.find(b("month next")),this.$monthCurrent=i.find(b("month current")),this.$days=i.find(b("days")),this.inline?T(t.container||e).append(i.addClass(l+"-inline")):(T(document.body).append(i.addClass(l+"-dropdown")),i.addClass(u)),this.renderWeek()}}},{key:"unbuild",value:function(){this.built&&(this.built=!1,this.$picker.remove())}},{key:"bind",value:function(){var e=this.options,t=this.$element;T.isFunction(e.show)&&t.on(d,e.show),T.isFunction(e.hide)&&t.on(r,e.hide),T.isFunction(e.pick)&&t.on(o,e.pick),this.isInput&&t.on(h,T.proxy(this.keyup,this)),this.inline||(e.trigger?this.$trigger.on(s,T.proxy(this.toggle,this)):this.isInput?t.on(n,T.proxy(this.show,this)):t.on(s,T.proxy(this.show,this)))}},{key:"unbind",value:function(){var e=this.$element,t=this.options;T.isFunction(t.show)&&e.off(d,t.show),T.isFunction(t.hide)&&e.off(r,t.hide),T.isFunction(t.pick)&&e.off(o,t.pick),this.isInput&&e.off(h,this.keyup),this.inline||(t.trigger?this.$trigger.off(s,this.toggle):this.isInput?e.off(n,this.show):e.off(s,this.show))}},{key:"showView",value:function(e){var t=this.$yearsPicker,i=this.$monthsPicker,a=this.$daysPicker,s=this.format;if(s.hasYear||s.hasMonth||s.hasDay)switch(Number(e)){case p:i.addClass(u),a.addClass(u),s.hasYear?(this.renderYears(),t.removeClass(u),this.place()):this.showView(f);break;case g:t.addClass(u),a.addClass(u),s.hasMonth?(this.renderMonths(),i.removeClass(u),this.place()):this.showView(p);break;default:t.addClass(u),i.addClass(u),s.hasDay?(this.renderDays(),a.removeClass(u),this.place()):this.showView(g)}}},{key:"hideView",value:function(){!this.inline&&this.options.autoHide&&this.hide()}},{key:"place",value:function(){if(!this.inline){var e=this.$element,t=this.options,i=this.$picker,a=T(document).outerWidth(),s=T(document).outerHeight(),n=e.outerWidth(),r=e.outerHeight(),h=i.width(),o=i.height(),l=e.offset(),d=l.left,u=l.top,c=parseFloat(t.offset),f=I;v(c)&&(c=10),o'+a.text+""}},{key:"getValue",value:function(){var e=this.$element;return this.isInput?e.val():e.text()}},{key:"setValue",value:function(){var e=0 ul > li.featured { + font-weight: bold; +} + .datepicker-panel > ul > li[data-view="years prev"], .datepicker-panel > ul > li[data-view="year prev"], .datepicker-panel > ul > li[data-view="month prev"], diff --git a/docs/css/main.css b/docs/css/main.css index 8a76599..047c2a0 100644 --- a/docs/css/main.css +++ b/docs/css/main.css @@ -120,7 +120,7 @@ .docs-options > .input-group > .input-group-addon { justify-content: center; - min-width: 6rem; + min-width: 8rem; } .docs-actions > .input-group, diff --git a/docs/index.html b/docs/index.html index 121989a..93fedad 100644 --- a/docs/index.html +++ b/docs/index.html @@ -95,6 +95,10 @@ endDate +
                                          + featuredDates + +
                                          language