|
7 | 7 | * @author Alexander Krupko <[email protected]>
|
8 | 8 | * @copyright 2016 Alexander Krupko
|
9 | 9 | * @license MIT
|
10 |
| - * @version 1.0.5 |
| 10 | + * @version 1.0.7 |
11 | 11 | */
|
12 | 12 |
|
13 | 13 | !function()
|
|
26 | 26 | todayButtonLabel : 'Today',
|
27 | 27 | clearButton : true,
|
28 | 28 | clearButtonLabel : 'Clear',
|
29 |
| - titleFormatDay : '{MM} {dd}, {yyyy}', |
30 |
| - titleFormatMonth : '{MM} {yyyy}', |
31 |
| - titleFormatYear : '{yyyy}' |
| 29 | + titleFormatDay : 'MM dd, yyyy', |
| 30 | + titleFormatMonth : 'MM yyyy', |
| 31 | + titleFormatYear : 'yyyy' |
32 | 32 | },
|
33 | 33 | openedDPX = null;
|
34 | 34 |
|
|
155 | 155 | * MM - full month name
|
156 | 156 | * yy - 2-digits year number
|
157 | 157 | * yyyy - 4-digits year number
|
158 |
| - * @param {Boolean} [useBrackets=false] If true, literals should be wrapped to curly brackets |
159 | 158 | */
|
160 |
| - function getFormatedDate(dt, format, useBrackets) |
| 159 | + function getFormatedDate(dt, format) |
161 | 160 | {
|
162 | 161 | var items = {
|
163 | 162 | d : dt.getDate(),
|
|
177 | 176 | items.M = options.shortMonthLabels[items.M];
|
178 | 177 | items.MM = options.singleMonthLabels[items.MM];
|
179 | 178 |
|
180 |
| - var regexp = useBrackets ? /\{([dmM]{1,2}|D|yyyy|yy)\}/g : /([dmM]{1,2}|D|yyyy|yy)/g; |
181 |
| - return format.replace(regexp, function(match, literal) |
| 179 | + return format.replace(/([dmM]{1,2}|D|yyyy|yy)/g, function(match) |
182 | 180 | {
|
183 |
| - return typeof items[literal] !== 'undefined' ? items[literal] : match; |
| 181 | + return typeof items[match] !== 'undefined' ? items[match] : match; |
184 | 182 | });
|
185 | 183 | }
|
186 | 184 |
|
|
315 | 313 |
|
316 | 314 | // set title
|
317 | 315 | elements.title.innerHTML = mode
|
318 |
| - ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true) |
| 316 | + ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear) |
319 | 317 | : (zeroYear + ' - ' + (zeroYear + 9));
|
320 | 318 | elements.title.dpxValue = dt.getTime();
|
321 |
| - elements.title.title = mode === 2 |
322 |
| - ? getFormatedDate(dt, options.titleFormatYear, true) |
323 |
| - : (zeroYear + ' - ' + (zeroYear + 9)); |
| 319 | + elements.title.title = mode === 2 ? getFormatedDate(dt, options.titleFormatYear) : (zeroYear + ' - ' + (zeroYear + 9)); |
324 | 320 |
|
325 | 321 | // prev and next arrows
|
326 | 322 | elements.prevTitle.classList[dt.getTime() <= dtMin ? 'add' : 'remove']('dpx-disabled');
|
327 | 323 | mode === 2 ? dt.setMonth(setMonth - 1) : dt.setFullYear(mode ? setYear - 1 : zeroYear - 10);
|
328 | 324 | elements.prevTitle.title = mode
|
329 |
| - ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true) |
| 325 | + ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear) |
330 | 326 | : ((zeroYear - 10) + ' - ' + (zeroYear - 1));
|
331 | 327 | elements.prevTitle.dpxValue = dt.getTime();
|
332 | 328 |
|
333 | 329 | mode === 2 ? dt.setMonth(dt.getMonth() + 2) : dt.setFullYear(mode ? setYear + 1 : zeroYear + 20);
|
334 | 330 | elements.nextTitle.classList[dt.getTime() > dtMax ? 'add' : 'remove']('dpx-disabled');
|
335 | 331 | elements.nextTitle.title = mode
|
336 |
| - ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true) |
| 332 | + ? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear) |
337 | 333 | : ((zeroYear + 10) + ' - ' + (zeroYear + 19));
|
338 | 334 | elements.nextTitle.dpxValue = dt.getTime();
|
339 | 335 |
|
|
381 | 377 | i = mode === 2 ? 42 : 16;
|
382 | 378 | for (; i--; dt[setter](dt[getter]() + 1)) {
|
383 | 379 | var classes = ['dpx-item'],
|
384 |
| - title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode], true); |
| 380 | + title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode]); |
385 | 381 |
|
386 | 382 | (mode ? (mode === 2 ? dt.getMonth() !== setMonth : dt.getFullYear() !== setYear) : (dt.getFullYear() < zeroYear || dt.getFullYear() > zeroYear + 9)) && classes.push('dpx-out');
|
387 | 383 | mode === 2 && (dt.getDay() === 6 || dt.getDay() === 0) && classes.push('dpx-weekend');
|
|
0 commit comments