jquery-timepicker-rails 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,14 @@
|
|
1
1
|
$(function() {
|
2
2
|
|
3
|
+
var DATE_FORMAT = 'Y-m-d';
|
4
|
+
var DATEPICKER_FORMAT = 'yyyy-m-d';
|
5
|
+
|
3
6
|
$('.datepair input.date').each(function(){
|
4
7
|
var $this = $(this);
|
5
|
-
$this.datepicker({
|
8
|
+
$this.datepicker({
|
9
|
+
'format': DATEPICKER_FORMAT,
|
10
|
+
'autoclose': true
|
11
|
+
});
|
6
12
|
|
7
13
|
if ($this.hasClass('start') || $this.hasClass('end')) {
|
8
14
|
$this.on('changeDate change', doDatepair);
|
@@ -61,7 +67,7 @@ $(function() {
|
|
61
67
|
if (target.val() == '') {
|
62
68
|
return;
|
63
69
|
}
|
64
|
-
|
70
|
+
|
65
71
|
var container = target.closest('.datepair');
|
66
72
|
|
67
73
|
if (target.hasClass('date')) {
|
@@ -88,7 +94,7 @@ $(function() {
|
|
88
94
|
|
89
95
|
if (oldDelta && target.hasClass('start')) {
|
90
96
|
var newEnd = new Date(startDate.getTime()+oldDelta);
|
91
|
-
end.val(newEnd.format(
|
97
|
+
end.val(newEnd.format(DATE_FORMAT));
|
92
98
|
end.datepicker('update');
|
93
99
|
return;
|
94
100
|
|
@@ -99,10 +105,10 @@ $(function() {
|
|
99
105
|
newDelta = 0;
|
100
106
|
|
101
107
|
if (target.hasClass('start')) {
|
102
|
-
end.val(
|
108
|
+
end.val(start.val());
|
103
109
|
end.datepicker('update');
|
104
110
|
} else if (target.hasClass('end')) {
|
105
|
-
start.val(
|
111
|
+
start.val(end.val());
|
106
112
|
start.datepicker('update');
|
107
113
|
}
|
108
114
|
}
|
@@ -185,7 +191,7 @@ $(function() {
|
|
185
191
|
if (dateDelta || dateDelta === 0) {
|
186
192
|
var endDate = new Date(endInput.val());
|
187
193
|
var newEnd = new Date(endDate.getTime() + endDateAdvance);
|
188
|
-
endInput.val(newEnd.format(
|
194
|
+
endInput.val(newEnd.format(DATE_FORMAT));
|
189
195
|
endInput.datepicker('update');
|
190
196
|
container.data('dateDelta', dateDelta + endDateAdvance);
|
191
197
|
}
|
@@ -2,15 +2,22 @@
|
|
2
2
|
jquery-timepicker
|
3
3
|
http://jonthornton.github.com/jquery-timepicker/
|
4
4
|
|
5
|
-
requires jQuery 1.
|
5
|
+
requires jQuery 1.7+
|
6
6
|
************************/
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
{
|
11
|
-
|
9
|
+
(function (factory) {
|
10
|
+
if (typeof define === 'function' && define.amd) {
|
11
|
+
// AMD. Register as an anonymous module.
|
12
|
+
define(['jquery'], factory);
|
13
|
+
} else {
|
14
|
+
// Browser globals
|
15
|
+
factory(jQuery);
|
16
|
+
}
|
17
|
+
}(function ($) {
|
12
18
|
var _baseDate = _generateBaseDate();
|
13
19
|
var _ONE_DAY = 86400;
|
20
|
+
var _closeEvent = 'ontouchstart' in document ? 'touchstart' : 'mousedown';
|
14
21
|
var _defaults = {
|
15
22
|
className: null,
|
16
23
|
minTime: null,
|
@@ -21,7 +28,9 @@ requires jQuery 1.6+
|
|
21
28
|
timeFormat: 'g:ia',
|
22
29
|
scrollDefaultNow: false,
|
23
30
|
scrollDefaultTime: false,
|
24
|
-
selectOnBlur: false
|
31
|
+
selectOnBlur: false,
|
32
|
+
forceRoundTime: false,
|
33
|
+
appendTo: 'body'
|
25
34
|
};
|
26
35
|
var _lang = {
|
27
36
|
decimal: '.',
|
@@ -87,8 +96,10 @@ requires jQuery 1.6+
|
|
87
96
|
|
88
97
|
if (!globalInit) {
|
89
98
|
// close the dropdown when container loses focus
|
90
|
-
$('body').on(
|
91
|
-
|
99
|
+
$('body').on(_closeEvent, function(e) {
|
100
|
+
var target = $(e.target);
|
101
|
+
var input = target.closest('.ui-timepicker-input');
|
102
|
+
if (input.length === 0 && target.closest('.ui-timepicker-list').length === 0) {
|
92
103
|
methods.hide();
|
93
104
|
}
|
94
105
|
});
|
@@ -100,6 +111,12 @@ requires jQuery 1.6+
|
|
100
111
|
show: function(e)
|
101
112
|
{
|
102
113
|
var self = $(this);
|
114
|
+
|
115
|
+
if ('ontouchstart' in document) {
|
116
|
+
// block the keyboard on mobile devices
|
117
|
+
self.blur();
|
118
|
+
}
|
119
|
+
|
103
120
|
var list = self.data('timepicker-list');
|
104
121
|
|
105
122
|
// check if input is readonly
|
@@ -108,7 +125,7 @@ requires jQuery 1.6+
|
|
108
125
|
}
|
109
126
|
|
110
127
|
// check if list needs to be rendered
|
111
|
-
if (!list || list.length
|
128
|
+
if (!list || list.length === 0) {
|
112
129
|
_render(self);
|
113
130
|
list = self.data('timepicker-list');
|
114
131
|
}
|
@@ -127,15 +144,12 @@ requires jQuery 1.6+
|
|
127
144
|
// make sure other pickers are hidden
|
128
145
|
methods.hide();
|
129
146
|
|
130
|
-
var topMargin = parseInt(self.css('marginTop').slice(0, -2));
|
131
|
-
if (!topMargin) topMargin = 0; // correct for IE returning "auto"
|
132
|
-
|
133
147
|
if ((self.offset().top + self.outerHeight(true) + list.outerHeight()) > $(window).height() + $(window).scrollTop()) {
|
134
148
|
// position the dropdown on top
|
135
|
-
list.css({ 'left':(self.offset().left), 'top': self.offset().top
|
149
|
+
list.css({ 'left':(self.offset().left), 'top': self.offset().top - list.outerHeight() });
|
136
150
|
} else {
|
137
151
|
// put it under the input
|
138
|
-
list.css({ 'left':(self.offset().left), 'top': self.offset().top +
|
152
|
+
list.css({ 'left':(self.offset().left), 'top': self.offset().top + self.outerHeight() });
|
139
153
|
}
|
140
154
|
|
141
155
|
list.show();
|
@@ -145,13 +159,13 @@ requires jQuery 1.6+
|
|
145
159
|
var selected = list.find('.ui-timepicker-selected');
|
146
160
|
|
147
161
|
if (!selected.length) {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
162
|
+
if (self.val()) {
|
163
|
+
selected = _findRow(self, list, _time2int(self.val()));
|
164
|
+
} else if (settings.scrollDefaultNow) {
|
165
|
+
selected = _findRow(self, list, _time2int(new Date()));
|
166
|
+
} else if (settings.scrollDefaultTime !== false) {
|
167
|
+
selected = _findRow(self, list, _time2int(settings.scrollDefaultTime));
|
168
|
+
}
|
155
169
|
}
|
156
170
|
|
157
171
|
if (selected && selected.length) {
|
@@ -278,7 +292,7 @@ requires jQuery 1.6+
|
|
278
292
|
|
279
293
|
list.css({'display':'none', 'position': 'absolute' });
|
280
294
|
|
281
|
-
if (settings.minTime !== null && settings.showDuration) {
|
295
|
+
if ((settings.minTime !== null || settings.durationTime !== null) && settings.showDuration) {
|
282
296
|
list.addClass('ui-timepicker-with-duration');
|
283
297
|
}
|
284
298
|
|
@@ -294,14 +308,14 @@ requires jQuery 1.6+
|
|
294
308
|
for (var i=start; i <= end; i += settings.step*60) {
|
295
309
|
var timeInt = i%_ONE_DAY;
|
296
310
|
var row = $('<li />');
|
297
|
-
row.data('time', timeInt)
|
311
|
+
row.data('time', timeInt);
|
298
312
|
row.text(_int2time(timeInt, settings.timeFormat));
|
299
313
|
|
300
|
-
if (settings.minTime !== null && settings.showDuration) {
|
314
|
+
if ((settings.minTime !== null || settings.durationTime !== null) && settings.showDuration) {
|
301
315
|
var duration = $('<span />');
|
302
316
|
duration.addClass('ui-timepicker-duration');
|
303
317
|
duration.text(' ('+_int2duration(i - durStart)+')');
|
304
|
-
row.append(duration)
|
318
|
+
row.append(duration);
|
305
319
|
}
|
306
320
|
|
307
321
|
list.append(row);
|
@@ -310,7 +324,13 @@ requires jQuery 1.6+
|
|
310
324
|
list.data('timepicker-input', self);
|
311
325
|
self.data('timepicker-list', list);
|
312
326
|
|
313
|
-
|
327
|
+
var appendTo = settings.appendTo;
|
328
|
+
if (typeof appendTo === 'string') {
|
329
|
+
appendTo = $(appendTo);
|
330
|
+
} else if (typeof appendTo === 'function') {
|
331
|
+
appendTo = appendTo(self);
|
332
|
+
}
|
333
|
+
appendTo.append(list);
|
314
334
|
_setSelected(self, list);
|
315
335
|
|
316
336
|
list.on('click', 'li', function(e) {
|
@@ -324,7 +344,7 @@ requires jQuery 1.6+
|
|
324
344
|
_selectValue(self);
|
325
345
|
list.hide();
|
326
346
|
});
|
327
|
-
}
|
347
|
+
}
|
328
348
|
|
329
349
|
function _generateBaseDate()
|
330
350
|
{
|
@@ -344,13 +364,16 @@ requires jQuery 1.6+
|
|
344
364
|
|
345
365
|
var settings = self.data('timepicker-settings');
|
346
366
|
var out = false;
|
367
|
+
var halfStep = settings.step*30;
|
347
368
|
|
348
369
|
// loop through the menu items
|
349
370
|
list.find('li').each(function(i, obj) {
|
350
371
|
var jObj = $(obj);
|
351
372
|
|
373
|
+
var offset = jObj.data('time') - value;
|
374
|
+
|
352
375
|
// check if the value is less than half a step from each row
|
353
|
-
if (Math.abs(
|
376
|
+
if (Math.abs(offset) < halfStep || offset == halfStep) {
|
354
377
|
out = jObj;
|
355
378
|
return false;
|
356
379
|
}
|
@@ -370,19 +393,33 @@ requires jQuery 1.6+
|
|
370
393
|
|
371
394
|
function _formatValue()
|
372
395
|
{
|
373
|
-
if (this.value
|
396
|
+
if (this.value === '') {
|
374
397
|
return;
|
375
398
|
}
|
376
399
|
|
377
400
|
var self = $(this);
|
378
|
-
var
|
401
|
+
var seconds = _time2int(this.value);
|
379
402
|
|
380
|
-
if (
|
403
|
+
if (seconds === null) {
|
381
404
|
self.trigger('timeFormatError');
|
382
405
|
return;
|
383
406
|
}
|
384
407
|
|
385
|
-
var
|
408
|
+
var settings = self.data('timepicker-settings');
|
409
|
+
|
410
|
+
if (settings.forceRoundTime) {
|
411
|
+
var offset = seconds % (settings.step*60); // step is in minutes
|
412
|
+
|
413
|
+
if (offset >= settings.step*30) {
|
414
|
+
// if offset is larger than a half step, round up
|
415
|
+
seconds += (settings.step*60) - offset;
|
416
|
+
} else {
|
417
|
+
// round down
|
418
|
+
seconds -= offset;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
|
422
|
+
var prettyTime = _int2time(seconds, settings.timeFormat);
|
386
423
|
self.val(prettyTime);
|
387
424
|
}
|
388
425
|
|
@@ -397,7 +434,7 @@ requires jQuery 1.6+
|
|
397
434
|
} else {
|
398
435
|
return true;
|
399
436
|
}
|
400
|
-
}
|
437
|
+
}
|
401
438
|
|
402
439
|
switch (e.keyCode) {
|
403
440
|
|
@@ -406,13 +443,11 @@ requires jQuery 1.6+
|
|
406
443
|
methods.hide.apply(this);
|
407
444
|
e.preventDefault();
|
408
445
|
return false;
|
409
|
-
break;
|
410
446
|
|
411
447
|
case 38: // up
|
412
448
|
var selected = list.find('.ui-timepicker-selected');
|
413
449
|
|
414
450
|
if (!selected.length) {
|
415
|
-
var selected;
|
416
451
|
list.children().each(function(i, obj) {
|
417
452
|
if ($(obj).position().top > 0) {
|
418
453
|
selected = $(obj);
|
@@ -433,10 +468,9 @@ requires jQuery 1.6+
|
|
433
468
|
break;
|
434
469
|
|
435
470
|
case 40: // down
|
436
|
-
|
471
|
+
selected = list.find('.ui-timepicker-selected');
|
437
472
|
|
438
|
-
if (selected.length
|
439
|
-
var selected;
|
473
|
+
if (selected.length === 0) {
|
440
474
|
list.children().each(function(i, obj) {
|
441
475
|
if ($(obj).position().top > 0) {
|
442
476
|
selected = $(obj);
|
@@ -483,11 +517,11 @@ requires jQuery 1.6+
|
|
483
517
|
list.find('li').removeClass('ui-timepicker-selected');
|
484
518
|
return;
|
485
519
|
}
|
486
|
-
}
|
520
|
+
}
|
487
521
|
|
488
522
|
function _selectValue(self)
|
489
523
|
{
|
490
|
-
var settings = self.data('timepicker-settings')
|
524
|
+
var settings = self.data('timepicker-settings');
|
491
525
|
var list = self.data('timepicker-list');
|
492
526
|
var timeValue = null;
|
493
527
|
|
@@ -495,12 +529,12 @@ requires jQuery 1.6+
|
|
495
529
|
|
496
530
|
if (cursor.length) {
|
497
531
|
// selected value found
|
498
|
-
|
532
|
+
timeValue = cursor.data('time');
|
499
533
|
|
500
534
|
} else if (self.val()) {
|
501
535
|
|
502
536
|
// no selected value; fall back on input value
|
503
|
-
|
537
|
+
timeValue = _time2int(self.val());
|
504
538
|
|
505
539
|
_setSelected(self, list);
|
506
540
|
}
|
@@ -511,14 +545,14 @@ requires jQuery 1.6+
|
|
511
545
|
}
|
512
546
|
|
513
547
|
self.trigger('change').trigger('changeTime');
|
514
|
-
}
|
548
|
+
}
|
515
549
|
|
516
550
|
function _int2duration(seconds)
|
517
551
|
{
|
518
552
|
var minutes = Math.round(seconds/60);
|
519
553
|
var duration;
|
520
554
|
|
521
|
-
if (minutes < 60) {
|
555
|
+
if (Math.abs(minutes) < 60) {
|
522
556
|
duration = [minutes, _lang.mins];
|
523
557
|
} else if (minutes == 60) {
|
524
558
|
duration = ['1', _lang.hr];
|
@@ -529,7 +563,7 @@ requires jQuery 1.6+
|
|
529
563
|
}
|
530
564
|
|
531
565
|
return duration.join(' ');
|
532
|
-
}
|
566
|
+
}
|
533
567
|
|
534
568
|
function _int2time(seconds, format)
|
535
569
|
{
|
@@ -539,10 +573,11 @@ requires jQuery 1.6+
|
|
539
573
|
|
540
574
|
var time = new Date(_baseDate.valueOf() + (seconds*1000));
|
541
575
|
var output = '';
|
576
|
+
var hour, code;
|
542
577
|
|
543
578
|
for (var i=0; i<format.length; i++) {
|
544
579
|
|
545
|
-
|
580
|
+
code = format.charAt(i);
|
546
581
|
switch (code) {
|
547
582
|
|
548
583
|
case 'a':
|
@@ -554,8 +589,8 @@ requires jQuery 1.6+
|
|
554
589
|
break;
|
555
590
|
|
556
591
|
case 'g':
|
557
|
-
|
558
|
-
output += (hour
|
592
|
+
hour = time.getHours() % 12;
|
593
|
+
output += (hour === 0) ? '12' : hour;
|
559
594
|
break;
|
560
595
|
|
561
596
|
case 'G':
|
@@ -563,17 +598,17 @@ requires jQuery 1.6+
|
|
563
598
|
break;
|
564
599
|
|
565
600
|
case 'h':
|
566
|
-
|
601
|
+
hour = time.getHours() % 12;
|
567
602
|
|
568
|
-
if (hour
|
603
|
+
if (hour !== 0 && hour < 10) {
|
569
604
|
hour = '0'+hour;
|
570
605
|
}
|
571
606
|
|
572
|
-
output += (hour
|
607
|
+
output += (hour === 0) ? '12' : hour;
|
573
608
|
break;
|
574
609
|
|
575
610
|
case 'H':
|
576
|
-
|
611
|
+
hour = time.getHours();
|
577
612
|
output += (hour > 9) ? hour : '0'+hour;
|
578
613
|
break;
|
579
614
|
|
@@ -583,7 +618,7 @@ requires jQuery 1.6+
|
|
583
618
|
break;
|
584
619
|
|
585
620
|
case 's':
|
586
|
-
|
621
|
+
seconds = time.getSeconds();
|
587
622
|
output += (seconds > 9) ? seconds : '0'+seconds;
|
588
623
|
break;
|
589
624
|
|
@@ -593,11 +628,11 @@ requires jQuery 1.6+
|
|
593
628
|
}
|
594
629
|
|
595
630
|
return output;
|
596
|
-
}
|
631
|
+
}
|
597
632
|
|
598
633
|
function _time2int(timeString)
|
599
634
|
{
|
600
|
-
if (timeString
|
635
|
+
if (timeString === '') return null;
|
601
636
|
if (timeString+0 == timeString) return timeString;
|
602
637
|
|
603
638
|
if (typeof(timeString) == 'object') {
|
@@ -605,29 +640,30 @@ requires jQuery 1.6+
|
|
605
640
|
}
|
606
641
|
|
607
642
|
var d = new Date(0);
|
608
|
-
var time = timeString.toLowerCase().match(/(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*([pa]?)/);
|
643
|
+
var time = timeString.toLowerCase().match(/(\d{1,2})(?::(\d{1,2}))?(?::(\d{2}))?\s*([pa]?)/);
|
609
644
|
|
610
645
|
if (!time) {
|
611
646
|
return null;
|
612
647
|
}
|
613
648
|
|
614
|
-
var hour = parseInt(time[1]*1);
|
649
|
+
var hour = parseInt(time[1]*1, 10);
|
650
|
+
var hours;
|
615
651
|
|
616
652
|
if (time[4]) {
|
617
653
|
if (hour == 12) {
|
618
|
-
|
654
|
+
hours = (time[4] == 'p') ? 12 : 0;
|
619
655
|
} else {
|
620
|
-
|
656
|
+
hours = (hour + (time[4] == 'p' ? 12 : 0));
|
621
657
|
}
|
622
658
|
|
623
659
|
} else {
|
624
|
-
|
660
|
+
hours = hour;
|
625
661
|
}
|
626
662
|
|
627
663
|
var minutes = ( time[2]*1 || 0 );
|
628
664
|
var seconds = ( time[3]*1 || 0 );
|
629
665
|
return hours*3600 + minutes*60 + seconds;
|
630
|
-
}
|
666
|
+
}
|
631
667
|
|
632
668
|
// Plugin entry
|
633
669
|
$.fn.timepicker = function(method)
|
@@ -636,4 +672,4 @@ requires jQuery 1.6+
|
|
636
672
|
else if(typeof method === "object" || !method) { return methods.init.apply(this, arguments); }
|
637
673
|
else { $.error("Method "+ method + " does not exist on jQuery.timepicker"); }
|
638
674
|
};
|
639
|
-
})
|
675
|
+
}));
|
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: 0.0
|
4
|
+
version: 0.1.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:
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
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:
|
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.
|
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
|