jquery-timepicker-rails 1.3.9 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 545fa00de0d6a98095473a70516e8ae9437cb9a4
4
- data.tar.gz: 00b5995547dba2820adf60f2ae3467580c93af1e
3
+ metadata.gz: c978407cf2665af4f801c09c347d41e493133053
4
+ data.tar.gz: 037931e33cf27380cdf92a93131d2e37ef0129bb
5
5
  SHA512:
6
- metadata.gz: 92fd90b8cb6d70dc849e77200a41705770731465dd2a5f5e7ec24096bdac4c7c1b5babce3e072b0946ed2f3f29e2a6507233ac32136cb8999af71ecfdf550f55
7
- data.tar.gz: 40e0464a7e807e57eed19987dd259cf5947fbe848ba8897c5abef0741a20965d74ba7aa24940285fa30e0955fccc066c9c6b8c1d538e88ae1fac236aae55f864
6
+ metadata.gz: 831b5fe6f57a22b12e3cb9f4b9d3290eff7272c850833d7dff3fd221cb1f61cd8a1683875ddf8ed1fbc8fe5387c183dc020f3a8c40db0df136e5861eae46f9a2
7
+ data.tar.gz: 2d7cf44e2a010096a9490ed8f836386fb2e6ce149af1464804504f4da75a8b27478cdea06e8dc998f3d260832497ba11d32070be707930fef83db5194d175dad
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Timepicker
3
3
  module Rails
4
- VERSION = '1.3.9'
4
+ VERSION = '1.4.3'
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * datepair.js v0.2.1 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
2
+ * datepair.js v0.2.2 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
3
3
  * Copyright (c) 2014 Jon Thornton - http://jonthornton.github.com/Datepair.js
4
4
  * License: MIT
5
5
  */
@@ -10,19 +10,19 @@
10
10
 
11
11
  var _ONE_DAY = 86400000;
12
12
  var jq = window.Zepto || window.jQuery
13
-
13
+
14
14
  function simpleExtend(obj1, obj2) {
15
15
  var out = obj2 || {};
16
-
16
+
17
17
  for (var i in obj1) {
18
18
  if (!(i in out)) {
19
19
  out[i] = obj1[i]
20
20
  }
21
21
  }
22
-
22
+
23
23
  return out;
24
24
  }
25
-
25
+
26
26
  // IE's custom event support is totally borked.
27
27
  // Use jQuery if possible
28
28
  function triggerSimpleCustomEvent(el, eventName) {
@@ -34,7 +34,7 @@
34
34
  el.dispatchEvent(event);
35
35
  }
36
36
  }
37
-
37
+
38
38
  // el.classList not supported by < IE10
39
39
  // use jQuery if available
40
40
  function hasClass(el, className) {
@@ -44,7 +44,7 @@
44
44
  return el.classList.contains(className);
45
45
  }
46
46
  }
47
-
47
+
48
48
  function Datepair(container, options) {
49
49
  this.dateDelta = null;
50
50
  this.timeDelta = null;
@@ -55,7 +55,7 @@
55
55
  dateClass: 'date',
56
56
  defaultDateDelta: 0,
57
57
  defaultTimeDelta: 3600000,
58
-
58
+
59
59
  // defaults for jquery-timepicker; override when using other input widgets
60
60
  parseTime: function(input){
61
61
  return jq(input).timepicker('getTime');
@@ -66,7 +66,7 @@
66
66
  setMinTime: function(input, dateObj){
67
67
  jq(input).timepicker('option', 'minTime', dateObj);
68
68
  },
69
-
69
+
70
70
  // defaults for bootstrap datepicker; override when using other input widgets
71
71
  parseDate: function(input){
72
72
  return jq(input).datepicker('getDate');
@@ -75,22 +75,34 @@
75
75
  jq(input).datepicker('update', dateObj);
76
76
  }
77
77
  };
78
-
78
+
79
79
  this.container = container;
80
80
  this.settings = simpleExtend(this._defaults, options);
81
-
81
+
82
82
  this.startDateInput = this.container.querySelector('.'+this.settings.startClass+'.'+this.settings.dateClass);
83
83
  this.endDateInput = this.container.querySelector('.'+this.settings.endClass+'.'+this.settings.dateClass);
84
84
  this.startTimeInput = this.container.querySelector('.'+this.settings.startClass+'.'+this.settings.timeClass);
85
85
  this.endTimeInput = this.container.querySelector('.'+this.settings.endClass+'.'+this.settings.timeClass);
86
-
86
+
87
+ // initialize date and time deltas
88
+ if (this.startDateInput && this.startDateInput.value && this.startDateInput && this.endDateInput.value) {
89
+ var startDate = this.settings.parseDate(this.startDateInput);
90
+ var endDate = this.settings.parseDate(this.endDateInput);
91
+ this.dateDelta = endDate.getTime() - startDate.getTime();
92
+ }
93
+ if (this.startTimeInput && this.startTimeInput.value && this.endTimeInput && this.endTimeInput.value) {
94
+ var startTime = this.settings.parseTime(this.startTimeInput);
95
+ var endTime = this.settings.parseTime(this.endTimeInput);
96
+ this.timeDelta = endTime.getTime() - startTime.getTime();
97
+ }
98
+
87
99
  // init starts here
88
100
  this._bindChangeHandler();
89
101
  }
90
-
102
+
91
103
  Datepair.prototype = {
92
104
  constructor: Datepair,
93
-
105
+
94
106
  _bindChangeHandler: function(){
95
107
  // addEventListener doesn't work with synthetic "change" events
96
108
  // fired by jQuery's trigger() functioin. If jQuery is present,
@@ -101,7 +113,7 @@
101
113
  this.container.addEventListener('change', this, false);
102
114
  }
103
115
  },
104
-
116
+
105
117
  _unbindChangeHandler: function(){
106
118
  if (jq) {
107
119
  jq(this.container).off('change.datepair');
@@ -109,20 +121,20 @@
109
121
  this.container.removeEventListener('change', this, false);
110
122
  }
111
123
  },
112
-
124
+
113
125
  // This function will be called when passing 'this' to addEventListener
114
126
  handleEvent: function(e){
115
127
  // temporarily unbind the change handler to prevent triggering this
116
128
  // if we update other inputs
117
129
  this._unbindChangeHandler();
118
-
130
+
119
131
  if (hasClass(e.target, this.settings.dateClass)) {
120
132
  if (e.target.value != '') {
121
133
  this._dateChanged(e.target);
122
134
  } else {
123
135
  this.dateDelta = null;
124
136
  }
125
-
137
+
126
138
  } else if (hasClass(e.target, this.settings.timeClass)) {
127
139
  if (e.target.value != '') {
128
140
  this._timeChanged(e.target);
@@ -130,41 +142,41 @@
130
142
  this.timeDelta = null;
131
143
  }
132
144
  }
133
-
145
+
134
146
  this._validateRanges();
135
147
  this._updateEndMintime()
136
148
  this._bindChangeHandler();
137
149
  },
138
-
150
+
139
151
  _dateChanged: function(target){
140
152
  if (!this.startDateInput || !this.endDateInput) {
141
153
  return
142
154
  }
143
-
155
+
144
156
  if (!this.startDateInput.value || !this.endDateInput.value) {
145
157
  if (this.settings.defaultDateDelta !== null) {
146
158
  if (this.startDateInput.value) {
147
159
  var startDate = this.settings.parseDate(this.startDateInput);
148
160
  var newEnd = new Date(startDate.getTime() + this.settings.defaultDateDelta * _ONE_DAY);
149
161
  this.settings.updateDate(this.endDateInput, newEnd);
150
-
162
+
151
163
  } else if (this.endDateInput.value) {
152
164
  var endDate = this.settings.parseDate($endDateInput);
153
165
  var newStart = new Date(endDate.getTime() - this.settings.defaultDateDelta * _ONE_DAY);
154
166
  this.settings.updateDate(this.startDateInput, newStart);
155
167
  }
156
-
168
+
157
169
  this.dateDelta = this.settings.defaultDateDelta * _ONE_DAY;
158
170
  } else {
159
171
  this.dateDelta = null;
160
172
  }
161
-
173
+
162
174
  return;
163
175
  }
164
-
176
+
165
177
  var startDate = this.settings.parseDate(this.startDateInput);
166
178
  var endDate = this.settings.parseDate(this.endDateInput);
167
-
179
+
168
180
  if (hasClass(target, this.settings.startClass)) {
169
181
  var newEndDate = new Date(startDate.getTime() + this.dateDelta);
170
182
  this.settings.updateDate(this.endDateInput, newEndDate);
@@ -177,12 +189,12 @@
177
189
  }
178
190
  }
179
191
  },
180
-
192
+
181
193
  _timeChanged: function(target){
182
194
  if (!this.startTimeInput || !this.endTimeInput) {
183
195
  return
184
196
  }
185
-
197
+
186
198
  if (!this.startTimeInput.value || !this.endTimeInput.value) {
187
199
  if (this.settings.defaultTimeDelta !== null) {
188
200
  if (this.startTimeInput.value) {
@@ -194,56 +206,56 @@
194
206
  var newStart = new Date(endTime.getTime() - this.settings.defaultTimeDelta);
195
207
  this.settings.updateTime(this.startTimeInput, newStart);
196
208
  }
197
-
209
+
198
210
  this.timeDelta = this.settings.defaultTimeDelta;
199
211
  } else {
200
212
  this.timeDelta = null;
201
213
  }
202
-
214
+
203
215
  return;
204
216
  }
205
-
217
+
206
218
  var startTime = this.settings.parseTime(this.startTimeInput);
207
219
  var endTime = this.settings.parseTime(this.endTimeInput);
208
-
220
+
209
221
  if (hasClass(target, this.settings.startClass)) {
210
222
  var newEndTime = new Date(startTime.getTime() + this.timeDelta);
211
223
  this.settings.updateTime(this.endTimeInput, newEndTime);
212
224
  endTime = this.settings.parseTime(this.endTimeInput);
213
225
  }
214
-
226
+
215
227
  if (this.endDateInput && this.endDateInput.value && this.dateDelta + this.timeDelta < _ONE_DAY && (endTime.getTime() - startTime.getTime()) * this.timeDelta < 0) {
216
228
  var offset = (endTime < startTime) ? _ONE_DAY : -1 * _ONE_DAY;
217
229
  var endDate = this.settings.parseDate(this.endDateInput);
218
230
  this.settings.updateDate(this.endDateInput, new Date(endDate.getTime() + offset));
219
231
  this._dateChanged(this.endDateInput);
220
232
  }
221
-
233
+
222
234
  this.timeDelta = endTime.getTime() - startTime.getTime();
223
235
  },
224
-
236
+
225
237
  _updateEndMintime: function(){
226
238
  if (typeof this.settings.setMinTime != 'function') return;
227
-
239
+
228
240
  var startTime = null;
229
241
  if (!this.dateDelta || this.dateDelta < _ONE_DAY || (this.timeDelta && this.dateDelta + this.timeDelta < _ONE_DAY)) {
230
242
  startTime = this.settings.parseTime(this.startTimeInput);
231
243
  }
232
-
244
+
233
245
  this.settings.setMinTime(this.endTimeInput, startTime);
234
246
  },
235
-
247
+
236
248
  _validateRanges: function(){
237
249
  if (this.startTimeInput && this.endTimeInput && this.timeDelta === null) {
238
250
  triggerSimpleCustomEvent(this.container, 'rangeIncomplete');
239
251
  return;
240
252
  }
241
-
253
+
242
254
  if (this.startDateInput && this.endDateInput && this.dateDelta === null) {
243
255
  triggerSimpleCustomEvent(this.container, 'rangeIncomplete');
244
256
  return;
245
257
  }
246
-
258
+
247
259
  if (this.dateDelta + this.timeDelta >= 0) {
248
260
  triggerSimpleCustomEvent(this.container, 'rangeSelected');
249
261
  } else {
@@ -257,7 +269,7 @@
257
269
  }(window, document));
258
270
 
259
271
  /*!
260
- * datepair.js v0.2.1 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
272
+ * datepair.js v0.2.2 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
261
273
  * Copyright (c) 2014 Jon Thornton - http://jonthornton.github.com/Datepair.js
262
274
  * License: MIT
263
275
  */
@@ -1,5 +1,5 @@
1
1
  /************************
2
- jquery-timepicker v1.3.9
2
+ jquery-timepicker v1.4.3
3
3
  http://jonthornton.github.com/jquery-timepicker/
4
4
 
5
5
  requires jQuery 1.7+
@@ -24,9 +24,9 @@ requires jQuery 1.7+
24
24
  durationTime: null,
25
25
  step: 30,
26
26
  showDuration: false,
27
+ showOnFocus: true,
27
28
  timeFormat: 'g:ia',
28
- scrollDefaultNow: false,
29
- scrollDefaultTime: false,
29
+ scrollDefault: null,
30
30
  selectOnBlur: false,
31
31
  disableTouchKeyboard: false,
32
32
  forceRoundTime: false,
@@ -90,13 +90,17 @@ requires jQuery 1.7+
90
90
 
91
91
  show: function(e)
92
92
  {
93
+ var self = $(this);
94
+ var settings = self.data('timepicker-settings');
95
+
93
96
  if (e) {
97
+ if (!settings.showOnFocus) {
98
+ return true;
99
+ }
100
+
94
101
  e.preventDefault();
95
102
  }
96
103
 
97
- var self = $(this);
98
- var settings = self.data('timepicker-settings');
99
-
100
104
  if (settings.useSelect) {
101
105
  self.data('timepicker-list').focus();
102
106
  return;
@@ -155,10 +159,8 @@ requires jQuery 1.7+
155
159
  if (!selected.length) {
156
160
  if (_getTimeValue(self)) {
157
161
  selected = _findRow(self, list, _time2int(_getTimeValue(self)));
158
- } else if (settings.scrollDefaultNow) {
159
- selected = _findRow(self, list, _time2int(new Date()));
160
- } else if (settings.scrollDefaultTime !== false) {
161
- selected = _findRow(self, list, _time2int(settings.scrollDefaultTime));
162
+ } else if (settings.scrollDefault) {
163
+ selected = _findRow(self, list, settings.scrollDefault);
162
164
  }
163
165
  }
164
166
 
@@ -207,34 +209,34 @@ requires jQuery 1.7+
207
209
 
208
210
  option: function(key, value)
209
211
  {
210
- var self = this;
211
- var settings = self.data('timepicker-settings');
212
- var list = self.data('timepicker-list');
213
-
214
- if (typeof key == 'object') {
215
- settings = $.extend(settings, key);
212
+ return this.each(function(){
213
+ var self = $(this);
214
+ var settings = self.data('timepicker-settings');
215
+ var list = self.data('timepicker-list');
216
216
 
217
- } else if (typeof key == 'string' && typeof value != 'undefined') {
218
- settings[key] = value;
217
+ if (typeof key == 'object') {
218
+ settings = $.extend(settings, key);
219
219
 
220
- } else if (typeof key == 'string') {
221
- return settings[key];
222
- }
220
+ } else if (typeof key == 'string' && typeof value != 'undefined') {
221
+ settings[key] = value;
223
222
 
224
- settings = _parseSettings(settings);
223
+ } else if (typeof key == 'string') {
224
+ return settings[key];
225
+ }
225
226
 
226
- self.data('timepicker-settings', settings);
227
+ settings = _parseSettings(settings);
227
228
 
228
- if (list) {
229
- list.remove();
230
- self.data('timepicker-list', false);
231
- }
229
+ self.data('timepicker-settings', settings);
232
230
 
233
- if (settings.useSelect) {
234
- _render(self);
235
- }
231
+ if (list) {
232
+ list.remove();
233
+ self.data('timepicker-list', false);
234
+ }
236
235
 
237
- return this;
236
+ if (settings.useSelect) {
237
+ _render(self);
238
+ }
239
+ });
238
240
  },
239
241
 
240
242
  getSecondsFromMidnight: function()
@@ -325,6 +327,22 @@ requires jQuery 1.7+
325
327
  settings.durationTime = _time2int(settings.durationTime);
326
328
  }
327
329
 
330
+ if (settings.scrollDefault == 'now') {
331
+ settings.scrollDefault = _time2int(new Date());
332
+ } else if (settings.scrollDefault) {
333
+ settings.scrollDefault = _time2int(settings.scrollDefault);
334
+ } else if (settings.minTime) {
335
+ settings.scrollDefault = settings.minTime;
336
+ }
337
+
338
+ if (settings.scrollDefault) {
339
+ settings.scrollDefault = _time2int(_roundTime(settings.scrollDefault, settings));
340
+ }
341
+
342
+ if (settings.timeFormat.match(/[gh]/)) {
343
+ settings._twelveHourTime = true;
344
+ }
345
+
328
346
  if (settings.disableTimeRanges.length > 0) {
329
347
  // convert string times to integers
330
348
  for (var i in settings.disableTimeRanges) {
@@ -491,7 +509,7 @@ requires jQuery 1.7+
491
509
  appendTo.append(wrapped_list);
492
510
  _setSelected(self, list);
493
511
 
494
- list.on('click', 'li', function(e) {
512
+ list.on('mousedown', 'li', function(e) {
495
513
 
496
514
  // hack: temporarily disable the focus handler
497
515
  // to deal with the fact that IE fires 'focus'
@@ -616,7 +634,7 @@ requires jQuery 1.7+
616
634
  {
617
635
  list.find('li').removeClass('ui-timepicker-selected');
618
636
 
619
- var timeValue = _time2int(_getTimeValue(self));
637
+ var timeValue = _time2int(_getTimeValue(self), self.data('timepicker-settings'));
620
638
  if (timeValue === null) {
621
639
  return;
622
640
  }
@@ -741,6 +759,9 @@ requires jQuery 1.7+
741
759
 
742
760
  if (!list || !list.is(':visible')) {
743
761
  if (e.keyCode == 40) {
762
+ // show the list!
763
+ methods.show.call(self.get(0));
764
+ list = self.data('timepicker-list');
744
765
  if (!_hideKeyboard(self)) {
745
766
  self.focus();
746
767
  }
@@ -888,13 +909,6 @@ requires jQuery 1.7+
888
909
  if (cursor.length) {
889
910
  // selected value found
890
911
  timeValue = cursor.data('time');
891
-
892
- } else if (_getTimeValue(self)) {
893
-
894
- // no selected value; fall back on input value
895
- timeValue = _time2int(_getTimeValue(self));
896
-
897
- _setSelected(self, list);
898
912
  }
899
913
 
900
914
  if (timeValue !== null) {
@@ -912,6 +926,7 @@ requires jQuery 1.7+
912
926
 
913
927
  function _int2duration(seconds, step)
914
928
  {
929
+ seconds = Math.abs(seconds);
915
930
  var minutes = Math.round(seconds/60),
916
931
  duration = [],
917
932
  hours, mins;
@@ -1013,7 +1028,7 @@ requires jQuery 1.7+
1013
1028
  return output;
1014
1029
  }
1015
1030
 
1016
- function _time2int(timeString)
1031
+ function _time2int(timeString, settings)
1017
1032
  {
1018
1033
  if (timeString === '') return null;
1019
1034
  if (!timeString || timeString+0 == timeString) return timeString;
@@ -1044,22 +1059,30 @@ requires jQuery 1.7+
1044
1059
  }
1045
1060
 
1046
1061
  var hour = parseInt(time[1]*1, 10);
1047
- var hours;
1062
+ var ampm = time[4];
1063
+ var hours = hour;
1048
1064
 
1049
- if (time[4]) {
1065
+ if (ampm) {
1050
1066
  if (hour == 12) {
1051
1067
  hours = (time[4] == 'p') ? 12 : 0;
1052
1068
  } else {
1053
1069
  hours = (hour + (time[4] == 'p' ? 12 : 0));
1054
1070
  }
1055
-
1056
- } else {
1057
- hours = hour;
1058
1071
  }
1059
1072
 
1060
1073
  var minutes = ( time[2]*1 || 0 );
1061
1074
  var seconds = ( time[3]*1 || 0 );
1062
- return hours*3600 + minutes*60 + seconds;
1075
+ var timeInt = hours*3600 + minutes*60 + seconds;
1076
+
1077
+ // if no am/pm provided, intelligently guess based on the scrollDefault
1078
+ if (!ampm && settings && settings._twelveHourTime && settings.scrollDefault) {
1079
+ var delta = timeInt - settings.scrollDefault;
1080
+ if (delta < 0 && delta >= _ONE_DAY / -2) {
1081
+ timeInt = (timeInt + (_ONE_DAY / 2)) % _ONE_DAY;
1082
+ }
1083
+ }
1084
+
1085
+ return timeInt
1063
1086
  }
1064
1087
 
1065
1088
  function _pad2(n) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-timepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanguy Krotoff (jQuery plugin by Jon Thornton)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-24 00:00:00.000000000 Z
12
+ date: 2014-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties