parallel588-bootstrap-timepicker-rails 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ bootstrap-timepicker-src
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Bootstrap Timepicker for Rails
2
+ This is the gemified version of https://github.com/jdewit/bootstrap-timepicker
3
+
4
+ bootstrap-timepicker-rails project integrates Timepicker with Rails 3 assets pipeline.
5
+
6
+ ## Rails > 3.1
7
+ Include bootstrap-timepicker-rails in Gemfile;
8
+
9
+ ``` ruby
10
+ gem 'bootstrap-timepicker-rails'
11
+ ```
12
+
13
+ or you can install from latest build;
14
+
15
+ ``` ruby
16
+ gem 'bootstrap-timepicker-rails', :require => 'bootstrap-timepicker-rails',
17
+ :git => 'git://github.com/tispratik/bootstrap-timepicker-rails.git'
18
+ ```
19
+
20
+ and run bundle install.
21
+
22
+ ## Configuration
23
+
24
+ Add this line to app/assets/stylesheets/application.css
25
+
26
+ ``` css
27
+ *= require bootstrap-timepicker
28
+ ```
29
+
30
+ Add this line to app/assets/javascripts/application.js
31
+
32
+ ``` javascript
33
+ //= require bootstrap-timepicker
34
+ ```
35
+
36
+ ## Using bootstrap-timepicker-rails
37
+
38
+ Just call timepicker() with any selector.
39
+
40
+ ```javascript
41
+ $('.timepicker').timepicker()
42
+ ```
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+ require File.expand_path('../lib/bootstrap-timepicker-rails/version', __FILE__)
3
+
4
+ desc "Update assets"
5
+ task 'update' do
6
+ system("rm -rf bootstrap-timepicker-src")
7
+ system("git clone git://github.com/jdewit/bootstrap-timepicker.git bootstrap-timepicker-src")
8
+ system("cp bootstrap-timepicker-src/less/timepicker.less vendor/assets/stylesheets/bootstrap-timepicker.less")
9
+ system("lessc vendor/assets/stylesheets/bootstrap-timepicker.less > vendor/assets/stylesheets/bootstrap-timepicker.css")
10
+ system("cp bootstrap-timepicker-src/js/bootstrap-timepicker.js vendor/assets/javascripts/bootstrap-timepicker.js")
11
+ system("git status")
12
+ end
13
+
14
+ desc "Build the gem"
15
+ task "build" do
16
+ system("gem build bootstrap-timepicker-rails.gemspec")
17
+ end
18
+
19
+ desc "Publish the gem"
20
+ task 'publish' do
21
+ system("gem push bootstrap-timepicker-rails-#{BootstrapTimepickerRails::Rails::VERSION}.gem")
22
+ system("git push")
23
+ end
24
+
25
+ desc "Build and publish the gem"
26
+ task "release" do
27
+ system("gem build bootstrap-timepicker-rails.gemspec")
28
+ system("gem push bootstrap-timepicker-rails-#{BootstrapTimepickerRails::Rails::VERSION}.gem")
29
+ system("git push")
30
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bootstrap-timepicker-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Pratik Khadloya"]
6
+ gem.email = ["tispratik@gmail.com"]
7
+ gem.description = %q{Gemified https://github.com/parallel588/bootstrap-timepicker-rails}
8
+ gem.homepage = "https://github.com/parallel588/bootstrap-timepicker-rails"
9
+ gem.summary = gem.description
10
+
11
+ gem.name = "parallel588-bootstrap-timepicker-rails"
12
+ gem.require_paths = ["lib"]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.version = BootstrapTimepickerRails::Rails::VERSION
15
+
16
+ gem.add_dependency "railties", ">= 3.0"
17
+ gem.add_development_dependency "bundler", ">= 1.0"
18
+ gem.add_development_dependency "rake"
19
+ end
@@ -0,0 +1,12 @@
1
+ require "rails"
2
+ require "bootstrap-timepicker-rails/version"
3
+
4
+ module BootstrapTimepickerRails
5
+ module Rails
6
+ if ::Rails.version < "3.1"
7
+ require "bootstrap-timepicker-rails/railtie"
8
+ else
9
+ require "bootstrap-timepicker-rails/engine"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module BootstrapTimepickerRails
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module BootstrapTimepickerRails
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module BootstrapTimepickerRails
2
+ module Rails
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -0,0 +1,804 @@
1
+ /* =========================================================
2
+ * bootstrap-timepicker.js
3
+ * http://www.github.com/jdewit/bootstrap-timepicker
4
+ * =========================================================
5
+ * Copyright 2012
6
+ *
7
+ * Created By:
8
+ * Joris de Wit @joris_dewit
9
+ *
10
+ * Contributions By:
11
+ * Gilbert @mindeavor
12
+ * Koen Punt info@koenpunt.nl
13
+ * Nek
14
+ * Chris Martin
15
+ * Dominic Barnes contact@dominicbarnes.us
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
28
+ * ========================================================= */
29
+
30
+ !function($) {
31
+
32
+ "use strict"; // jshint ;_;
33
+
34
+ /* TIMEPICKER PUBLIC CLASS DEFINITION
35
+ * ================================== */
36
+ var Timepicker = function(element, options) {
37
+ this.$element = $(element);
38
+ this.options = $.extend({}, $.fn.timepicker.defaults, options, this.$element.data());
39
+ this.minuteStep = this.options.minuteStep || this.minuteStep;
40
+ this.secondStep = this.options.secondStep || this.secondStep;
41
+ this.showMeridian = this.options.showMeridian || this.showMeridian;
42
+ this.showSeconds = this.options.showSeconds || this.showSeconds;
43
+ this.showInputs = this.options.showInputs || this.showInputs;
44
+ this.disableFocus = this.options.disableFocus || this.disableFocus;
45
+ this.template = this.options.template || this.template;
46
+ this.modalBackdrop = this.options.modalBackdrop || this.modalBackdrop;
47
+ this.defaultTime = this.options.defaultTime || this.defaultTime;
48
+ this.open = false;
49
+ this.init();
50
+ };
51
+
52
+ Timepicker.prototype = {
53
+
54
+ constructor: Timepicker
55
+
56
+ , init: function () {
57
+ if (this.$element.parent().hasClass('input-append')) {
58
+ this.$element.parent('.input-append').find('.add-on').on('click', $.proxy(this.showWidget, this));
59
+ this.$element.on({
60
+ focus: $.proxy(this.highlightUnit, this),
61
+ click: $.proxy(this.highlightUnit, this),
62
+ keypress: $.proxy(this.elementKeypress, this),
63
+ blur: $.proxy(this.blurElement, this)
64
+ });
65
+
66
+ } else {
67
+ if (this.template) {
68
+ this.$element.on({
69
+ focus: $.proxy(this.showWidget, this),
70
+ click: $.proxy(this.showWidget, this),
71
+ blur: $.proxy(this.blurElement, this)
72
+ });
73
+ } else {
74
+ this.$element.on({
75
+ focus: $.proxy(this.highlightUnit, this),
76
+ click: $.proxy(this.highlightUnit, this),
77
+ keypress: $.proxy(this.elementKeypress, this),
78
+ blur: $.proxy(this.blurElement, this)
79
+ });
80
+ }
81
+ }
82
+
83
+
84
+ this.$widget = $(this.getTemplate()).appendTo('body');
85
+
86
+ this.$widget.on('click', $.proxy(this.widgetClick, this));
87
+
88
+ if (this.showInputs) {
89
+ this.$widget.find('input').on({
90
+ click: function() { this.select(); },
91
+ keypress: $.proxy(this.widgetKeypress, this),
92
+ change: $.proxy(this.updateFromWidgetInputs, this)
93
+ });
94
+ }
95
+
96
+ this.setDefaultTime(this.defaultTime);
97
+ }
98
+
99
+ , showWidget: function(e) {
100
+ e.stopPropagation();
101
+ e.preventDefault();
102
+
103
+ if (this.open) {
104
+ return;
105
+ }
106
+
107
+ this.$element.trigger('show');
108
+
109
+ if (this.disableFocus) {
110
+ this.$element.blur();
111
+ }
112
+
113
+ var pos = $.extend({}, this.$element.offset(), {
114
+ height: this.$element[0].offsetHeight
115
+ });
116
+
117
+ this.updateFromElementVal();
118
+
119
+ $('html')
120
+ .trigger('click.timepicker.data-api')
121
+ .one('click.timepicker.data-api', $.proxy(this.hideWidget, this));
122
+
123
+ if (this.template === 'modal') {
124
+ this.$widget.modal('show').on('hidden', $.proxy(this.hideWidget, this));
125
+ } else {
126
+ this.$widget.css({
127
+ top: pos.top + pos.height
128
+ , left: pos.left
129
+ })
130
+
131
+ if (!this.open) {
132
+ this.$widget.addClass('open');
133
+ }
134
+ }
135
+
136
+ this.open = true;
137
+ this.$element.trigger('shown');
138
+ }
139
+
140
+ , hideWidget: function(){
141
+ this.$element.trigger('hide');
142
+
143
+ if (this.template === 'modal') {
144
+ this.$widget.modal('hide');
145
+ } else {
146
+ this.$widget.removeClass('open');
147
+ }
148
+ this.open = false;
149
+ this.$element.trigger('hidden');
150
+ }
151
+
152
+ , widgetClick: function(e) {
153
+ e.stopPropagation();
154
+ e.preventDefault();
155
+
156
+ var action = $(e.target).closest('a').data('action');
157
+ if (action) {
158
+ this[action]();
159
+ this.update();
160
+ }
161
+ }
162
+
163
+ , widgetKeypress: function(e) {
164
+ var input = $(e.target).closest('input').attr('name');
165
+
166
+ switch (e.keyCode) {
167
+ case 9: //tab
168
+ if (this.showMeridian) {
169
+ if (input == 'meridian') {
170
+ this.hideWidget();
171
+ }
172
+ } else {
173
+ if (this.showSeconds) {
174
+ if (input == 'second') {
175
+ this.hideWidget();
176
+ }
177
+ } else {
178
+ if (input == 'minute') {
179
+ this.hideWidget();
180
+ }
181
+ }
182
+ }
183
+ break;
184
+ case 27: // escape
185
+ this.hideWidget();
186
+ break;
187
+ case 38: // up arrow
188
+ switch (input) {
189
+ case 'hour':
190
+ this.incrementHour();
191
+ break;
192
+ case 'minute':
193
+ this.incrementMinute();
194
+ break;
195
+ case 'second':
196
+ this.incrementSecond();
197
+ break;
198
+ case 'meridian':
199
+ this.toggleMeridian();
200
+ break;
201
+ }
202
+ this.update();
203
+ break;
204
+ case 40: // down arrow
205
+ switch (input) {
206
+ case 'hour':
207
+ this.decrementHour();
208
+ break;
209
+ case 'minute':
210
+ this.decrementMinute();
211
+ break;
212
+ case 'second':
213
+ this.decrementSecond();
214
+ break;
215
+ case 'meridian':
216
+ this.toggleMeridian();
217
+ break;
218
+ }
219
+ this.update();
220
+ break;
221
+ }
222
+ }
223
+
224
+ , elementKeypress: function(e) {
225
+ var input = this.$element.get(0);
226
+ switch (e.keyCode) {
227
+ case 0: //input
228
+ break;
229
+ case 9: //tab
230
+ this.updateFromElementVal();
231
+ if (this.showMeridian) {
232
+ if (this.highlightedUnit != 'meridian') {
233
+ e.preventDefault();
234
+ this.highlightNextUnit();
235
+ }
236
+ } else {
237
+ if (this.showSeconds) {
238
+ if (this.highlightedUnit != 'second') {
239
+ e.preventDefault();
240
+ this.highlightNextUnit();
241
+ }
242
+ } else {
243
+ if (this.highlightedUnit != 'minute') {
244
+ e.preventDefault();
245
+ this.highlightNextUnit();
246
+ }
247
+ }
248
+ }
249
+ break;
250
+ case 27: // escape
251
+ this.updateFromElementVal();
252
+ break;
253
+ case 37: // left arrow
254
+ this.updateFromElementVal();
255
+ this.highlightPrevUnit();
256
+ break;
257
+ case 38: // up arrow
258
+ switch (this.highlightedUnit) {
259
+ case 'hour':
260
+ this.incrementHour();
261
+ break;
262
+ case 'minute':
263
+ this.incrementMinute();
264
+ break;
265
+ case 'second':
266
+ this.incrementSecond();
267
+ break;
268
+ case 'meridian':
269
+ this.toggleMeridian();
270
+ break;
271
+ }
272
+ this.updateElement();
273
+ break;
274
+ case 39: // right arrow
275
+ this.updateFromElementVal();
276
+ this.highlightNextUnit();
277
+ break;
278
+ case 40: // down arrow
279
+ switch (this.highlightedUnit) {
280
+ case 'hour':
281
+ this.decrementHour();
282
+ break;
283
+ case 'minute':
284
+ this.decrementMinute();
285
+ break;
286
+ case 'second':
287
+ this.decrementSecond();
288
+ break;
289
+ case 'meridian':
290
+ this.toggleMeridian();
291
+ break;
292
+ }
293
+ this.updateElement();
294
+ break;
295
+ }
296
+
297
+ if (e.keyCode !== 0 && e.keyCode !== 8 && e.keyCode !== 9 && e.keyCode !== 46) {
298
+ e.preventDefault();
299
+ }
300
+ }
301
+
302
+ , setValues: function(time) {
303
+ if (this.showMeridian) {
304
+ var arr = time.split(' ');
305
+ var timeArray = arr[0].split(':');
306
+ this.meridian = arr[1];
307
+ } else {
308
+ var timeArray = time.split(':');
309
+ }
310
+
311
+ this.hour = parseInt(timeArray[0], 10);
312
+ this.minute = parseInt(timeArray[1], 10);
313
+ this.second = parseInt(timeArray[2], 10);
314
+
315
+ if (isNaN(this.hour)) {
316
+ this.hour = 0;
317
+ }
318
+ if (isNaN(this.minute)) {
319
+ this.minute = 0;
320
+ }
321
+
322
+ if (this.showMeridian) {
323
+ if (this.hour > 12) {
324
+ this.hour = 12;
325
+ } else if (this.hour < 1) {
326
+ this.hour = 1;
327
+ }
328
+
329
+ if (this.meridian == 'am' || this.meridian == 'a') {
330
+ this.meridian = 'AM';
331
+ } else if (this.meridian == 'pm' || this.meridian == 'p') {
332
+ this.meridian = 'PM';
333
+ }
334
+
335
+ if (this.meridian != 'AM' && this.meridian != 'PM') {
336
+ this.meridian = 'AM';
337
+ }
338
+ } else {
339
+ if (this.hour >= 24) {
340
+ this.hour = 23;
341
+ } else if (this.hour < 0) {
342
+ this.hour = 0;
343
+ }
344
+ }
345
+
346
+ if (this.minute < 0) {
347
+ this.minute = 0;
348
+ } else if (this.minute >= 60) {
349
+ this.minute = 59;
350
+ }
351
+
352
+ if (this.showSeconds) {
353
+ if (isNaN(this.second)) {
354
+ this.second = 0;
355
+ } else if (this.second < 0) {
356
+ this.second = 0;
357
+ } else if (this.second >= 60) {
358
+ this.second = 59;
359
+ }
360
+ }
361
+
362
+ this.updateElement();
363
+ this.updateWidget();
364
+ }
365
+
366
+ , setMeridian: function(meridian) {
367
+ if (meridian == 'a' || meridian == 'am' || meridian == 'AM' ) {
368
+ this.meridian = 'AM';
369
+ } else if (meridian == 'p' || meridian == 'pm' || meridian == 'PM' ) {
370
+ this.meridian = 'PM';
371
+ } else {
372
+ this.updateWidget();
373
+ }
374
+
375
+ this.updateElement();
376
+ }
377
+
378
+ , setDefaultTime: function(defaultTime){
379
+ if (defaultTime) {
380
+ if (defaultTime === 'current') {
381
+ var dTime = new Date();
382
+ var hours = dTime.getHours();
383
+ var minutes = Math.floor(dTime.getMinutes() / this.minuteStep) * this.minuteStep;
384
+ var seconds = Math.floor(dTime.getSeconds() / this.secondStep) * this.secondStep;
385
+ var meridian = "AM";
386
+ if (this.showMeridian) {
387
+ if (hours === 0) {
388
+ hours = 12;
389
+ } else if (hours >= 12) {
390
+ if (hours > 12) {
391
+ hours = hours - 12;
392
+ }
393
+ meridian = "PM";
394
+ } else {
395
+ meridian = "AM";
396
+ }
397
+ }
398
+ this.hour = hours;
399
+ this.minute = minutes;
400
+ this.second = seconds;
401
+ this.meridian = meridian;
402
+ } else if (defaultTime === 'value') {
403
+ this.setValues(this.$element.val());
404
+ } else {
405
+ this.setValues(defaultTime);
406
+ }
407
+ this.update();
408
+ } else {
409
+ this.hour = 0;
410
+ this.minute = 0;
411
+ this.second = 0;
412
+ }
413
+ }
414
+
415
+ , formatTime: function(hour, minute, second, meridian) {
416
+ hour = hour < 10 ? '0' + hour : hour;
417
+ minute = minute < 10 ? '0' + minute : minute;
418
+ second = second < 10 ? '0' + second : second;
419
+
420
+ return hour + ':' + minute + (this.showSeconds ? ':' + second : '') + (this.showMeridian ? ' ' + meridian : '');
421
+ }
422
+
423
+ , getTime: function() {
424
+ return this.formatTime(this.hour, this.minute, this.second, this.meridian);
425
+ }
426
+
427
+ , setTime: function(time) {
428
+ this.setValues(time);
429
+ this.update();
430
+ }
431
+
432
+ , update: function() {
433
+ this.updateElement();
434
+ this.updateWidget();
435
+ this.$element.trigger({
436
+ type: 'changeTime',
437
+ time: this.time
438
+ });
439
+ }
440
+
441
+ , blurElement: function() {
442
+ this.highlightedUnit = undefined;
443
+ this.updateFromElementVal();
444
+ }
445
+
446
+ , updateElement: function() {
447
+ var time = this.getTime();
448
+
449
+ this.$element.val(time).change();
450
+
451
+ switch (this.highlightedUnit) {
452
+ case 'hour':
453
+ this.highlightHour();
454
+ break;
455
+ case 'minute':
456
+ this.highlightMinute();
457
+ break;
458
+ case 'second':
459
+ this.highlightSecond();
460
+ break;
461
+ case 'meridian':
462
+ this.highlightMeridian();
463
+ break;
464
+ }
465
+ }
466
+
467
+ , updateWidget: function() {
468
+ if (this.showInputs) {
469
+ this.$widget.find('input.bootstrap-timepicker-hour').val(this.hour < 10 ? '0' + this.hour : this.hour);
470
+ this.$widget.find('input.bootstrap-timepicker-minute').val(this.minute < 10 ? '0' + this.minute : this.minute);
471
+ if (this.showSeconds) {
472
+ this.$widget.find('input.bootstrap-timepicker-second').val(this.second < 10 ? '0' + this.second : this.second);
473
+ }
474
+ if (this.showMeridian) {
475
+ this.$widget.find('input.bootstrap-timepicker-meridian').val(this.meridian);
476
+ }
477
+ } else {
478
+ this.$widget.find('span.bootstrap-timepicker-hour').text(this.hour);
479
+ this.$widget.find('span.bootstrap-timepicker-minute').text(this.minute < 10 ? '0' + this.minute : this.minute);
480
+ if (this.showSeconds) {
481
+ this.$widget.find('span.bootstrap-timepicker-second').text(this.second < 10 ? '0' + this.second : this.second);
482
+ }
483
+ if (this.showMeridian) {
484
+ this.$widget.find('span.bootstrap-timepicker-meridian').text(this.meridian);
485
+ }
486
+ }
487
+ }
488
+
489
+ , updateFromElementVal: function (e) {
490
+ var time = this.$element.val();
491
+ if (time) {
492
+ this.setValues(time);
493
+ this.updateWidget();
494
+ }
495
+ }
496
+
497
+ , updateFromWidgetInputs: function () {
498
+ var time = $('input.bootstrap-timepicker-hour', this.$widget).val() + ':' +
499
+ $('input.bootstrap-timepicker-minute', this.$widget).val() +
500
+ (this.showSeconds ?
501
+ ':' + $('input.bootstrap-timepicker-second', this.$widget).val()
502
+ : '') +
503
+ (this.showMeridian ?
504
+ ' ' + $('input.bootstrap-timepicker-meridian', this.$widget).val()
505
+ : '');
506
+
507
+ this.setValues(time);
508
+ }
509
+
510
+ , getCursorPosition: function() {
511
+ var input = this.$element.get(0);
512
+
513
+ if ('selectionStart' in input) {
514
+ // Standard-compliant browsers
515
+ return input.selectionStart;
516
+ } else if (document.selection) {
517
+ // IE fix
518
+ input.focus();
519
+ var sel = document.selection.createRange();
520
+ var selLen = document.selection.createRange().text.length;
521
+ sel.moveStart('character', - input.value.length);
522
+
523
+ return sel.text.length - selLen;
524
+ }
525
+ }
526
+
527
+ , highlightUnit: function () {
528
+ var input = this.$element.get(0);
529
+
530
+ this.position = this.getCursorPosition();
531
+ if (this.position >= 0 && this.position <= 2) {
532
+ this.highlightHour();
533
+ } else if (this.position >= 3 && this.position <= 5) {
534
+ this.highlightMinute();
535
+ } else if (this.position >= 6 && this.position <= 8) {
536
+ if (this.showSeconds) {
537
+ this.highlightSecond();
538
+ } else {
539
+ this.highlightMeridian();
540
+ }
541
+ } else if (this.position >= 9 && this.position <= 11) {
542
+ this.highlightMeridian();
543
+ }
544
+ }
545
+
546
+ , highlightNextUnit: function() {
547
+ switch (this.highlightedUnit) {
548
+ case 'hour':
549
+ this.highlightMinute();
550
+ break;
551
+ case 'minute':
552
+ if (this.showSeconds) {
553
+ this.highlightSecond();
554
+ } else {
555
+ this.highlightMeridian();
556
+ }
557
+ break;
558
+ case 'second':
559
+ this.highlightMeridian();
560
+ break;
561
+ case 'meridian':
562
+ this.highlightHour();
563
+ break;
564
+ }
565
+ }
566
+
567
+ , highlightPrevUnit: function() {
568
+ switch (this.highlightedUnit) {
569
+ case 'hour':
570
+ this.highlightMeridian();
571
+ break;
572
+ case 'minute':
573
+ this.highlightHour();
574
+ break;
575
+ case 'second':
576
+ this.highlightMinute();
577
+ break;
578
+ case 'meridian':
579
+ if (this.showSeconds) {
580
+ this.highlightSecond();
581
+ } else {
582
+ this.highlightMinute();
583
+ }
584
+ break;
585
+ }
586
+ }
587
+
588
+ , highlightHour: function() {
589
+ this.highlightedUnit = 'hour';
590
+ this.$element.get(0).setSelectionRange(0,2);
591
+ }
592
+
593
+ , highlightMinute: function() {
594
+ this.highlightedUnit = 'minute';
595
+ this.$element.get(0).setSelectionRange(3,5);
596
+ }
597
+
598
+ , highlightSecond: function() {
599
+ this.highlightedUnit = 'second';
600
+ this.$element.get(0).setSelectionRange(6,8);
601
+ }
602
+
603
+ , highlightMeridian: function() {
604
+ this.highlightedUnit = 'meridian';
605
+ if (this.showSeconds) {
606
+ this.$element.get(0).setSelectionRange(9,11);
607
+ } else {
608
+ this.$element.get(0).setSelectionRange(6,8);
609
+ }
610
+ }
611
+
612
+ , incrementHour: function() {
613
+ if (this.showMeridian) {
614
+ if (this.hour === 11) {
615
+ this.toggleMeridian();
616
+ } else if (this.hour === 12) {
617
+ return this.hour = 1;
618
+ }
619
+ }
620
+ if (this.hour === 23) {
621
+ return this.hour = 0;
622
+ }
623
+ this.hour = this.hour + 1;
624
+ }
625
+
626
+ , decrementHour: function() {
627
+ if (this.showMeridian) {
628
+ if (this.hour === 1) {
629
+ return this.hour = 12;
630
+ }
631
+ else if (this.hour === 12) {
632
+ this.toggleMeridian();
633
+ }
634
+ }
635
+ if (this.hour === 0) {
636
+ return this.hour = 23;
637
+ }
638
+ this.hour = this.hour - 1;
639
+ }
640
+
641
+ , incrementMinute: function() {
642
+ var newVal = this.minute + this.minuteStep - (this.minute % this.minuteStep);
643
+ if (newVal > 59) {
644
+ this.incrementHour();
645
+ this.minute = newVal - 60;
646
+ } else {
647
+ this.minute = newVal;
648
+ }
649
+ }
650
+
651
+ , decrementMinute: function() {
652
+ var newVal = this.minute - this.minuteStep;
653
+ if (newVal < 0) {
654
+ this.decrementHour();
655
+ this.minute = newVal + 60;
656
+ } else {
657
+ this.minute = newVal;
658
+ }
659
+ }
660
+
661
+ , incrementSecond: function() {
662
+ var newVal = this.second + this.secondStep - (this.second % this.secondStep);
663
+ if (newVal > 59) {
664
+ this.incrementMinute();
665
+ this.second = newVal - 60;
666
+ } else {
667
+ this.second = newVal;
668
+ }
669
+ }
670
+
671
+ , decrementSecond: function() {
672
+ var newVal = this.second - this.secondStep;
673
+ if (newVal < 0) {
674
+ this.decrementMinute();
675
+ this.second = newVal + 60;
676
+ } else {
677
+ this.second = newVal;
678
+ }
679
+ }
680
+
681
+ , toggleMeridian: function() {
682
+ this.meridian = this.meridian === 'AM' ? 'PM' : 'AM';
683
+
684
+ this.update();
685
+ }
686
+
687
+ , getTemplate: function() {
688
+ if (this.options.templates[this.options.template]) {
689
+ return this.options.templates[this.options.template];
690
+ }
691
+ if (this.showInputs) {
692
+ var hourTemplate = '<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>';
693
+ var minuteTemplate = '<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>';
694
+ var secondTemplate = '<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>';
695
+ var meridianTemplate = '<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>';
696
+ } else {
697
+ var hourTemplate = '<span class="bootstrap-timepicker-hour"></span>';
698
+ var minuteTemplate = '<span class="bootstrap-timepicker-minute"></span>';
699
+ var secondTemplate = '<span class="bootstrap-timepicker-second"></span>';
700
+ var meridianTemplate = '<span class="bootstrap-timepicker-meridian"></span>';
701
+ }
702
+ var templateContent = '<table class="'+ (this.showSeconds ? 'show-seconds' : '') +' '+ (this.showMeridian ? 'show-meridian' : '') +'">'+
703
+ '<tr>'+
704
+ '<td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td>'+
705
+ '<td class="separator">&nbsp;</td>'+
706
+ '<td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+
707
+ (this.showSeconds ?
708
+ '<td class="separator">&nbsp;</td>'+
709
+ '<td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>'
710
+ : '') +
711
+ (this.showMeridian ?
712
+ '<td class="separator">&nbsp;</td>'+
713
+ '<td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>'
714
+ : '') +
715
+ '</tr>'+
716
+ '<tr>'+
717
+ '<td>'+ hourTemplate +'</td> '+
718
+ '<td class="separator">:</td>'+
719
+ '<td>'+ minuteTemplate +'</td> '+
720
+ (this.showSeconds ?
721
+ '<td class="separator">:</td>'+
722
+ '<td>'+ secondTemplate +'</td>'
723
+ : '') +
724
+ (this.showMeridian ?
725
+ '<td class="separator">&nbsp;</td>'+
726
+ '<td>'+ meridianTemplate +'</td>'
727
+ : '') +
728
+ '</tr>'+
729
+ '<tr>'+
730
+ '<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+
731
+ '<td class="separator"></td>'+
732
+ '<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+
733
+ (this.showSeconds ?
734
+ '<td class="separator">&nbsp;</td>'+
735
+ '<td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>'
736
+ : '') +
737
+ (this.showMeridian ?
738
+ '<td class="separator">&nbsp;</td>'+
739
+ '<td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>'
740
+ : '') +
741
+ '</tr>'+
742
+ '</table>';
743
+
744
+ var template;
745
+ switch(this.options.template) {
746
+ case 'modal':
747
+ template = '<div class="bootstrap-timepicker modal hide fade in" style="top: 30%; margin-top: 0; width: 200px; margin-left: -100px;" data-backdrop="'+ (this.modalBackdrop ? 'true' : 'false') +'">'+
748
+ '<div class="modal-header">'+
749
+ '<a href="#" class="close" data-dismiss="modal">×</a>'+
750
+ '<h3>Pick a Time</h3>'+
751
+ '</div>'+
752
+ '<div class="modal-content">'+
753
+ templateContent +
754
+ '</div>'+
755
+ '<div class="modal-footer">'+
756
+ '<a href="#" class="btn btn-primary" data-dismiss="modal">Ok</a>'+
757
+ '</div>'+
758
+ '</div>';
759
+
760
+ break;
761
+ case 'dropdown':
762
+ template = '<div class="bootstrap-timepicker dropdown-menu">'+
763
+ templateContent +
764
+ '</div>';
765
+ break;
766
+
767
+ }
768
+ return template;
769
+ }
770
+ };
771
+
772
+
773
+ /* TIMEPICKER PLUGIN DEFINITION
774
+ * =========================== */
775
+
776
+ $.fn.timepicker = function (option) {
777
+ return this.each(function () {
778
+ var $this = $(this)
779
+ , data = $this.data('timepicker')
780
+ , options = typeof option == 'object' && option;
781
+ if (!data) {
782
+ $this.data('timepicker', (data = new Timepicker(this, options)));
783
+ }
784
+ if (typeof option == 'string') {
785
+ data[option]();
786
+ }
787
+ })
788
+ }
789
+
790
+ $.fn.timepicker.defaults = {
791
+ minuteStep: 15
792
+ , secondStep: 15
793
+ , disableFocus: false
794
+ , defaultTime: 'current'
795
+ , showSeconds: false
796
+ , showInputs: true
797
+ , showMeridian: true
798
+ , template: 'dropdown'
799
+ , modalBackdrop: false
800
+ , templates: {} // set custom templates
801
+ }
802
+
803
+ $.fn.timepicker.Constructor = Timepicker
804
+ }(window.jQuery);
@@ -0,0 +1,81 @@
1
+ .bootstrap-timepicker.dropdown-menu {
2
+ border-radius: 4px 4px 4px 4px;
3
+ display: none;
4
+ left: 0;
5
+ margin-top: 1px;
6
+ padding: 4px;
7
+ top: 0;
8
+ min-width: 10px;
9
+ }
10
+ .bootstrap-timepicker.dropdown-menu.open {
11
+ display: inline-block;
12
+ }
13
+ .bootstrap-timepicker.dropdown-menu:before {
14
+ border-bottom: 7px solid rgba(0, 0, 0, 0.2);
15
+ border-left: 7px solid transparent;
16
+ border-right: 7px solid transparent;
17
+ content: "";
18
+ left: 6px;
19
+ position: absolute;
20
+ top: -7px;
21
+ }
22
+ .bootstrap-timepicker.dropdown-menu:after {
23
+ border-bottom: 6px solid #FFFFFF;
24
+ border-left: 6px solid transparent;
25
+ border-right: 6px solid transparent;
26
+ content: "";
27
+ left: 7px;
28
+ position: absolute;
29
+ top: -6px;
30
+ }
31
+ .bootstrap-timepicker.modal {
32
+ margin-left: -100px;
33
+ margin-top: 0;
34
+ top: 30%;
35
+ width: 200px;
36
+ }
37
+ .bootstrap-timepicker.modal .modal-content {
38
+ padding: 0;
39
+ }
40
+ .bootstrap-timepicker table {
41
+ margin: 0;
42
+ width: 100%;
43
+ }
44
+ .bootstrap-timepicker table td {
45
+ height: 30px;
46
+ margin: 0;
47
+ padding: 2px;
48
+ text-align: center;
49
+ }
50
+ .bootstrap-timepicker table td span {
51
+ width: 100%;
52
+ }
53
+ .bootstrap-timepicker table td a {
54
+ border: 1px solid transparent;
55
+ display: inline-block;
56
+ margin: 0;
57
+ outline: 0 none;
58
+ padding: 8px 0;
59
+ width: 3em;
60
+ }
61
+ .bootstrap-timepicker table td a:hover {
62
+ background-color: #EEEEEE;
63
+ border-color: #DDDDDD;
64
+ border-radius: 4px 4px 4px 4px;
65
+ }
66
+ .bootstrap-timepicker table td a i {
67
+ margin-top: 2px;
68
+ }
69
+ .bootstrap-timepicker table td input {
70
+ margin: 0;
71
+ text-align: center;
72
+ width: 25px;
73
+ }
74
+ .bootstrap-timepicker-component .add-on {
75
+ cursor: pointer;
76
+ }
77
+ .bootstrap-timepicker-component .add-on i {
78
+ display: block;
79
+ height: 16px;
80
+ width: 16px;
81
+ }
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parallel588-bootstrap-timepicker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pratik Khadloya
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Gemified https://github.com/parallel588/bootstrap-timepicker-rails
63
+ email:
64
+ - tispratik@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - bootstrap-timepicker-rails.gemspec
74
+ - lib/bootstrap-timepicker-rails.rb
75
+ - lib/bootstrap-timepicker-rails/engine.rb
76
+ - lib/bootstrap-timepicker-rails/railtie.rb
77
+ - lib/bootstrap-timepicker-rails/version.rb
78
+ - vendor/assets/javascripts/bootstrap-timepicker.js
79
+ - vendor/assets/stylesheets/bootstrap-timepicker.css
80
+ homepage: https://github.com/parallel588/bootstrap-timepicker-rails
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Gemified https://github.com/parallel588/bootstrap-timepicker-rails
104
+ test_files: []