romo 0.19.10 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,280 +1,195 @@
1
- $.fn.romoDatepicker = function() {
2
- return $.map(this, function(element) {
3
- return new RomoDatepicker(element);
4
- });
5
- }
6
-
7
- var RomoDatepicker = function(element) {
8
- this.elem = $(element);
1
+ var RomoDatepicker = RomoComponent(function(elem) {
2
+ this.elem = elem;
9
3
 
10
4
  this.defaultFormat = 'yyyy-mm-dd'
11
5
  this.defaultPrevClass = undefined;
12
6
  this.defaultNextClass = undefined;
13
7
  this.itemSelector = 'TD.romo-datepicker-day:not(.disabled)';
14
- this.calTable = $();
8
+ this.calTable = undefined;
15
9
  this.date = undefined;
16
10
  this.today = RomoDate.today();
17
11
  this.prevValue = undefined;
18
12
 
19
13
  this.doInit();
20
- this.doBindElem();
21
- this.doSetFormat();
22
- this.doSetDate(this.elem.val());
23
- this.doBindDropdown();
24
- this.doBuildUI();
14
+ this._bindElem();
25
15
 
26
- this.elem.trigger('datepicker:ready', [this]);
16
+ Romo.trigger(this.elem, 'romoDatepicker:ready', [this]);
17
+ });
18
+
19
+ RomoDatepicker.prototype.formatString = function() {
20
+ return Romo.data(this.elem, 'romo-datepicker-format') || this.defaultFormat;
27
21
  }
28
22
 
29
- RomoDatepicker.prototype.doInit = function() {
30
- // override as needed
23
+ RomoDatepicker.prototype.doSetDate = function(value) {
24
+ this.date = RomoDate.parse(value);
25
+ if (this.date !== undefined) {
26
+ this.elem.value = RomoDate.format(this.date, this.formatString());
27
+ } else {
28
+ this.elem.value = value;
29
+ }
31
30
  }
32
31
 
33
- RomoDatepicker.prototype.doBindElem = function() {
34
- this.elem.attr('autocomplete', 'off');
35
- this.elem.attr('data-romo-indicator-text-input-indicator-position', "right");
32
+ RomoDatepicker.prototype.doRefreshUI = function(date) {
33
+ var rDate = date || this.date || this.today;
34
+ this._refreshCalendar(rDate);
35
+ Romo.trigger(this.elem, 'romoDatepicker:refresh', [rDate, this]);
36
+
37
+ var itemElems = Romo.find(this.calTable, this.itemSelector);
38
+ Romo.on(itemElems, 'mouseenter', Romo.proxy(this._onItemEnter, this));
39
+ Romo.on(itemElems, 'click', Romo.proxy(this._onItemClick, this));
40
+
41
+ Romo.on(this.romoDropdown.popupElem, 'mousedown', Romo.proxy(this._onPopupMouseDown, this));
42
+ Romo.on(this.romoDropdown.popupElem, 'mouseup', Romo.proxy(this._onPopupMouseUp, this));
43
+ }
44
+
45
+ // private
46
+
47
+ RomoDatepicker.prototype._bindElem = function() {
48
+ Romo.setAttr(this.elem, 'autocomplete', 'off');
49
+ Romo.setData(this.elem, 'romo-indicator-text-input-indicator-position', "right");
36
50
 
37
- if (this.elem.data('romo-datepicker-indicator') !== undefined) {
38
- this.elem.attr('data-romo-indicator-text-input-indicator', this.elem.data('romo-datepicker-indicator'));
51
+ if (Romo.data(this.elem, 'romo-datepicker-indicator') !== undefined) {
52
+ Romo.setData(this.elem, 'romo-indicator-text-input-indicator', Romo.data(this.elem, 'romo-datepicker-indicator'));
39
53
  }
40
- if (this.elem.data('romo-datepicker-indicator-width-px') !== undefined) {
41
- this.elem.attr('data-romo-indicator-text-input-indicator-width-px', this.elem.data('romo-datepicker-indicator-width-px'));
54
+ if (Romo.data(this.elem, 'romo-datepicker-indicator-width-px') !== undefined) {
55
+ Romo.setData(this.elem, 'romo-indicator-text-input-indicator-width-px', Romo.data(this.elem, 'romo-datepicker-indicator-width-px'));
42
56
  }
43
- if (this.elem.data('romo-datepicker-btn-group') === true) {
44
- this.elem.attr('data-romo-indicator-text-input-btn-group', this.elem.data('romo-datepicker-btn-group'));
57
+ if (Romo.data(this.elem, 'romo-datepicker-btn-group') === true) {
58
+ Romo.setData(this.elem, 'romo-indicator-text-input-btn-group', Romo.data(this.elem, 'romo-datepicker-btn-group'));
45
59
  }
46
- if (this.elem.data('romo-datepicker-elem-display') !== undefined) {
47
- this.elem.attr('data-romo-indicator-text-input-elem-display', this.elem.data('romo-datepicker-elem-display'));
60
+ if (Romo.data(this.elem, 'romo-datepicker-elem-display') !== undefined) {
61
+ Romo.setData(this.elem, 'romo-indicator-text-input-elem-display', Romo.data(this.elem, 'romo-datepicker-elem-display'));
48
62
  }
49
63
 
50
- this.elem.romoIndicatorTextInput();
64
+ new RomoIndicatorTextInput(this.elem);
51
65
 
52
- this.prevValue = this.elem.val();
53
- this.elem.on('change', $.proxy(function(e) {
54
- var newValue = this.elem.val();
55
- this.elem.trigger('datepicker:change', [newValue, this.prevValue, this]);
66
+ this.prevValue = this.elem.value;
67
+ Romo.on(this.elem, 'change', Romo.proxy(function(e) {
68
+ var newValue = this.elem.value;
69
+ Romo.trigger(this.elem, 'romoDatepicker:change', [newValue, this.prevValue, this]);
56
70
  this.prevValue = newValue;
57
71
  }, this));
58
72
 
59
- this.elem.on('indicatorTextInput:indicatorClick', $.proxy(function(e) {
73
+ Romo.on(this.elem, 'romoIndicatorTextInput:indicatorClick', Romo.proxy(function(e) {
60
74
  this._clearBlurTimeout();
61
- this.elem.trigger('datepicker:triggerPopupOpen');
75
+ Romo.trigger(this.elem, 'romoDatepicker:triggerPopupOpen');
62
76
  }, this));
63
77
 
64
- this.elem.on('datepicker:triggerEnable', $.proxy(function(e) {
65
- this.elem.trigger('indicatorTextInput:triggerEnable', []);
78
+ Romo.on(this.elem, 'romoDatepicker:triggerEnable', Romo.proxy(function(e) {
79
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerEnable', []);
66
80
  }, this));
67
- this.elem.on('datepicker:triggerDisable', $.proxy(function(e) {
68
- this.elem.trigger('indicatorTextInput:triggerDisable', []);
81
+ Romo.on(this.elem, 'romoDatepicker:triggerDisable', Romo.proxy(function(e) {
82
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerDisable', []);
69
83
  }, this));
70
- this.elem.on('datepicker:triggerShow', $.proxy(function(e) {
71
- this.elem.trigger('indicatorTextInput:triggerShow', []);
84
+ Romo.on(this.elem, 'romoDatepicker:triggerShow', Romo.proxy(function(e) {
85
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerShow', []);
72
86
  }, this));
73
- this.elem.on('datepicker:triggerHide', $.proxy(function(e) {
74
- this.elem.trigger('indicatorTextInput:triggerHide', []);
87
+ Romo.on(this.elem, 'romoDatepicker:triggerHide', Romo.proxy(function(e) {
88
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerHide', []);
75
89
  }, this));
76
90
 
77
- this.elem.on('datepicker:triggerSetFormat', $.proxy(function(e) {
78
- this.doSetFormat();
79
- }, this));
80
- this.elem.on('datepicker:triggerSetDate', $.proxy(this.onTriggerSetDate, this));
81
- }
91
+ Romo.on(this.elem, 'romoDatepicker:triggerSetDate', Romo.proxy(this._onTriggerSetDate, this));
82
92
 
83
- RomoDatepicker.prototype.doSetFormat = function() {
84
- this.formatString = this.elem.data('romo-datepicker-format') || this.defaultFormat;
93
+ this._bindDropdown();
94
+ this.doSetDate(this.elem.value);
95
+ this._buildUI();
85
96
  }
86
97
 
87
- RomoDatepicker.prototype.doSetDate = function(value) {
88
- this.date = RomoDate.parse(value);
89
- if (this.date !== undefined) {
90
- this.elem.val(RomoDate.format(this.date, this.formatString));
91
- } else {
92
- this.elem.val(value);
98
+ RomoDatepicker.prototype._bindDropdown = function() {
99
+ Romo.setData(this.elem, 'romo-dropdown-disable-toggle', 'true');
100
+ if (Romo.data(this.elem, 'romo-dropdown-width') === undefined) {
101
+ Romo.setData(this.elem, 'romo-dropdown-width', 'elem');
93
102
  }
94
- }
95
-
96
- RomoDatepicker.prototype.doBindDropdown = function() {
97
- this.elem.attr('data-romo-dropdown-disable-toggle', 'true');
98
- if (this.elem.data('romo-dropdown-width') === undefined) {
99
- this.elem.attr('data-romo-dropdown-width', 'elem');
103
+ if (parseInt(Romo.css(this.elem, 'width'), 10) < 175) {
104
+ Romo.setData(this.elem, 'romo-dropdown-width', '175px');
100
105
  }
101
- if (this.elem.width() < 175) {
102
- this.elem.attr('data-romo-dropdown-width', '175px');
103
- }
104
- this.romoDropdown = this.elem.romoDropdown()[0];
106
+ this.romoDropdown = new RomoDropdown(this.elem);
105
107
 
106
108
  this.romoDropdown.doSetPopupZIndex(this.elem);
107
- this.romoDropdown.bodyElem.addClass('romo-datepicker-calendar');
108
- this.romoDropdown.elem.on('dropdown:popupOpen', $.proxy(this.onPopupOpen, this));
109
- this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(this.onPopupClose, this));
110
- this.romoDropdown.elem.on('blur', $.proxy(function(e) {
111
- this.blurTimeoutId = setTimeout($.proxy(function() {
109
+ Romo.addClass(this.romoDropdown.bodyElem, 'romo-datepicker-calendar');
110
+ Romo.on(this.romoDropdown.elem, 'romoDropdown:popupOpen', Romo.proxy(this._onPopupOpen, this));
111
+ Romo.on(this.romoDropdown.elem, 'romoDropdown:popupClose', Romo.proxy(this._onPopupClose, this));
112
+ Romo.on(this.romoDropdown.elem, 'blur', Romo.proxy(function(e) {
113
+ this.blurTimeoutId = setTimeout(Romo.proxy(function() {
112
114
  if (this.popupMouseDown !== true) {
113
- this.romoDropdown.elem.trigger('dropdown:triggerPopupClose', []);
115
+ Romo.trigger(this.romoDropdown.elem, 'romoDropdown:triggerPopupClose', []);
114
116
  }
115
117
  }, this), 10);
116
118
  }, this));
117
- this.romoDropdown.elem.on('keydown', $.proxy(this.onElemKeyDown, this));
119
+ Romo.on(this.romoDropdown.elem, 'keydown', Romo.proxy(this._onElemKeyDown, this));
118
120
 
119
- this.romoDropdown.elem.on('dropdown:toggle', $.proxy(function(e, dropdown) {
120
- this.elem.trigger('datepicker:dropdown:toggle', [dropdown, this]);
121
+ Romo.on(this.romoDropdown.elem, 'romoDropdown:toggle', Romo.proxy(function(e, romoDropdown) {
122
+ Romo.trigger(this.elem, 'romoDatepicker:romoDropdown:toggle', [romoDropdown, this]);
121
123
  }, this));
122
- this.romoDropdown.elem.on('dropdown:popupOpen', $.proxy(function(e, dropdown) {
123
- this.elem.trigger('datepicker:dropdown:popupOpen', [dropdown, this]);
124
+ Romo.on(this.romoDropdown.elem, 'romoDropdown:popupOpen', Romo.proxy(function(e, romoDropdown) {
125
+ Romo.trigger(this.elem, 'romoDatepicker:romoDropdown:popupOpen', [romoDropdown, this]);
124
126
  }, this));
125
- this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(function(e, dropdown) {
126
- this.elem.trigger('datepicker:dropdown:popupClose', [dropdown, this]);
127
+ Romo.on(this.romoDropdown.elem, 'romoDropdown:popupClose', Romo.proxy(function(e, romoDropdown) {
128
+ Romo.trigger(this.elem, 'romoDatepicker:romoDropdown:popupClose', [romoDropdown, this]);
127
129
  }, this));
128
130
 
129
- this.elem.on('datepicker:triggerToggle', $.proxy(function(e) {
130
- this.romoDropdown.elem.trigger('dropdown:triggerToggle', []);
131
+ Romo.on(this.elem, 'romoDatepicker:triggerToggle', Romo.proxy(function(e) {
132
+ Romo.trigger(this.romoDropdown.elem, 'romoDropdown:triggerToggle', []);
131
133
  }, this));
132
- this.elem.on('datepicker:triggerPopupOpen', $.proxy(function(e) {
133
- this.romoDropdown.elem.trigger('dropdown:triggerPopupOpen', []);
134
+ Romo.on(this.elem, 'romoDatepicker:triggerPopupOpen', Romo.proxy(function(e) {
135
+ Romo.trigger(this.romoDropdown.elem, 'romoDropdown:triggerPopupOpen', []);
134
136
  }, this));
135
- this.elem.on('datepicker:triggerPopupClose', $.proxy(function(e) {
136
- this.romoDropdown.elem.trigger('dropdown:triggerPopupClose', []);
137
+ Romo.on(this.elem, 'romoDatepicker:triggerPopupClose', Romo.proxy(function(e) {
138
+ Romo.trigger(this.romoDropdown.elem, 'romoDropdown:triggerPopupClose', []);
137
139
  }, this));
138
140
  }
139
141
 
140
- RomoDatepicker.prototype.doBuildUI = function() {
142
+ RomoDatepicker.prototype._buildUI = function() {
141
143
  this.calTable = this._buildCalendar();
142
- this.romoDropdown.bodyElem.html('');
143
- this.romoDropdown.bodyElem.append(this.calTable);
144
-
145
- this.calTable.find('.romo-datepicker-prev').on('click', $.proxy(this.onPrevClick, this));
146
- this.calTable.find('.romo-datepicker-next').on('click', $.proxy(this.onNextClick, this));
147
- }
148
-
149
- RomoDatepicker.prototype.doRefreshUI = function(date) {
150
- var rDate = date || this.date || this.today;
151
- this._refreshCalendar(rDate);
152
- this.elem.trigger('datepicker:refresh', [rDate, this]);
153
-
154
- this.calTable.find(this.itemSelector).on('mouseenter', $.proxy(this.onItemEnter, this));
155
- this.calTable.find(this.itemSelector).on('click', $.proxy(this.onItemClick, this));
144
+ Romo.updateHtml(this.romoDropdown.bodyElem, '');
145
+ Romo.append(this.romoDropdown.bodyElem, this.calTable);
156
146
 
157
- this.romoDropdown.popupElem.on('mousedown', $.proxy(this.onPopupMouseDown, this));
158
- this.romoDropdown.popupElem.on('mouseup', $.proxy(this.onPopupMouseUp, this));
147
+ var prevElem = Romo.find(this.calTable, '.romo-datepicker-prev')[0];
148
+ Romo.on(prevElem, 'click', Romo.proxy(this._onPrevClick, this));
149
+ var nextElem = Romo.find(this.calTable, '.romo-datepicker-next')[0];
150
+ Romo.on(nextElem, 'click', Romo.proxy(this._onNextClick, this));
159
151
  }
160
152
 
161
- RomoDatepicker.prototype.doRefreshToPrevMonth = function() {
153
+ RomoDatepicker.prototype._refreshToPrevMonth = function() {
162
154
  var date = this.refreshDate || this.date || (new Date);
163
155
  var pDate = RomoDate.lastDateOfPrevMonth(date);
164
156
  this.doRefreshUI(pDate);
165
- this.elem.trigger('datepicker:prevRefresh', [pDate, this]);
157
+ Romo.trigger(this.elem, 'romoDatepicker:prevRefresh', [pDate, this]);
166
158
  }
167
159
 
168
- RomoDatepicker.prototype.doRefreshToNextMonth = function() {
160
+ RomoDatepicker.prototype._refreshToNextMonth = function() {
169
161
  var date = this.refreshDate || this.date || (new Date);
170
162
  var nDate = RomoDate.firstDateOfNextMonth(date);
171
163
  this.doRefreshUI(nDate);
172
- this.elem.trigger('datepicker:nextRefresh', [nDate, this]);
164
+ Romo.trigger(this.elem, 'romoDatepicker:nextRefresh', [nDate, this]);
173
165
  }
174
166
 
175
- RomoDatepicker.prototype.doSelectHighlightedItem = function() {
176
- var newValue = this.calTable.find('TD.romo-datepicker-highlight').data('romo-datepicker-value');
167
+ RomoDatepicker.prototype._selectHighlightedItem = function() {
168
+ var highlightElem = Romo.find(this.calTable, 'TD.romo-datepicker-highlight')[0];
169
+ var newValue = Romo.data(highlightElem, 'romo-datepicker-value');
177
170
 
178
171
  this.romoDropdown.doPopupClose();
179
172
  this.doSetDate(newValue);
180
173
  this.elem.focus();
181
- this.elem.trigger('datepicker:itemSelected', [newValue, this]);
174
+ Romo.trigger(this.elem, 'romoDatepicker:itemSelected', [newValue, this]);
182
175
  if (newValue !== this.prevValue) {
183
- this.elem.trigger('datepicker:newItemSelected', [newValue, this]);
176
+ Romo.trigger(this.elem, 'romoDatepicker:newItemSelected', [newValue, this]);
184
177
  }
185
178
  // always publish the item selected events before publishing any change events
186
179
  this._triggerSetDateChangeEvent();
187
180
  }
188
181
 
189
- RomoDatepicker.prototype.onTriggerSetDate = function(e, value) {
190
- this.doSetDate(value);
191
- this._triggerSetDateChangeEvent();
192
- }
193
-
194
- RomoDatepicker.prototype.onElemKeyDown = function(e) {
195
- if (this.elem.hasClass('disabled') === false) {
196
- if (this.romoDropdown.popupOpen()) {
197
- return true;
198
- } else {
199
- if(e.keyCode === 40 /* Down */ ) {
200
- this.romoDropdown.doPopupOpen();
201
- this.romoDropdown.popupElem.focus();
202
- return false;
203
- } else {
204
- return true;
205
- }
206
- }
207
- }
208
- return true;
209
- }
210
-
211
- RomoDatepicker.prototype.onPopupOpen = function(e) {
212
- if (this.elem.hasClass('disabled') === false) {
213
- this.doSetDate(this.elem.val());
214
- this.doRefreshUI();
215
- }
216
- }
217
-
218
- RomoDatepicker.prototype.onPopupClose = function(e) {
219
- this._highlightItem($());
220
- }
221
-
222
- RomoDatepicker.prototype.onItemEnter = function(e) {
223
- if (e !== undefined) {
224
- e.preventDefault();
225
- e.stopPropagation();
226
- }
227
- this._highlightItem($(e.target));
228
- }
229
-
230
- RomoDatepicker.prototype.onItemClick = function(e) {
231
- this._clearBlurTimeout();
232
- if (e !== undefined) {
233
- e.preventDefault();
234
- e.stopPropagation();
235
- }
236
- this.doSelectHighlightedItem();
237
- }
238
-
239
- RomoDatepicker.prototype.onPrevClick = function(e) {
240
- this._clearBlurTimeout();
241
- if (e !== undefined) {
242
- e.preventDefault();
243
- e.stopPropagation();
244
- }
245
- this.doRefreshToPrevMonth();
246
- }
247
-
248
- RomoDatepicker.prototype.onNextClick = function(e) {
249
- this._clearBlurTimeout();
250
- if (e !== undefined) {
251
- e.preventDefault();
252
- e.stopPropagation();
253
- }
254
- this.doRefreshToNextMonth();
255
- }
256
-
257
- RomoDatepicker.prototype.onPopupMouseDown = function(e) {
258
- this.popupMouseDown = true;
259
- }
260
-
261
- RomoDatepicker.prototype.onPopupMouseUp = function(e) {
262
- this.popupMouseDown = false;
263
- }
264
-
265
- // private
266
-
267
182
  RomoDatepicker.prototype._show = function(elem) {
268
- elem.css('display', '');
183
+ Romo.show(elem);
269
184
  }
270
185
 
271
186
  RomoDatepicker.prototype._hide = function(elem) {
272
- elem.css('display', 'none');
187
+ Romo.hide(elem);
273
188
  }
274
189
 
275
190
  RomoDatepicker.prototype._triggerSetDateChangeEvent = function() {
276
- if (this.elem.val() !== this.prevValue) {
277
- this.elem.trigger('change');
191
+ if (this.elem.value !== this.prevValue) {
192
+ Romo.trigger(this.elem, 'change');
278
193
  }
279
194
  }
280
195
 
@@ -286,59 +201,66 @@ RomoDatepicker.prototype._clearBlurTimeout = function() {
286
201
  }
287
202
 
288
203
  RomoDatepicker.prototype._refreshCalendar = function(date) {
289
- this.calTable.find('.romo-datepicker-title').html(this._buildCalendarTitle(date));
290
- this.calTable.find('tbody').empty().append(this._buildCalendarBody(date));
204
+ var titleElem = Romo.find(this.calTable, '.romo-datepicker-title')[0];
205
+ Romo.updateText(titleElem, this._buildCalendarTitle(date));
206
+
207
+ var tableBodyElem = Romo.find(this.calTable, 'tbody')[0];
208
+ Romo.updateHtml(tableBodyElem, '');
209
+ var rowElems = this._buildCalendarBodyRows(date);
210
+ Romo.append(tableBodyElem, rowElems);
211
+
291
212
  this.refreshDate = date;
292
213
  }
293
214
 
294
215
  RomoDatepicker.prototype._buildCalendar = function() {
295
- var table = $('<table></table>');
296
- table.append(this._buildCalendarHeader());
297
- table.append($('<tbody></tbody>'));
298
- return table;
216
+ var tableElem = Romo.elems('<table></table>')[0];
217
+ Romo.append(tableElem, this._buildCalendarHeader());
218
+ Romo.appendHtml(tableElem, '<tbody></tbody>');
219
+ return tableElem;
299
220
  }
300
221
 
301
222
  RomoDatepicker.prototype._buildCalendarHeader = function() {
302
- var prevClass = this.elem.data('romo-datepicker-prev') || this.defaultPrevClass;
303
- var nextClass = this.elem.data('romo-datepicker-next') || this.defaultNextClass;
304
- var header = $('<thead></thead');
305
-
306
- var row = $('<tr></tr>');
307
- var th = $('<th class="romo-datepicker-prev" title="Previous Month"></th>');
223
+ var prevClass = Romo.data(this.elem, 'romo-datepicker-prev') || this.defaultPrevClass;
224
+ var nextClass = Romo.data(this.elem, 'romo-datepicker-next') || this.defaultNextClass;
225
+ var headerElem = Romo.elems('<thead></thead')[0];
226
+ var titleRowElem = Romo.elems('<tr></tr>')[0];
227
+ var thPrevElem = Romo.elems('<th class="romo-datepicker-prev" title="Previous Month"></th>')[0];
308
228
  if (prevClass) {
309
- th.append('<i class="'+prevClass+'"></i>');
229
+ Romo.updateHtml(thPrevElem, '<i class="'+prevClass+'"></i>');
310
230
  } else {
311
- th.text('<<');
231
+ Romo.updateText(thPrevElem, '<<');
312
232
  }
313
- row.append(th);
314
- row.append($('<th class="romo-datepicker-title" colspan="5"></th>'));
315
- var th = $('<th class="romo-datepicker-next" title="Next Month"></th>');
233
+ Romo.append(titleRowElem, thPrevElem);
234
+
235
+ Romo.appendHtml(titleRowElem, '<th class="romo-datepicker-title" colspan="5"></th>');
236
+
237
+ var thNextElem = Romo.elems('<th class="romo-datepicker-next" title="Next Month"></th>')[0];
316
238
  if (nextClass) {
317
- th.append('<i class="'+nextClass+'"></i>');
239
+ Romo.updateHtml(thNextElem, '<i class="'+nextClass+'"></i>');
318
240
  } else {
319
- th.text('>>');
241
+ Romo.updateText(thNextElem, '>>');
320
242
  }
321
- row.append(th);
322
- header.append(row);
323
-
324
- row = $('<tr></tr>');
325
- row.append($('<th class="romo-datepicker-day">S</th>'));
326
- row.append($('<th class="romo-datepicker-day">M</th>'));
327
- row.append($('<th class="romo-datepicker-day">T</th>'));
328
- row.append($('<th class="romo-datepicker-day">W</th>'));
329
- row.append($('<th class="romo-datepicker-day">T</th>'));
330
- row.append($('<th class="romo-datepicker-day">F</th>'));
331
- row.append($('<th class="romo-datepicker-day">S</th>'));
332
- header.append(row);
333
-
334
- return header;
243
+ Romo.append(titleRowElem, thNextElem);
244
+ Romo.append(headerElem, titleRowElem);
245
+
246
+ var daysRowElem = Romo.elems('<tr></tr>')[0];
247
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">S</th>');
248
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">M</th>');
249
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">T</th>');
250
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">W</th>');
251
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">T</th>');
252
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">F</th>');
253
+ Romo.appendHtml(daysRowElem, '<th class="romo-datepicker-day">S</th>');
254
+ Romo.append(headerElem, daysRowElem);
255
+
256
+ return headerElem;
335
257
  }
336
258
 
337
259
  RomoDatepicker.prototype._buildCalendarTitle = function(date) {
338
260
  return RomoDate.format(date, 'MM yyyy');
339
261
  }
340
262
 
341
- RomoDatepicker.prototype._buildCalendarBody = function(date) {
263
+ RomoDatepicker.prototype._buildCalendarBodyRows = function(date) {
342
264
  var html = [];
343
265
 
344
266
  // prefer showing as many past dates in each month as possible
@@ -378,7 +300,7 @@ RomoDatepicker.prototype._buildCalendarBody = function(date) {
378
300
 
379
301
  html.push('<td');
380
302
  html.push(' class="'+cls.join(' ')+'"');
381
- var dt = RomoDate.format(iDate, this.formatString);
303
+ var dt = RomoDate.format(iDate, this.formatString());
382
304
  html.push(' title="'+dt+'"');
383
305
  html.push(' data-romo-datepicker-value="'+dt+'"');
384
306
  html.push('>');
@@ -392,14 +314,85 @@ RomoDatepicker.prototype._buildCalendarBody = function(date) {
392
314
  iDate = RomoDate.next(iDate);
393
315
  }
394
316
 
395
- return $(html.join(''));
317
+ return Romo.elems(html.join(''));
396
318
  }
397
319
 
398
- RomoDatepicker.prototype._highlightItem = function(item) {
399
- this.calTable.find('TD.romo-datepicker-highlight').removeClass('romo-datepicker-highlight');
400
- item.addClass('romo-datepicker-highlight');
320
+ RomoDatepicker.prototype._highlightItem = function(itemElem) {
321
+ var highlightElem = Romo.find(this.calTable, 'TD.romo-datepicker-highlight')[0];
322
+ if(highlightElem !== undefined) {
323
+ Romo.removeClass(highlightElem, 'romo-datepicker-highlight');
324
+ }
325
+ if(itemElem !== undefined) {
326
+ Romo.addClass(itemElem, 'romo-datepicker-highlight');
327
+ }
401
328
  }
402
329
 
403
- Romo.onInitUI(function(e) {
404
- Romo.initUIElems(e, '[data-romo-datepicker-auto="true"]').romoDatepicker();
405
- });
330
+ // event functions
331
+
332
+ RomoDatepicker.prototype.romoEvFn._onTriggerSetDate = function(e, value) {
333
+ this.doSetDate(value);
334
+ this._triggerSetDateChangeEvent();
335
+ }
336
+
337
+ RomoDatepicker.prototype.romoEvFn._onElemKeyDown = function(e) {
338
+ if (Romo.hasClass(this.elem, 'disabled') === false) {
339
+ if (this.romoDropdown.popupOpen()) {
340
+ return true;
341
+ } else {
342
+ if(e.keyCode === 40 /* Down */ ) {
343
+ this.romoDropdown.doPopupOpen();
344
+ this.romoDropdown.popupElem.focus();
345
+ return false;
346
+ } else {
347
+ return true;
348
+ }
349
+ }
350
+ }
351
+ return true;
352
+ }
353
+
354
+ RomoDatepicker.prototype.romoEvFn._onPopupOpen = function(e) {
355
+ if (Romo.hasClass(this.elem, 'disabled') === false) {
356
+ this.doSetDate(this.elem.value);
357
+ this.doRefreshUI();
358
+ }
359
+ }
360
+
361
+ RomoDatepicker.prototype.romoEvFn._onPopupClose = function(e) {
362
+ this._highlightItem(undefined);
363
+ }
364
+
365
+ RomoDatepicker.prototype.romoEvFn._onItemEnter = function(e) {
366
+ this._highlightItem(e.target);
367
+ return false
368
+ }
369
+
370
+ RomoDatepicker.prototype.romoEvFn._onItemClick = function(e) {
371
+ this._clearBlurTimeout();
372
+ this._selectHighlightedItem();
373
+ return false;
374
+ }
375
+
376
+ RomoDatepicker.prototype.romoEvFn._onPrevClick = function(e) {
377
+ this._clearBlurTimeout();
378
+ this._refreshToPrevMonth();
379
+ return false;
380
+ }
381
+
382
+ RomoDatepicker.prototype.romoEvFn._onNextClick = function(e) {
383
+ this._clearBlurTimeout();
384
+ this._refreshToNextMonth();
385
+ return false;
386
+ }
387
+
388
+ RomoDatepicker.prototype.romoEvFn._onPopupMouseDown = function(e) {
389
+ this.popupMouseDown = true;
390
+ }
391
+
392
+ RomoDatepicker.prototype.romoEvFn._onPopupMouseUp = function(e) {
393
+ this.popupMouseDown = false;
394
+ }
395
+
396
+ // init
397
+
398
+ Romo.addElemsInitSelector('[data-romo-datepicker-auto="true"]', RomoDatepicker);