materialize-sass 0.97.0 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -0
- data/README.md +48 -10
- data/Rakefile +129 -1
- data/assets/javascripts/materialize/anime.min.js +417 -0
- data/assets/javascripts/materialize/autocomplete.js +504 -0
- data/assets/javascripts/materialize/buttons.js +409 -0
- data/assets/javascripts/materialize/cards.js +34 -0
- data/assets/javascripts/materialize/carousel.js +797 -0
- data/assets/javascripts/materialize/cash.js +990 -0
- data/assets/javascripts/materialize/characterCounter.js +180 -0
- data/assets/javascripts/materialize/chips.js +564 -0
- data/assets/javascripts/materialize/collapsible.js +337 -0
- data/assets/javascripts/materialize/component.js +57 -0
- data/assets/javascripts/materialize/datepicker.js +935 -0
- data/assets/javascripts/materialize/dropdown.js +659 -0
- data/assets/javascripts/materialize/extras/nouislider.js +2147 -0
- data/assets/javascripts/materialize/extras/nouislider.min.js +1 -0
- data/assets/javascripts/materialize/forms.js +244 -0
- data/assets/javascripts/materialize/global.js +408 -0
- data/assets/javascripts/materialize/materialbox.js +513 -0
- data/assets/javascripts/materialize/modal.js +449 -0
- data/assets/javascripts/materialize/parallax.js +173 -0
- data/assets/javascripts/materialize/pushpin.js +179 -0
- data/assets/javascripts/materialize/range.js +310 -0
- data/assets/javascripts/materialize/scrollspy.js +328 -0
- data/assets/javascripts/materialize/select.js +497 -0
- data/assets/javascripts/materialize/sidenav.js +655 -0
- data/assets/javascripts/materialize/slider.js +424 -0
- data/assets/javascripts/materialize/tabs.js +476 -0
- data/assets/javascripts/materialize/tapTarget.js +364 -0
- data/assets/javascripts/materialize/timepicker.js +647 -0
- data/assets/javascripts/materialize/toasts.js +355 -0
- data/assets/javascripts/materialize/tooltip.js +351 -0
- data/{app/assets → assets}/javascripts/materialize/waves.js +42 -47
- data/assets/javascripts/materialize-sprockets.js +29 -0
- data/assets/javascripts/materialize.js +12374 -0
- data/assets/stylesheets/materialize/components/_badges.scss +55 -0
- data/assets/stylesheets/materialize/components/_buttons.scss +322 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +72 -29
- data/assets/stylesheets/materialize/components/_carousel.scss +90 -0
- data/assets/stylesheets/materialize/components/_chips.scss +90 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +23 -17
- data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
- data/{app/assets/stylesheets/materialize/components/_color.scss → assets/stylesheets/materialize/components/_color-variables.scss} +22 -64
- data/assets/stylesheets/materialize/components/_datepicker.scss +191 -0
- data/assets/stylesheets/materialize/components/_dropdown.scss +85 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +197 -144
- data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +57 -18
- data/assets/stylesheets/materialize/components/_icons-material-design.scss +5 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +15 -13
- data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +18 -14
- data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +89 -25
- data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +5 -3
- data/assets/stylesheets/materialize/components/_pulse.scss +34 -0
- data/assets/stylesheets/materialize/components/_sidenav.scss +208 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +2 -2
- data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +5 -5
- data/assets/stylesheets/materialize/components/_tabs.scss +99 -0
- data/assets/stylesheets/materialize/components/_tapTarget.scss +103 -0
- data/assets/stylesheets/materialize/components/_timepicker.scss +183 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +17 -22
- data/assets/stylesheets/materialize/components/_tooltip.scss +32 -0
- data/assets/stylesheets/materialize/components/_transitions.scss +13 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +11 -9
- data/assets/stylesheets/materialize/components/_variables.scss +349 -0
- data/assets/stylesheets/materialize/components/_waves.scss +114 -0
- data/assets/stylesheets/materialize/components/forms/_checkboxes.scss +200 -0
- data/assets/stylesheets/materialize/components/forms/_file-input.scss +44 -0
- data/assets/stylesheets/materialize/components/forms/_forms.scss +22 -0
- data/assets/stylesheets/materialize/components/forms/_input-fields.scss +354 -0
- data/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +115 -0
- data/assets/stylesheets/materialize/components/forms/_range.scss +161 -0
- data/assets/stylesheets/materialize/components/forms/_select.scss +190 -0
- data/assets/stylesheets/materialize/components/forms/_switches.scss +89 -0
- data/assets/stylesheets/materialize/extras/nouislider.css +406 -0
- data/{app/assets → assets}/stylesheets/materialize.scss +13 -10
- data/lib/materialize-sass/engine.rb +11 -6
- data/lib/materialize-sass/helpers.rb +38 -0
- data/lib/materialize-sass/version.rb +1 -1
- data/lib/materialize-sass.rb +13 -28
- data/materialize-sass.gemspec +5 -5
- metadata +97 -105
- data/app/assets/fonts/material-design-icons/LICENSE.txt +0 -428
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.eot +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.svg +0 -769
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.ttf +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.woff +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
- data/app/assets/javascripts/materialize/animation.js +0 -9
- data/app/assets/javascripts/materialize/buttons.js +0 -61
- data/app/assets/javascripts/materialize/cards.js +0 -27
- data/app/assets/javascripts/materialize/character_counter.js +0 -59
- data/app/assets/javascripts/materialize/collapsible.js +0 -139
- data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1430
- data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1123
- data/app/assets/javascripts/materialize/dropdown.js +0 -178
- data/app/assets/javascripts/materialize/forms.js +0 -456
- data/app/assets/javascripts/materialize/global.js +0 -36
- data/app/assets/javascripts/materialize/hammer.min.js +0 -1
- data/app/assets/javascripts/materialize/init.js +0 -136
- data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
- data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
- data/app/assets/javascripts/materialize/jquery.timeago.min.js +0 -1
- data/app/assets/javascripts/materialize/leanModal.js +0 -178
- data/app/assets/javascripts/materialize/materialbox.js +0 -249
- data/app/assets/javascripts/materialize/parallax.js +0 -58
- data/app/assets/javascripts/materialize/prism.js +0 -8
- data/app/assets/javascripts/materialize/pushpin.js +0 -62
- data/app/assets/javascripts/materialize/scrollFire.js +0 -44
- data/app/assets/javascripts/materialize/scrollspy.js +0 -284
- data/app/assets/javascripts/materialize/sideNav.js +0 -312
- data/app/assets/javascripts/materialize/slider.js +0 -301
- data/app/assets/javascripts/materialize/tabs.js +0 -136
- data/app/assets/javascripts/materialize/toasts.js +0 -125
- data/app/assets/javascripts/materialize/tooltip.js +0 -166
- data/app/assets/javascripts/materialize/transitions.js +0 -154
- data/app/assets/javascripts/materialize/velocity.min.js +0 -4
- data/app/assets/javascripts/materialize-sprockets.js +0 -27
- data/app/assets/javascripts/materialize.js +0 -6159
- data/app/assets/stylesheets/materialize/components/_buttons.scss +0 -157
- data/app/assets/stylesheets/materialize/components/_dropdown.scss +0 -40
- data/app/assets/stylesheets/materialize/components/_form.scss +0 -886
- data/app/assets/stylesheets/materialize/components/_icons-material-design.scss +0 -3257
- data/app/assets/stylesheets/materialize/components/_mixins.scss +0 -5
- data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -427
- data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -376
- data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -38
- data/app/assets/stylesheets/materialize/components/_sideNav.scss +0 -111
- data/app/assets/stylesheets/materialize/components/_tabs.scss +0 -47
- data/app/assets/stylesheets/materialize/components/_tooltip.scss +0 -34
- data/app/assets/stylesheets/materialize/components/_variables.scss +0 -152
- data/app/assets/stylesheets/materialize/components/_waves.scss +0 -167
- data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -435
- data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -201
- data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -125
@@ -0,0 +1,935 @@
|
|
1
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2
|
+
|
3
|
+
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
4
|
+
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
+
|
7
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
8
|
+
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
10
|
+
|
11
|
+
(function ($) {
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _defaults = {
|
15
|
+
// Close when date is selected
|
16
|
+
autoClose: false,
|
17
|
+
|
18
|
+
// the default output format for the input field value
|
19
|
+
format: 'mmm dd, yyyy',
|
20
|
+
|
21
|
+
// Used to create date object from current input string
|
22
|
+
parse: null,
|
23
|
+
|
24
|
+
// The initial date to view when first opened
|
25
|
+
defaultDate: null,
|
26
|
+
|
27
|
+
// Make the `defaultDate` the initial selected value
|
28
|
+
setDefaultDate: false,
|
29
|
+
|
30
|
+
disableWeekends: false,
|
31
|
+
|
32
|
+
disableDayFn: null,
|
33
|
+
|
34
|
+
// First day of week (0: Sunday, 1: Monday etc)
|
35
|
+
firstDay: 0,
|
36
|
+
|
37
|
+
// The earliest date that can be selected
|
38
|
+
minDate: null,
|
39
|
+
// Thelatest date that can be selected
|
40
|
+
maxDate: null,
|
41
|
+
|
42
|
+
// Number of years either side, or array of upper/lower range
|
43
|
+
yearRange: 10,
|
44
|
+
|
45
|
+
// used internally (don't config outside)
|
46
|
+
minYear: 0,
|
47
|
+
maxYear: 9999,
|
48
|
+
minMonth: undefined,
|
49
|
+
maxMonth: undefined,
|
50
|
+
|
51
|
+
startRange: null,
|
52
|
+
endRange: null,
|
53
|
+
|
54
|
+
isRTL: false,
|
55
|
+
|
56
|
+
// Render the month after year in the calendar title
|
57
|
+
showMonthAfterYear: false,
|
58
|
+
|
59
|
+
// Render days of the calendar grid that fall in the next or previous month
|
60
|
+
showDaysInNextAndPreviousMonths: false,
|
61
|
+
|
62
|
+
// Specify a DOM element to render the calendar in
|
63
|
+
container: null,
|
64
|
+
|
65
|
+
// Show clear button
|
66
|
+
showClearBtn: false,
|
67
|
+
|
68
|
+
// internationalization
|
69
|
+
i18n: {
|
70
|
+
cancel: 'Cancel',
|
71
|
+
clear: 'Clear',
|
72
|
+
done: 'Ok',
|
73
|
+
previousMonth: '‹',
|
74
|
+
nextMonth: '›',
|
75
|
+
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
76
|
+
monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
77
|
+
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
78
|
+
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
79
|
+
weekdaysAbbrev: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
|
80
|
+
},
|
81
|
+
|
82
|
+
// events array
|
83
|
+
events: [],
|
84
|
+
|
85
|
+
// callback function
|
86
|
+
onSelect: null,
|
87
|
+
onOpen: null,
|
88
|
+
onClose: null,
|
89
|
+
onDraw: null
|
90
|
+
};
|
91
|
+
|
92
|
+
/**
|
93
|
+
* @class
|
94
|
+
*
|
95
|
+
*/
|
96
|
+
|
97
|
+
var Datepicker = function (_Component) {
|
98
|
+
_inherits(Datepicker, _Component);
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Construct Datepicker instance and set up overlay
|
102
|
+
* @constructor
|
103
|
+
* @param {Element} el
|
104
|
+
* @param {Object} options
|
105
|
+
*/
|
106
|
+
function Datepicker(el, options) {
|
107
|
+
_classCallCheck(this, Datepicker);
|
108
|
+
|
109
|
+
var _this = _possibleConstructorReturn(this, (Datepicker.__proto__ || Object.getPrototypeOf(Datepicker)).call(this, Datepicker, el, options));
|
110
|
+
|
111
|
+
_this.el.M_Datepicker = _this;
|
112
|
+
|
113
|
+
_this.options = $.extend({}, Datepicker.defaults, options);
|
114
|
+
|
115
|
+
// make sure i18n defaults are not lost when only few i18n option properties are passed
|
116
|
+
if (!!options && options.hasOwnProperty('i18n') && typeof options.i18n === 'object') {
|
117
|
+
_this.options.i18n = $.extend({}, Datepicker.defaults.i18n, options.i18n);
|
118
|
+
}
|
119
|
+
|
120
|
+
// Remove time component from minDate and maxDate options
|
121
|
+
if (_this.options.minDate) _this.options.minDate.setHours(0, 0, 0, 0);
|
122
|
+
if (_this.options.maxDate) _this.options.maxDate.setHours(0, 0, 0, 0);
|
123
|
+
|
124
|
+
_this.id = M.guid();
|
125
|
+
|
126
|
+
_this._setupVariables();
|
127
|
+
_this._insertHTMLIntoDOM();
|
128
|
+
_this._setupModal();
|
129
|
+
|
130
|
+
_this._setupEventHandlers();
|
131
|
+
|
132
|
+
if (!_this.options.defaultDate) {
|
133
|
+
_this.options.defaultDate = new Date(Date.parse(_this.el.value));
|
134
|
+
}
|
135
|
+
|
136
|
+
var defDate = _this.options.defaultDate;
|
137
|
+
if (Datepicker._isDate(defDate)) {
|
138
|
+
if (_this.options.setDefaultDate) {
|
139
|
+
_this.setDate(defDate, true);
|
140
|
+
_this.setInputValue();
|
141
|
+
} else {
|
142
|
+
_this.gotoDate(defDate);
|
143
|
+
}
|
144
|
+
} else {
|
145
|
+
_this.gotoDate(new Date());
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Describes open/close state of datepicker
|
150
|
+
* @type {Boolean}
|
151
|
+
*/
|
152
|
+
_this.isOpen = false;
|
153
|
+
return _this;
|
154
|
+
}
|
155
|
+
|
156
|
+
_createClass(Datepicker, [{
|
157
|
+
key: 'destroy',
|
158
|
+
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Teardown component
|
162
|
+
*/
|
163
|
+
value: function destroy() {
|
164
|
+
this._removeEventHandlers();
|
165
|
+
this.modal.destroy();
|
166
|
+
$(this.modalEl).remove();
|
167
|
+
this.destroySelects();
|
168
|
+
this.el.M_Datepicker = undefined;
|
169
|
+
}
|
170
|
+
}, {
|
171
|
+
key: 'destroySelects',
|
172
|
+
value: function destroySelects() {
|
173
|
+
var oldYearSelect = this.calendarEl.querySelector('.orig-select-year');
|
174
|
+
if (oldYearSelect) {
|
175
|
+
M.FormSelect.getInstance(oldYearSelect).destroy();
|
176
|
+
}
|
177
|
+
var oldMonthSelect = this.calendarEl.querySelector('.orig-select-month');
|
178
|
+
if (oldMonthSelect) {
|
179
|
+
M.FormSelect.getInstance(oldMonthSelect).destroy();
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}, {
|
183
|
+
key: '_insertHTMLIntoDOM',
|
184
|
+
value: function _insertHTMLIntoDOM() {
|
185
|
+
if (this.options.showClearBtn) {
|
186
|
+
$(this.clearBtn).css({ visibility: '' });
|
187
|
+
this.clearBtn.innerHTML = this.options.i18n.clear;
|
188
|
+
}
|
189
|
+
|
190
|
+
this.doneBtn.innerHTML = this.options.i18n.done;
|
191
|
+
this.cancelBtn.innerHTML = this.options.i18n.cancel;
|
192
|
+
|
193
|
+
if (this.options.container) {
|
194
|
+
this.$modalEl.appendTo(this.options.container);
|
195
|
+
} else {
|
196
|
+
this.$modalEl.insertBefore(this.el);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
}, {
|
200
|
+
key: '_setupModal',
|
201
|
+
value: function _setupModal() {
|
202
|
+
var _this2 = this;
|
203
|
+
|
204
|
+
this.modalEl.id = 'modal-' + this.id;
|
205
|
+
this.modal = M.Modal.init(this.modalEl, {
|
206
|
+
onCloseEnd: function () {
|
207
|
+
_this2.isOpen = false;
|
208
|
+
}
|
209
|
+
});
|
210
|
+
}
|
211
|
+
}, {
|
212
|
+
key: 'toString',
|
213
|
+
value: function toString(format) {
|
214
|
+
var _this3 = this;
|
215
|
+
|
216
|
+
format = format || this.options.format;
|
217
|
+
if (!Datepicker._isDate(this.date)) {
|
218
|
+
return '';
|
219
|
+
}
|
220
|
+
|
221
|
+
var formatArray = format.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g);
|
222
|
+
var formattedDate = formatArray.map(function (label) {
|
223
|
+
if (_this3.formats[label]) {
|
224
|
+
return _this3.formats[label]();
|
225
|
+
}
|
226
|
+
|
227
|
+
return label;
|
228
|
+
}).join('');
|
229
|
+
return formattedDate;
|
230
|
+
}
|
231
|
+
}, {
|
232
|
+
key: 'setDate',
|
233
|
+
value: function setDate(date, preventOnSelect) {
|
234
|
+
if (!date) {
|
235
|
+
this.date = null;
|
236
|
+
this._renderDateDisplay();
|
237
|
+
return this.draw();
|
238
|
+
}
|
239
|
+
if (typeof date === 'string') {
|
240
|
+
date = new Date(Date.parse(date));
|
241
|
+
}
|
242
|
+
if (!Datepicker._isDate(date)) {
|
243
|
+
return;
|
244
|
+
}
|
245
|
+
|
246
|
+
var min = this.options.minDate,
|
247
|
+
max = this.options.maxDate;
|
248
|
+
|
249
|
+
if (Datepicker._isDate(min) && date < min) {
|
250
|
+
date = min;
|
251
|
+
} else if (Datepicker._isDate(max) && date > max) {
|
252
|
+
date = max;
|
253
|
+
}
|
254
|
+
|
255
|
+
this.date = new Date(date.getTime());
|
256
|
+
|
257
|
+
this._renderDateDisplay();
|
258
|
+
|
259
|
+
Datepicker._setToStartOfDay(this.date);
|
260
|
+
this.gotoDate(this.date);
|
261
|
+
|
262
|
+
if (!preventOnSelect && typeof this.options.onSelect === 'function') {
|
263
|
+
this.options.onSelect.call(this, this.date);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}, {
|
267
|
+
key: 'setInputValue',
|
268
|
+
value: function setInputValue() {
|
269
|
+
this.el.value = this.toString();
|
270
|
+
this.$el.trigger('change', { firedBy: this });
|
271
|
+
}
|
272
|
+
}, {
|
273
|
+
key: '_renderDateDisplay',
|
274
|
+
value: function _renderDateDisplay() {
|
275
|
+
var displayDate = Datepicker._isDate(this.date) ? this.date : new Date();
|
276
|
+
var i18n = this.options.i18n;
|
277
|
+
var day = i18n.weekdaysShort[displayDate.getDay()];
|
278
|
+
var month = i18n.monthsShort[displayDate.getMonth()];
|
279
|
+
var date = displayDate.getDate();
|
280
|
+
this.yearTextEl.innerHTML = displayDate.getFullYear();
|
281
|
+
this.dateTextEl.innerHTML = day + ', ' + month + ' ' + date;
|
282
|
+
}
|
283
|
+
|
284
|
+
/**
|
285
|
+
* change view to a specific date
|
286
|
+
*/
|
287
|
+
|
288
|
+
}, {
|
289
|
+
key: 'gotoDate',
|
290
|
+
value: function gotoDate(date) {
|
291
|
+
var newCalendar = true;
|
292
|
+
|
293
|
+
if (!Datepicker._isDate(date)) {
|
294
|
+
return;
|
295
|
+
}
|
296
|
+
|
297
|
+
if (this.calendars) {
|
298
|
+
var firstVisibleDate = new Date(this.calendars[0].year, this.calendars[0].month, 1),
|
299
|
+
lastVisibleDate = new Date(this.calendars[this.calendars.length - 1].year, this.calendars[this.calendars.length - 1].month, 1),
|
300
|
+
visibleDate = date.getTime();
|
301
|
+
// get the end of the month
|
302
|
+
lastVisibleDate.setMonth(lastVisibleDate.getMonth() + 1);
|
303
|
+
lastVisibleDate.setDate(lastVisibleDate.getDate() - 1);
|
304
|
+
newCalendar = visibleDate < firstVisibleDate.getTime() || lastVisibleDate.getTime() < visibleDate;
|
305
|
+
}
|
306
|
+
|
307
|
+
if (newCalendar) {
|
308
|
+
this.calendars = [{
|
309
|
+
month: date.getMonth(),
|
310
|
+
year: date.getFullYear()
|
311
|
+
}];
|
312
|
+
}
|
313
|
+
|
314
|
+
this.adjustCalendars();
|
315
|
+
}
|
316
|
+
}, {
|
317
|
+
key: 'adjustCalendars',
|
318
|
+
value: function adjustCalendars() {
|
319
|
+
this.calendars[0] = this.adjustCalendar(this.calendars[0]);
|
320
|
+
this.draw();
|
321
|
+
}
|
322
|
+
}, {
|
323
|
+
key: 'adjustCalendar',
|
324
|
+
value: function adjustCalendar(calendar) {
|
325
|
+
if (calendar.month < 0) {
|
326
|
+
calendar.year -= Math.ceil(Math.abs(calendar.month) / 12);
|
327
|
+
calendar.month += 12;
|
328
|
+
}
|
329
|
+
if (calendar.month > 11) {
|
330
|
+
calendar.year += Math.floor(Math.abs(calendar.month) / 12);
|
331
|
+
calendar.month -= 12;
|
332
|
+
}
|
333
|
+
return calendar;
|
334
|
+
}
|
335
|
+
}, {
|
336
|
+
key: 'nextMonth',
|
337
|
+
value: function nextMonth() {
|
338
|
+
this.calendars[0].month++;
|
339
|
+
this.adjustCalendars();
|
340
|
+
}
|
341
|
+
}, {
|
342
|
+
key: 'prevMonth',
|
343
|
+
value: function prevMonth() {
|
344
|
+
this.calendars[0].month--;
|
345
|
+
this.adjustCalendars();
|
346
|
+
}
|
347
|
+
}, {
|
348
|
+
key: 'render',
|
349
|
+
value: function render(year, month, randId) {
|
350
|
+
var opts = this.options,
|
351
|
+
now = new Date(),
|
352
|
+
days = Datepicker._getDaysInMonth(year, month),
|
353
|
+
before = new Date(year, month, 1).getDay(),
|
354
|
+
data = [],
|
355
|
+
row = [];
|
356
|
+
Datepicker._setToStartOfDay(now);
|
357
|
+
if (opts.firstDay > 0) {
|
358
|
+
before -= opts.firstDay;
|
359
|
+
if (before < 0) {
|
360
|
+
before += 7;
|
361
|
+
}
|
362
|
+
}
|
363
|
+
var previousMonth = month === 0 ? 11 : month - 1,
|
364
|
+
nextMonth = month === 11 ? 0 : month + 1,
|
365
|
+
yearOfPreviousMonth = month === 0 ? year - 1 : year,
|
366
|
+
yearOfNextMonth = month === 11 ? year + 1 : year,
|
367
|
+
daysInPreviousMonth = Datepicker._getDaysInMonth(yearOfPreviousMonth, previousMonth);
|
368
|
+
var cells = days + before,
|
369
|
+
after = cells;
|
370
|
+
while (after > 7) {
|
371
|
+
after -= 7;
|
372
|
+
}
|
373
|
+
cells += 7 - after;
|
374
|
+
var isWeekSelected = false;
|
375
|
+
for (var i = 0, r = 0; i < cells; i++) {
|
376
|
+
var day = new Date(year, month, 1 + (i - before)),
|
377
|
+
isSelected = Datepicker._isDate(this.date) ? Datepicker._compareDates(day, this.date) : false,
|
378
|
+
isToday = Datepicker._compareDates(day, now),
|
379
|
+
hasEvent = opts.events.indexOf(day.toDateString()) !== -1 ? true : false,
|
380
|
+
isEmpty = i < before || i >= days + before,
|
381
|
+
dayNumber = 1 + (i - before),
|
382
|
+
monthNumber = month,
|
383
|
+
yearNumber = year,
|
384
|
+
isStartRange = opts.startRange && Datepicker._compareDates(opts.startRange, day),
|
385
|
+
isEndRange = opts.endRange && Datepicker._compareDates(opts.endRange, day),
|
386
|
+
isInRange = opts.startRange && opts.endRange && opts.startRange < day && day < opts.endRange,
|
387
|
+
isDisabled = opts.minDate && day < opts.minDate || opts.maxDate && day > opts.maxDate || opts.disableWeekends && Datepicker._isWeekend(day) || opts.disableDayFn && opts.disableDayFn(day);
|
388
|
+
|
389
|
+
if (isEmpty) {
|
390
|
+
if (i < before) {
|
391
|
+
dayNumber = daysInPreviousMonth + dayNumber;
|
392
|
+
monthNumber = previousMonth;
|
393
|
+
yearNumber = yearOfPreviousMonth;
|
394
|
+
} else {
|
395
|
+
dayNumber = dayNumber - days;
|
396
|
+
monthNumber = nextMonth;
|
397
|
+
yearNumber = yearOfNextMonth;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
var dayConfig = {
|
402
|
+
day: dayNumber,
|
403
|
+
month: monthNumber,
|
404
|
+
year: yearNumber,
|
405
|
+
hasEvent: hasEvent,
|
406
|
+
isSelected: isSelected,
|
407
|
+
isToday: isToday,
|
408
|
+
isDisabled: isDisabled,
|
409
|
+
isEmpty: isEmpty,
|
410
|
+
isStartRange: isStartRange,
|
411
|
+
isEndRange: isEndRange,
|
412
|
+
isInRange: isInRange,
|
413
|
+
showDaysInNextAndPreviousMonths: opts.showDaysInNextAndPreviousMonths
|
414
|
+
};
|
415
|
+
|
416
|
+
row.push(this.renderDay(dayConfig));
|
417
|
+
|
418
|
+
if (++r === 7) {
|
419
|
+
data.push(this.renderRow(row, opts.isRTL, isWeekSelected));
|
420
|
+
row = [];
|
421
|
+
r = 0;
|
422
|
+
isWeekSelected = false;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
return this.renderTable(opts, data, randId);
|
426
|
+
}
|
427
|
+
}, {
|
428
|
+
key: 'renderDay',
|
429
|
+
value: function renderDay(opts) {
|
430
|
+
var arr = [];
|
431
|
+
var ariaSelected = 'false';
|
432
|
+
if (opts.isEmpty) {
|
433
|
+
if (opts.showDaysInNextAndPreviousMonths) {
|
434
|
+
arr.push('is-outside-current-month');
|
435
|
+
arr.push('is-selection-disabled');
|
436
|
+
} else {
|
437
|
+
return '<td class="is-empty"></td>';
|
438
|
+
}
|
439
|
+
}
|
440
|
+
if (opts.isDisabled) {
|
441
|
+
arr.push('is-disabled');
|
442
|
+
}
|
443
|
+
|
444
|
+
if (opts.isToday) {
|
445
|
+
arr.push('is-today');
|
446
|
+
}
|
447
|
+
if (opts.isSelected) {
|
448
|
+
arr.push('is-selected');
|
449
|
+
ariaSelected = 'true';
|
450
|
+
}
|
451
|
+
if (opts.hasEvent) {
|
452
|
+
arr.push('has-event');
|
453
|
+
}
|
454
|
+
if (opts.isInRange) {
|
455
|
+
arr.push('is-inrange');
|
456
|
+
}
|
457
|
+
if (opts.isStartRange) {
|
458
|
+
arr.push('is-startrange');
|
459
|
+
}
|
460
|
+
if (opts.isEndRange) {
|
461
|
+
arr.push('is-endrange');
|
462
|
+
}
|
463
|
+
return '<td data-day="' + opts.day + '" class="' + arr.join(' ') + '" aria-selected="' + ariaSelected + '">' + ('<button class="datepicker-day-button" type="button" data-year="' + opts.year + '" data-month="' + opts.month + '" data-day="' + opts.day + '">' + opts.day + '</button>') + '</td>';
|
464
|
+
}
|
465
|
+
}, {
|
466
|
+
key: 'renderRow',
|
467
|
+
value: function renderRow(days, isRTL, isRowSelected) {
|
468
|
+
return '<tr class="datepicker-row' + (isRowSelected ? ' is-selected' : '') + '">' + (isRTL ? days.reverse() : days).join('') + '</tr>';
|
469
|
+
}
|
470
|
+
}, {
|
471
|
+
key: 'renderTable',
|
472
|
+
value: function renderTable(opts, data, randId) {
|
473
|
+
return '<div class="datepicker-table-wrapper"><table cellpadding="0" cellspacing="0" class="datepicker-table" role="grid" aria-labelledby="' + randId + '">' + this.renderHead(opts) + this.renderBody(data) + '</table></div>';
|
474
|
+
}
|
475
|
+
}, {
|
476
|
+
key: 'renderHead',
|
477
|
+
value: function renderHead(opts) {
|
478
|
+
var i = void 0,
|
479
|
+
arr = [];
|
480
|
+
for (i = 0; i < 7; i++) {
|
481
|
+
arr.push('<th scope="col"><abbr title="' + this.renderDayName(opts, i) + '">' + this.renderDayName(opts, i, true) + '</abbr></th>');
|
482
|
+
}
|
483
|
+
return '<thead><tr>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</tr></thead>';
|
484
|
+
}
|
485
|
+
}, {
|
486
|
+
key: 'renderBody',
|
487
|
+
value: function renderBody(rows) {
|
488
|
+
return '<tbody>' + rows.join('') + '</tbody>';
|
489
|
+
}
|
490
|
+
}, {
|
491
|
+
key: 'renderTitle',
|
492
|
+
value: function renderTitle(instance, c, year, month, refYear, randId) {
|
493
|
+
var i = void 0,
|
494
|
+
j = void 0,
|
495
|
+
arr = void 0,
|
496
|
+
opts = this.options,
|
497
|
+
isMinYear = year === opts.minYear,
|
498
|
+
isMaxYear = year === opts.maxYear,
|
499
|
+
html = '<div id="' + randId + '" class="datepicker-controls" role="heading" aria-live="assertive">',
|
500
|
+
monthHtml = void 0,
|
501
|
+
yearHtml = void 0,
|
502
|
+
prev = true,
|
503
|
+
next = true;
|
504
|
+
|
505
|
+
for (arr = [], i = 0; i < 12; i++) {
|
506
|
+
arr.push('<option value="' + (year === refYear ? i - c : 12 + i - c) + '"' + (i === month ? ' selected="selected"' : '') + (isMinYear && i < opts.minMonth || isMaxYear && i > opts.maxMonth ? 'disabled="disabled"' : '') + '>' + opts.i18n.months[i] + '</option>');
|
507
|
+
}
|
508
|
+
|
509
|
+
monthHtml = '<select class="datepicker-select orig-select-month" tabindex="-1">' + arr.join('') + '</select>';
|
510
|
+
|
511
|
+
if ($.isArray(opts.yearRange)) {
|
512
|
+
i = opts.yearRange[0];
|
513
|
+
j = opts.yearRange[1] + 1;
|
514
|
+
} else {
|
515
|
+
i = year - opts.yearRange;
|
516
|
+
j = 1 + year + opts.yearRange;
|
517
|
+
}
|
518
|
+
|
519
|
+
for (arr = []; i < j && i <= opts.maxYear; i++) {
|
520
|
+
if (i >= opts.minYear) {
|
521
|
+
arr.push('<option value="' + i + '" ' + (i === year ? 'selected="selected"' : '') + '>' + i + '</option>');
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
yearHtml = '<select class="datepicker-select orig-select-year" tabindex="-1">' + arr.join('') + '</select>';
|
526
|
+
|
527
|
+
var leftArrow = '<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/><path d="M0-.5h24v24H0z" fill="none"/></svg>';
|
528
|
+
html += '<button class="month-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + leftArrow + '</button>';
|
529
|
+
|
530
|
+
html += '<div class="selects-container">';
|
531
|
+
if (opts.showMonthAfterYear) {
|
532
|
+
html += yearHtml + monthHtml;
|
533
|
+
} else {
|
534
|
+
html += monthHtml + yearHtml;
|
535
|
+
}
|
536
|
+
html += '</div>';
|
537
|
+
|
538
|
+
if (isMinYear && (month === 0 || opts.minMonth >= month)) {
|
539
|
+
prev = false;
|
540
|
+
}
|
541
|
+
|
542
|
+
if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
|
543
|
+
next = false;
|
544
|
+
}
|
545
|
+
|
546
|
+
var rightArrow = '<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/><path d="M0-.25h24v24H0z" fill="none"/></svg>';
|
547
|
+
html += '<button class="month-next' + (next ? '' : ' is-disabled') + '" type="button">' + rightArrow + '</button>';
|
548
|
+
|
549
|
+
return html += '</div>';
|
550
|
+
}
|
551
|
+
|
552
|
+
/**
|
553
|
+
* refresh the HTML
|
554
|
+
*/
|
555
|
+
|
556
|
+
}, {
|
557
|
+
key: 'draw',
|
558
|
+
value: function draw(force) {
|
559
|
+
if (!this.isOpen && !force) {
|
560
|
+
return;
|
561
|
+
}
|
562
|
+
var opts = this.options,
|
563
|
+
minYear = opts.minYear,
|
564
|
+
maxYear = opts.maxYear,
|
565
|
+
minMonth = opts.minMonth,
|
566
|
+
maxMonth = opts.maxMonth,
|
567
|
+
html = '',
|
568
|
+
randId = void 0;
|
569
|
+
|
570
|
+
if (this._y <= minYear) {
|
571
|
+
this._y = minYear;
|
572
|
+
if (!isNaN(minMonth) && this._m < minMonth) {
|
573
|
+
this._m = minMonth;
|
574
|
+
}
|
575
|
+
}
|
576
|
+
if (this._y >= maxYear) {
|
577
|
+
this._y = maxYear;
|
578
|
+
if (!isNaN(maxMonth) && this._m > maxMonth) {
|
579
|
+
this._m = maxMonth;
|
580
|
+
}
|
581
|
+
}
|
582
|
+
|
583
|
+
randId = 'datepicker-title-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 2);
|
584
|
+
|
585
|
+
for (var c = 0; c < 1; c++) {
|
586
|
+
this._renderDateDisplay();
|
587
|
+
html += this.renderTitle(this, c, this.calendars[c].year, this.calendars[c].month, this.calendars[0].year, randId) + this.render(this.calendars[c].year, this.calendars[c].month, randId);
|
588
|
+
}
|
589
|
+
|
590
|
+
this.destroySelects();
|
591
|
+
|
592
|
+
this.calendarEl.innerHTML = html;
|
593
|
+
|
594
|
+
// Init Materialize Select
|
595
|
+
var yearSelect = this.calendarEl.querySelector('.orig-select-year');
|
596
|
+
var monthSelect = this.calendarEl.querySelector('.orig-select-month');
|
597
|
+
M.FormSelect.init(yearSelect, {
|
598
|
+
classes: 'select-year',
|
599
|
+
dropdownOptions: { container: document.body, constrainWidth: false }
|
600
|
+
});
|
601
|
+
M.FormSelect.init(monthSelect, {
|
602
|
+
classes: 'select-month',
|
603
|
+
dropdownOptions: { container: document.body, constrainWidth: false }
|
604
|
+
});
|
605
|
+
|
606
|
+
// Add change handlers for select
|
607
|
+
yearSelect.addEventListener('change', this._handleYearChange.bind(this));
|
608
|
+
monthSelect.addEventListener('change', this._handleMonthChange.bind(this));
|
609
|
+
|
610
|
+
if (typeof this.options.onDraw === 'function') {
|
611
|
+
this.options.onDraw(this);
|
612
|
+
}
|
613
|
+
}
|
614
|
+
|
615
|
+
/**
|
616
|
+
* Setup Event Handlers
|
617
|
+
*/
|
618
|
+
|
619
|
+
}, {
|
620
|
+
key: '_setupEventHandlers',
|
621
|
+
value: function _setupEventHandlers() {
|
622
|
+
this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
|
623
|
+
this._handleInputClickBound = this._handleInputClick.bind(this);
|
624
|
+
this._handleInputChangeBound = this._handleInputChange.bind(this);
|
625
|
+
this._handleCalendarClickBound = this._handleCalendarClick.bind(this);
|
626
|
+
this._finishSelectionBound = this._finishSelection.bind(this);
|
627
|
+
this._handleMonthChange = this._handleMonthChange.bind(this);
|
628
|
+
this._closeBound = this.close.bind(this);
|
629
|
+
|
630
|
+
this.el.addEventListener('click', this._handleInputClickBound);
|
631
|
+
this.el.addEventListener('keydown', this._handleInputKeydownBound);
|
632
|
+
this.el.addEventListener('change', this._handleInputChangeBound);
|
633
|
+
this.calendarEl.addEventListener('click', this._handleCalendarClickBound);
|
634
|
+
this.doneBtn.addEventListener('click', this._finishSelectionBound);
|
635
|
+
this.cancelBtn.addEventListener('click', this._closeBound);
|
636
|
+
|
637
|
+
if (this.options.showClearBtn) {
|
638
|
+
this._handleClearClickBound = this._handleClearClick.bind(this);
|
639
|
+
this.clearBtn.addEventListener('click', this._handleClearClickBound);
|
640
|
+
}
|
641
|
+
}
|
642
|
+
}, {
|
643
|
+
key: '_setupVariables',
|
644
|
+
value: function _setupVariables() {
|
645
|
+
var _this4 = this;
|
646
|
+
|
647
|
+
this.$modalEl = $(Datepicker._template);
|
648
|
+
this.modalEl = this.$modalEl[0];
|
649
|
+
|
650
|
+
this.calendarEl = this.modalEl.querySelector('.datepicker-calendar');
|
651
|
+
|
652
|
+
this.yearTextEl = this.modalEl.querySelector('.year-text');
|
653
|
+
this.dateTextEl = this.modalEl.querySelector('.date-text');
|
654
|
+
if (this.options.showClearBtn) {
|
655
|
+
this.clearBtn = this.modalEl.querySelector('.datepicker-clear');
|
656
|
+
}
|
657
|
+
this.doneBtn = this.modalEl.querySelector('.datepicker-done');
|
658
|
+
this.cancelBtn = this.modalEl.querySelector('.datepicker-cancel');
|
659
|
+
|
660
|
+
this.formats = {
|
661
|
+
d: function () {
|
662
|
+
return _this4.date.getDate();
|
663
|
+
},
|
664
|
+
dd: function () {
|
665
|
+
var d = _this4.date.getDate();
|
666
|
+
return (d < 10 ? '0' : '') + d;
|
667
|
+
},
|
668
|
+
ddd: function () {
|
669
|
+
return _this4.options.i18n.weekdaysShort[_this4.date.getDay()];
|
670
|
+
},
|
671
|
+
dddd: function () {
|
672
|
+
return _this4.options.i18n.weekdays[_this4.date.getDay()];
|
673
|
+
},
|
674
|
+
m: function () {
|
675
|
+
return _this4.date.getMonth() + 1;
|
676
|
+
},
|
677
|
+
mm: function () {
|
678
|
+
var m = _this4.date.getMonth() + 1;
|
679
|
+
return (m < 10 ? '0' : '') + m;
|
680
|
+
},
|
681
|
+
mmm: function () {
|
682
|
+
return _this4.options.i18n.monthsShort[_this4.date.getMonth()];
|
683
|
+
},
|
684
|
+
mmmm: function () {
|
685
|
+
return _this4.options.i18n.months[_this4.date.getMonth()];
|
686
|
+
},
|
687
|
+
yy: function () {
|
688
|
+
return ('' + _this4.date.getFullYear()).slice(2);
|
689
|
+
},
|
690
|
+
yyyy: function () {
|
691
|
+
return _this4.date.getFullYear();
|
692
|
+
}
|
693
|
+
};
|
694
|
+
}
|
695
|
+
|
696
|
+
/**
|
697
|
+
* Remove Event Handlers
|
698
|
+
*/
|
699
|
+
|
700
|
+
}, {
|
701
|
+
key: '_removeEventHandlers',
|
702
|
+
value: function _removeEventHandlers() {
|
703
|
+
this.el.removeEventListener('click', this._handleInputClickBound);
|
704
|
+
this.el.removeEventListener('keydown', this._handleInputKeydownBound);
|
705
|
+
this.el.removeEventListener('change', this._handleInputChangeBound);
|
706
|
+
this.calendarEl.removeEventListener('click', this._handleCalendarClickBound);
|
707
|
+
}
|
708
|
+
}, {
|
709
|
+
key: '_handleInputClick',
|
710
|
+
value: function _handleInputClick() {
|
711
|
+
this.open();
|
712
|
+
}
|
713
|
+
}, {
|
714
|
+
key: '_handleInputKeydown',
|
715
|
+
value: function _handleInputKeydown(e) {
|
716
|
+
if (e.which === M.keys.ENTER) {
|
717
|
+
e.preventDefault();
|
718
|
+
this.open();
|
719
|
+
}
|
720
|
+
}
|
721
|
+
}, {
|
722
|
+
key: '_handleCalendarClick',
|
723
|
+
value: function _handleCalendarClick(e) {
|
724
|
+
if (!this.isOpen) {
|
725
|
+
return;
|
726
|
+
}
|
727
|
+
|
728
|
+
var $target = $(e.target);
|
729
|
+
if (!$target.hasClass('is-disabled')) {
|
730
|
+
if ($target.hasClass('datepicker-day-button') && !$target.hasClass('is-empty') && !$target.parent().hasClass('is-disabled')) {
|
731
|
+
this.setDate(new Date(e.target.getAttribute('data-year'), e.target.getAttribute('data-month'), e.target.getAttribute('data-day')));
|
732
|
+
if (this.options.autoClose) {
|
733
|
+
this._finishSelection();
|
734
|
+
}
|
735
|
+
} else if ($target.closest('.month-prev').length) {
|
736
|
+
this.prevMonth();
|
737
|
+
} else if ($target.closest('.month-next').length) {
|
738
|
+
this.nextMonth();
|
739
|
+
}
|
740
|
+
}
|
741
|
+
}
|
742
|
+
}, {
|
743
|
+
key: '_handleClearClick',
|
744
|
+
value: function _handleClearClick() {
|
745
|
+
this.date = null;
|
746
|
+
this.setInputValue();
|
747
|
+
this.close();
|
748
|
+
}
|
749
|
+
}, {
|
750
|
+
key: '_handleMonthChange',
|
751
|
+
value: function _handleMonthChange(e) {
|
752
|
+
this.gotoMonth(e.target.value);
|
753
|
+
}
|
754
|
+
}, {
|
755
|
+
key: '_handleYearChange',
|
756
|
+
value: function _handleYearChange(e) {
|
757
|
+
this.gotoYear(e.target.value);
|
758
|
+
}
|
759
|
+
|
760
|
+
/**
|
761
|
+
* change view to a specific month (zero-index, e.g. 0: January)
|
762
|
+
*/
|
763
|
+
|
764
|
+
}, {
|
765
|
+
key: 'gotoMonth',
|
766
|
+
value: function gotoMonth(month) {
|
767
|
+
if (!isNaN(month)) {
|
768
|
+
this.calendars[0].month = parseInt(month, 10);
|
769
|
+
this.adjustCalendars();
|
770
|
+
}
|
771
|
+
}
|
772
|
+
|
773
|
+
/**
|
774
|
+
* change view to a specific full year (e.g. "2012")
|
775
|
+
*/
|
776
|
+
|
777
|
+
}, {
|
778
|
+
key: 'gotoYear',
|
779
|
+
value: function gotoYear(year) {
|
780
|
+
if (!isNaN(year)) {
|
781
|
+
this.calendars[0].year = parseInt(year, 10);
|
782
|
+
this.adjustCalendars();
|
783
|
+
}
|
784
|
+
}
|
785
|
+
}, {
|
786
|
+
key: '_handleInputChange',
|
787
|
+
value: function _handleInputChange(e) {
|
788
|
+
var date = void 0;
|
789
|
+
|
790
|
+
// Prevent change event from being fired when triggered by the plugin
|
791
|
+
if (e.firedBy === this) {
|
792
|
+
return;
|
793
|
+
}
|
794
|
+
if (this.options.parse) {
|
795
|
+
date = this.options.parse(this.el.value, this.options.format);
|
796
|
+
} else {
|
797
|
+
date = new Date(Date.parse(this.el.value));
|
798
|
+
}
|
799
|
+
|
800
|
+
if (Datepicker._isDate(date)) {
|
801
|
+
this.setDate(date);
|
802
|
+
}
|
803
|
+
}
|
804
|
+
}, {
|
805
|
+
key: 'renderDayName',
|
806
|
+
value: function renderDayName(opts, day, abbr) {
|
807
|
+
day += opts.firstDay;
|
808
|
+
while (day >= 7) {
|
809
|
+
day -= 7;
|
810
|
+
}
|
811
|
+
return abbr ? opts.i18n.weekdaysAbbrev[day] : opts.i18n.weekdays[day];
|
812
|
+
}
|
813
|
+
|
814
|
+
/**
|
815
|
+
* Set input value to the selected date and close Datepicker
|
816
|
+
*/
|
817
|
+
|
818
|
+
}, {
|
819
|
+
key: '_finishSelection',
|
820
|
+
value: function _finishSelection() {
|
821
|
+
this.setInputValue();
|
822
|
+
this.close();
|
823
|
+
}
|
824
|
+
|
825
|
+
/**
|
826
|
+
* Open Datepicker
|
827
|
+
*/
|
828
|
+
|
829
|
+
}, {
|
830
|
+
key: 'open',
|
831
|
+
value: function open() {
|
832
|
+
if (this.isOpen) {
|
833
|
+
return;
|
834
|
+
}
|
835
|
+
|
836
|
+
this.isOpen = true;
|
837
|
+
if (typeof this.options.onOpen === 'function') {
|
838
|
+
this.options.onOpen.call(this);
|
839
|
+
}
|
840
|
+
this.draw();
|
841
|
+
this.modal.open();
|
842
|
+
return this;
|
843
|
+
}
|
844
|
+
|
845
|
+
/**
|
846
|
+
* Close Datepicker
|
847
|
+
*/
|
848
|
+
|
849
|
+
}, {
|
850
|
+
key: 'close',
|
851
|
+
value: function close() {
|
852
|
+
if (!this.isOpen) {
|
853
|
+
return;
|
854
|
+
}
|
855
|
+
|
856
|
+
this.isOpen = false;
|
857
|
+
if (typeof this.options.onClose === 'function') {
|
858
|
+
this.options.onClose.call(this);
|
859
|
+
}
|
860
|
+
this.modal.close();
|
861
|
+
return this;
|
862
|
+
}
|
863
|
+
}], [{
|
864
|
+
key: 'init',
|
865
|
+
value: function init(els, options) {
|
866
|
+
return _get(Datepicker.__proto__ || Object.getPrototypeOf(Datepicker), 'init', this).call(this, this, els, options);
|
867
|
+
}
|
868
|
+
}, {
|
869
|
+
key: '_isDate',
|
870
|
+
value: function _isDate(obj) {
|
871
|
+
return (/Date/.test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime())
|
872
|
+
);
|
873
|
+
}
|
874
|
+
}, {
|
875
|
+
key: '_isWeekend',
|
876
|
+
value: function _isWeekend(date) {
|
877
|
+
var day = date.getDay();
|
878
|
+
return day === 0 || day === 6;
|
879
|
+
}
|
880
|
+
}, {
|
881
|
+
key: '_setToStartOfDay',
|
882
|
+
value: function _setToStartOfDay(date) {
|
883
|
+
if (Datepicker._isDate(date)) date.setHours(0, 0, 0, 0);
|
884
|
+
}
|
885
|
+
}, {
|
886
|
+
key: '_getDaysInMonth',
|
887
|
+
value: function _getDaysInMonth(year, month) {
|
888
|
+
return [31, Datepicker._isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
889
|
+
}
|
890
|
+
}, {
|
891
|
+
key: '_isLeapYear',
|
892
|
+
value: function _isLeapYear(year) {
|
893
|
+
// solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
|
894
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
895
|
+
}
|
896
|
+
}, {
|
897
|
+
key: '_compareDates',
|
898
|
+
value: function _compareDates(a, b) {
|
899
|
+
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
|
900
|
+
return a.getTime() === b.getTime();
|
901
|
+
}
|
902
|
+
}, {
|
903
|
+
key: '_setToStartOfDay',
|
904
|
+
value: function _setToStartOfDay(date) {
|
905
|
+
if (Datepicker._isDate(date)) date.setHours(0, 0, 0, 0);
|
906
|
+
}
|
907
|
+
|
908
|
+
/**
|
909
|
+
* Get Instance
|
910
|
+
*/
|
911
|
+
|
912
|
+
}, {
|
913
|
+
key: 'getInstance',
|
914
|
+
value: function getInstance(el) {
|
915
|
+
var domElem = !!el.jquery ? el[0] : el;
|
916
|
+
return domElem.M_Datepicker;
|
917
|
+
}
|
918
|
+
}, {
|
919
|
+
key: 'defaults',
|
920
|
+
get: function () {
|
921
|
+
return _defaults;
|
922
|
+
}
|
923
|
+
}]);
|
924
|
+
|
925
|
+
return Datepicker;
|
926
|
+
}(Component);
|
927
|
+
|
928
|
+
Datepicker._template = ['<div class= "modal datepicker-modal">', '<div class="modal-content datepicker-container">', '<div class="datepicker-date-display">', '<span class="year-text"></span>', '<span class="date-text"></span>', '</div>', '<div class="datepicker-calendar-container">', '<div class="datepicker-calendar"></div>', '<div class="datepicker-footer">', '<button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>', '<div class="confirmation-btns">', '<button class="btn-flat datepicker-cancel waves-effect" type="button"></button>', '<button class="btn-flat datepicker-done waves-effect" type="button"></button>', '</div>', '</div>', '</div>', '</div>', '</div>'].join('');
|
929
|
+
|
930
|
+
M.Datepicker = Datepicker;
|
931
|
+
|
932
|
+
if (M.jQueryLoaded) {
|
933
|
+
M.initializeJqueryWrapper(Datepicker, 'datepicker', 'M_Datepicker');
|
934
|
+
}
|
935
|
+
})(cash);
|