/** * Date selector * @module Ink.UI.DatePicker_1 * @version 1 */ Ink.createModule('Ink.UI.DatePicker', '1', ['Ink.UI.Common_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1','Ink.Util.Date_1', 'Ink.Dom.Browser_1'], function(Common, Event, Css, InkElement, Selector, InkArray, InkDate ) { 'use strict'; // Clamp a number into a min/max limit function clamp(n, min, max) { if (n > max) { n = max; } if (n < min) { n = min; } return n; } function dateishFromYMDString(YMD) { var split = YMD.split('-'); return dateishFromYMD(+split[0], +split[1] - 1, +split[2]); } function dateishFromYMD(year, month, day) { return {_year: year, _month: month, _day: day}; } function dateishFromDate(date) { return {_year: date.getFullYear(), _month: date.getMonth(), _day: date.getDate()}; } /** * @class Ink.UI.DatePicker * @constructor * @version 1 * * @param {String|DOMElement} selector * @param {Object} [options] Options * @param {Boolean} [options.autoOpen] Flag to automatically open the datepicker. * @param {String} [options.cleanText] Text for the clean button. Defaults to 'Clear'. * @param {String} [options.closeText] Text for the close button. Defaults to 'Close'. * @param {String} [options.cssClass] CSS class to be applied on the datepicker * @param {String|DOMElement} [options.pickerField] (if not using in an input[type="text"]) Element which displays the DatePicker when clicked. Defaults to an "open" link. * @param {String} [options.dateRange] Enforce limits to year, month and day for the Date, ex: '1990-08-25:2020-11' * @param {Boolean} [options.displayInSelect] Flag to display the component in a select element. * @param {String|DOMElement} [options.dayField] (if using options.displayInSelect) `select` field with days. * @param {String|DOMElement} [options.monthField] (if using options.displayInSelect) `select` field with months. * @param {String|DOMElement} [options.yearField] (if using options.displayInSelect) `select` field with years. * @param {String} [options.format] Date format string * @param {Object} [options.month] Hash of month names. Defaults to portuguese month names. January is 1. * @param {String} [options.nextLinkText] Text for the previous button. Defaults to '«'. * @param {String} [options.ofText] Text to show between month and year. Defaults to ' of '. * @param {Boolean} [options.onFocus] If the datepicker should open when the target element is focused. Defaults to true. * @param {Function} [options.onMonthSelected] Callback to execute when the month is selected. * @param {Function} [options.onSetDate] Callback to execute when the date is set. * @param {Function} [options.onYearSelected] Callback to execute when the year is selected. * @param {String} [options.position] Position for the datepicker. Either 'right' or 'bottom'. Defaults to 'right'. * @param {String} [options.prevLinkText] Text for the previous button. Defaults to '«'. * @param {Boolean} [options.showClean] If the clean button should be visible. Defaults to true. * @param {Boolean} [options.showClose] If the close button should be visible. Defaults to true. * @param {Boolean} [options.shy] If the datepicker should start automatically. Defaults to true. * @param {String} [options.startDate] Date to define initial month. Must be in yyyy-mm-dd format. * @param {Number} [options.startWeekDay] First day of the week. Sunday is zero. Defaults to 1 (Monday). * @param {Function} [options.validYearFn] Callback to execute when 'rendering' the month (in the month view) * @param {Function} [options.validMonthFn] Callback to execute when 'rendering' the month (in the month view) * @param {Function} [options.validDayFn] Callback to execute when 'rendering' the day (in the month view) * @param {Function} [options.nextValidDateFn] Function to calculate the next valid date, given the current. Useful when there's invalid dates or time frames. * @param {Function} [options.prevValidDateFn] Function to calculate the previous valid date, given the current. Useful when there's invalid dates or time frames. * @param {Object} [options.wDay] Hash of week day names. Sunday is 0. Defaults to { 0:'Sunday', 1:'Monday', etc... * @param {String} [options.yearRange] Enforce limits to year for the Date, ex: '1990:2020' (deprecated) * * @sample Ink_UI_DatePicker_1.html */ var DatePicker = function() { Common.BaseUIComponent.apply(this, arguments); }; DatePicker._name = 'DatePicker_1'; DatePicker._optionDefinition = { autoOpen: ['Boolean', false], cleanText: ['String', 'Clear'], closeText: ['String', 'Close'], pickerField: ['Element', null], containerElement:['Element', null], cssClass: ['String', 'ink-calendar bottom'], dateRange: ['String', null], // use this in a