jquery-timepicker-rails 1.0.7.0 → 1.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Timepicker
3
3
  module Rails
4
- VERSION = "1.0.7.0"
4
+ VERSION = "1.1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  /************************
2
- jquery-timepicker
2
+ jquery-timepicker v1.1
3
3
  http://jonthornton.github.com/jquery-timepicker/
4
4
 
5
5
  requires jQuery 1.7+
@@ -30,7 +30,9 @@ requires jQuery 1.7+
30
30
  selectOnBlur: false,
31
31
  disableTouchKeyboard: true,
32
32
  forceRoundTime: false,
33
- appendTo: 'body'
33
+ appendTo: 'body',
34
+ disableTimeRanges: [],
35
+ closeOnWindowScroll: true
34
36
  };
35
37
  var _lang = {
36
38
  decimal: '.',
@@ -67,22 +69,12 @@ requires jQuery 1.7+
67
69
  settings = $.extend(settings, options);
68
70
  }
69
71
 
70
- if (settings.minTime) {
71
- settings.minTime = _time2int(settings.minTime);
72
- }
73
-
74
- if (settings.maxTime) {
75
- settings.maxTime = _time2int(settings.maxTime);
76
- }
77
-
78
- if (settings.durationTime) {
79
- settings.durationTime = _time2int(settings.durationTime);
80
- }
81
-
82
72
  if (settings.lang) {
83
73
  _lang = $.extend(_lang, settings.lang);
84
74
  }
85
75
 
76
+ settings = _parseSettings(settings);
77
+
86
78
  self.data('timepicker-settings', settings);
87
79
  self.prop('autocomplete', 'off');
88
80
  self.on('click.timepicker focus.timepicker', methods.show);
@@ -131,16 +123,16 @@ requires jQuery 1.7+
131
123
  // make sure other pickers are hidden
132
124
  methods.hide();
133
125
 
126
+ list.show();
127
+
134
128
  if ((self.offset().top + self.outerHeight(true) + list.outerHeight()) > $(window).height() + $(window).scrollTop()) {
135
129
  // position the dropdown on top
136
- list.css({ 'left':(self.offset().left), 'top': self.offset().top - list.outerHeight() });
130
+ list.offset({ 'left':(self.offset().left), 'top': self.offset().top - list.outerHeight() });
137
131
  } else {
138
132
  // put it under the input
139
- list.css({ 'left':(self.offset().left), 'top': self.offset().top + self.outerHeight() });
133
+ list.offset({ 'left':(self.offset().left), 'top': self.offset().top + self.outerHeight() });
140
134
  }
141
135
 
142
- list.show();
143
-
144
136
  // position scrolling
145
137
  var selected = list.find('.ui-timepicker-selected');
146
138
 
@@ -161,7 +153,7 @@ requires jQuery 1.7+
161
153
  list.scrollTop(0);
162
154
  }
163
155
 
164
- _attachCloseHandler();
156
+ _attachCloseHandler(settings);
165
157
 
166
158
  self.trigger('showTimepicker');
167
159
  },
@@ -198,17 +190,7 @@ requires jQuery 1.7+
198
190
  return settings[key];
199
191
  }
200
192
 
201
- if (settings.minTime) {
202
- settings.minTime = _time2int(settings.minTime);
203
- }
204
-
205
- if (settings.maxTime) {
206
- settings.maxTime = _time2int(settings.maxTime);
207
- }
208
-
209
- if (settings.durationTime) {
210
- settings.durationTime = _time2int(settings.durationTime);
211
- }
193
+ settings = _parseSettings(settings);
212
194
 
213
195
  self.data('timepicker-settings', settings);
214
196
 
@@ -226,7 +208,9 @@ requires jQuery 1.7+
226
208
 
227
209
  getTime: function()
228
210
  {
229
- return new Date(_baseDate.valueOf() + (_time2int($(this).val())*1000));
211
+ var today = new Date();
212
+ today.setHours(0, 0, 0, 0);
213
+ return new Date(today.valueOf() + (_time2int($(this).val())*1000));
230
214
  },
231
215
 
232
216
  setTime: function(value)
@@ -261,6 +245,38 @@ requires jQuery 1.7+
261
245
 
262
246
  // private methods
263
247
 
248
+ function _parseSettings(settings)
249
+ {
250
+ if (settings.minTime) {
251
+ settings.minTime = _time2int(settings.minTime);
252
+ }
253
+
254
+ if (settings.maxTime) {
255
+ settings.maxTime = _time2int(settings.maxTime);
256
+ }
257
+
258
+ if (settings.durationTime) {
259
+ settings.durationTime = _time2int(settings.durationTime);
260
+ }
261
+
262
+ if (settings.disableTimeRanges.length > 0) {
263
+ // convert string times to integers
264
+ for (var i in settings.disableTimeRanges) {
265
+ settings.disableTimeRanges[i] = [
266
+ _time2int(settings.disableTimeRanges[i][0]),
267
+ _time2int(settings.disableTimeRanges[i][1])
268
+ ];
269
+ }
270
+
271
+ // sort by starting time
272
+ settings.disableTimeRanges = settings.disableTimeRanges.sort(function(a, b){
273
+ return a[0] - b[0];
274
+ });
275
+ }
276
+
277
+ return settings;
278
+ }
279
+
264
280
  function _render(self)
265
281
  {
266
282
  var settings = self.data('timepicker-settings');
@@ -295,8 +311,12 @@ requires jQuery 1.7+
295
311
  end += _ONE_DAY;
296
312
  }
297
313
 
314
+ var disabledTimeRanges = settings.disableTimeRanges;
315
+ var disabledRange = disabledTimeRanges.shift();
316
+
298
317
  for (var i=start; i <= end; i += settings.step*60) {
299
318
  var timeInt = i%_ONE_DAY;
319
+
300
320
  var row = $('<li />');
301
321
  row.data('time', timeInt);
302
322
  row.text(_int2time(timeInt, settings.timeFormat));
@@ -308,6 +328,14 @@ requires jQuery 1.7+
308
328
  row.append(duration);
309
329
  }
310
330
 
331
+ if (disabledRange) {
332
+ if (timeInt >= disabledRange[0] && timeInt < disabledRange[1]) {
333
+ row.addClass('ui-timepicker-disabled');
334
+ } else if (timeInt > disabledRange[1]) {
335
+ disabledRange = disabledTimeRanges.shift();
336
+ }
337
+ }
338
+
311
339
  list.append(row);
312
340
  }
313
341
 
@@ -324,35 +352,33 @@ requires jQuery 1.7+
324
352
  _setSelected(self, list);
325
353
 
326
354
  list.on('click', 'li', function(e) {
327
- self.addClass('ui-timepicker-hideme');
328
355
  self[0].focus();
329
356
 
330
357
  // make sure only the clicked row is selected
331
358
  list.find('li').removeClass('ui-timepicker-selected');
332
359
  $(this).addClass('ui-timepicker-selected');
333
360
 
334
- _selectValue(self);
335
- list.hide();
361
+ if (_selectValue(self)) {
362
+ self.addClass('ui-timepicker-hideme');
363
+ list.hide();
364
+ }
336
365
  });
337
366
  }
338
367
 
339
368
  function _generateBaseDate()
340
369
  {
341
- var _baseDate = new Date();
342
- var _currentTimezoneOffset = _baseDate.getTimezoneOffset()*60000;
343
- _baseDate.setHours(0); _baseDate.setMinutes(0); _baseDate.setSeconds(0);
344
- var _baseDateTimezoneOffset = _baseDate.getTimezoneOffset()*60000;
345
-
346
- return new Date(_baseDate.valueOf() - _baseDateTimezoneOffset + _currentTimezoneOffset);
370
+ return new Date(1970, 1, 1, 0, 0, 0);
347
371
  }
348
372
 
349
- function _attachCloseHandler()
373
+ function _attachCloseHandler(settings)
350
374
  {
351
375
  if ('ontouchstart' in document) {
352
376
  $('body').on('touchstart.ui-timepicker', _closeHandler);
353
377
  } else {
354
378
  $('body').on('mousedown.ui-timepicker', _closeHandler);
355
- $(window).on('scroll.ui-timepicker', _closeHandler);
379
+ if (settings.closeOnWindowScroll) {
380
+ $(window).on('scroll.ui-timepicker', _closeHandler);
381
+ }
356
382
  }
357
383
  }
358
384
 
@@ -419,6 +445,13 @@ requires jQuery 1.7+
419
445
 
420
446
  var settings = self.data('timepicker-settings');
421
447
 
448
+ // check that the time in within bounds
449
+ if (settings.minTime !== null && seconds < settings.minTime) {
450
+ self.trigger('timeRangeError');
451
+ } else if (settings.maxTime !== null && seconds > settings.maxTime) {
452
+ self.trigger('timeRangeError');
453
+ }
454
+
422
455
  if (settings.forceRoundTime) {
423
456
  var offset = seconds % (settings.step*60); // step is in minutes
424
457
 
@@ -440,7 +473,7 @@ requires jQuery 1.7+
440
473
  var self = $(this);
441
474
  var list = self.data('timepicker-list');
442
475
 
443
- if (!list.is(':visible')) {
476
+ if (!list || !list.is(':visible')) {
444
477
  if (e.keyCode == 40) {
445
478
  self.focus();
446
479
  } else {
@@ -451,8 +484,10 @@ requires jQuery 1.7+
451
484
  switch (e.keyCode) {
452
485
 
453
486
  case 13: // return
454
- _selectValue(self);
455
- methods.hide.apply(this);
487
+ if (_selectValue(self)) {
488
+ methods.hide.apply(this);
489
+ }
490
+
456
491
  e.preventDefault();
457
492
  return false;
458
493
 
@@ -539,6 +574,10 @@ requires jQuery 1.7+
539
574
 
540
575
  var cursor = list.find('.ui-timepicker-selected');
541
576
 
577
+ if (cursor.hasClass('ui-timepicker-disabled')) {
578
+ return false;
579
+ }
580
+
542
581
  if (cursor.length) {
543
582
  // selected value found
544
583
  timeValue = cursor.data('time');
@@ -557,6 +596,7 @@ requires jQuery 1.7+
557
596
  }
558
597
 
559
598
  self.trigger('change').trigger('changeTime');
599
+ return true;
560
600
  }
561
601
 
562
602
  function _int2duration(seconds)
@@ -654,12 +694,12 @@ requires jQuery 1.7+
654
694
  var d = new Date(0);
655
695
 
656
696
  var timeRegex;
657
- if (timeString.indexOf(":") !== -1) {
658
- //colon-delimited version
659
- timeRegex = /(\d{1,2})(?::(\d{1,2}))?(?::(\d{2}))?\s*([pa]?)/;
660
- } else {
697
+ if (timeString.indexOf(":") === -1 && $.isNumeric(timeString.charAt(1))) {
661
698
  //zero-required, fixed-position version
662
- timeRegex = /^([0-2][0-9]):?([0-5][0-9])?:?([0-5][0-9])?\s*([pa]?)$/;
699
+ timeRegex = /^([0-2][0-9]):?([0-5][0-9])?:?([0-5][0-9])?\s*([pa]?)/;
700
+ } else {
701
+ //colon-delimited version
702
+ timeRegex = /^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([pa]?)/;
663
703
  }
664
704
 
665
705
  var time = timeString.toLowerCase().match(timeRegex);
@@ -694,4 +734,4 @@ requires jQuery 1.7+
694
734
  else if(typeof method === "object" || !method) { return methods.init.apply(this, arguments); }
695
735
  else { $.error("Method "+ method + " does not exist on jQuery.timepicker"); }
696
736
  };
697
- }));
737
+ }));
@@ -41,7 +41,7 @@
41
41
 
42
42
  li.ui-timepicker-selected,
43
43
  .ui-timepicker-list li:hover,
44
- .ui-timepicker-list:hover .ui-timepicker-selected:hover {
44
+ .ui-timepicker-list .ui-timepicker-selected:hover {
45
45
  background: #1980EC; color: #fff;
46
46
  }
47
47
 
@@ -49,3 +49,15 @@ li.ui-timepicker-selected .ui-timepicker-duration,
49
49
  .ui-timepicker-list li:hover .ui-timepicker-duration {
50
50
  color: #ccc;
51
51
  }
52
+
53
+ .ui-timepicker-list li.ui-timepicker-disabled,
54
+ .ui-timepicker-list li.ui-timepicker-disabled:hover,
55
+ .ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled {
56
+ color: #888;
57
+ cursor: default;
58
+ }
59
+
60
+ .ui-timepicker-list li.ui-timepicker-disabled:hover,
61
+ .ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled {
62
+ background: #f2f2f2;
63
+ }
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.0.7.0
4
+ version: 1.1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &26010300 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *26010300
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
25
30
  description: A jQuery timepicker plugin inspired by Google Calendar
26
31
  email:
27
32
  - tkrotoff@gmail.com
@@ -60,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
65
  version: '0'
61
66
  requirements: []
62
67
  rubyforge_project:
63
- rubygems_version: 1.8.16
68
+ rubygems_version: 1.8.23
64
69
  signing_key:
65
70
  specification_version: 3
66
71
  summary: jquery-timepicker packaged for the Rails 3.1+ asset pipeline