bootstrap-datepicker-rails 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.gem
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
@@ -0,0 +1,196 @@
1
+ # Bootstrap Datepicker for Rails
2
+ Bootstrap is a toolkit from Twitter designed to kickstart development of webapps and sites.
3
+ It includes base CSS and HTML for typography, forms, buttons, tables, grids, navigation, and more.
4
+
5
+ http://twitter.github.com/bootstrap/
6
+
7
+ Bootstrap Datepicker is a plugin for Bootstrap designed by Stefan Petre. It provides a stylish date picker for Bootstrap.
8
+
9
+ http://www.eyecon.ro/bootstrap-datepicker/
10
+
11
+ bootstrap-datepicker-rails project integrates Datepicker with Rails 3 assets pipeline.
12
+
13
+ http://github.com/Nerian/bootstrap-datepicker-rails
14
+
15
+ ## Rails > 3.1
16
+ Include bootstrap-datepicker-rails in Gemfile;
17
+
18
+ ``` ruby
19
+ gem 'bootstrap-datepicker-rails'
20
+ ```
21
+
22
+ or you can install from latest build;
23
+
24
+ ``` ruby
25
+ gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails',
26
+ :git => 'git://github.com/Nerian/bootstrap-datepicker-rails.git'
27
+ ```
28
+
29
+ and run bundle install.
30
+
31
+ ## Stylesheets
32
+
33
+ Add necessary stylesheet file to app/assets/stylesheets/application.css
34
+
35
+ ``` css
36
+ *=bootstrap-datepicker
37
+ ```
38
+
39
+ ## Javascripts
40
+
41
+ Add necessary javascript(s) files to app/assets/javascripts/application.js
42
+
43
+ ``` javascript
44
+ //= require bootstrap-datepicker
45
+ ```
46
+
47
+ ## Using bootstrap-datepicker-rails
48
+
49
+ Just call datepicker() with any selector.
50
+
51
+ ```javascript
52
+ $('.datepicker').datepicker()
53
+ ```
54
+
55
+ ### Options
56
+
57
+ #### format
58
+
59
+ String. Default: 'mm/dd/yyyy'
60
+
61
+ The date format, combination of d, dd, m, mm, yy, yyy.
62
+
63
+ #### weekStart
64
+
65
+ Integer. Default: 0
66
+
67
+ Day of the week start. 0 (Sunday) to 6 (Saturday)
68
+
69
+ #### startDate
70
+
71
+ String. Default: Beginning of time
72
+
73
+ The earliest date that may be selected; all earlier dates will be disabled.
74
+
75
+ #### endDate
76
+
77
+ String. Default: End of time
78
+
79
+ The latest date that may be selected; all later dates will be disabled.
80
+
81
+ ### Markup
82
+
83
+ Format a component.
84
+
85
+ ```html
86
+ <div class="input-append date" id="datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
87
+ <input class="span2" size="16" type="text" value="12-02-2012">
88
+ <span class="add-on"><i class="icon-th"></i></span>
89
+ </div>
90
+ ```
91
+
92
+ ### Methods
93
+
94
+ #### .datepicker(options)
95
+
96
+ Initializes an datepicker.
97
+
98
+ #### show
99
+
100
+ Arguments: None
101
+
102
+ Show the datepicker.
103
+
104
+ ```javascript
105
+ $('#datepicker').datepicker('show');
106
+ ```
107
+
108
+ #### hide
109
+
110
+ Arguments: None
111
+
112
+ Hide the datepicker.
113
+
114
+ ```javascript
115
+ $('#datepicker').datepicker('hide');
116
+ ```
117
+
118
+ #### update
119
+
120
+ Arguments: None
121
+
122
+ Update the datepicker with the current input value.
123
+
124
+ ```javascript
125
+ $('#datepicker').datepicker('update');
126
+ ```
127
+
128
+ #### setStartDate
129
+
130
+ Arguments:
131
+
132
+ * startDate (String)
133
+
134
+ Sets a new lower date limit on the datepicker.
135
+
136
+ ```javascript
137
+ $('#datepicker').datepicker('setStartDate', '2012-01-01');
138
+ ```
139
+ Omit startDate (or provide an otherwise falsey value) to unset the limit.
140
+
141
+ ```javascript
142
+ $('#datepicker').datepicker('setStartDate');
143
+ $('#datepicker').datepicker('setStartDate', null);
144
+ ```
145
+
146
+ #### setEndDate
147
+
148
+ Arguments:
149
+
150
+ * endDate (String)
151
+
152
+ Sets a new upper date limit on the datepicker.
153
+
154
+ ```javascript
155
+ $('#datepicker').datepicker('setEndDate', '2012-12-31');
156
+ ```
157
+
158
+ Omit endDate (or provide an otherwise falsey value) to unset the limit.
159
+
160
+ ```javascript
161
+ $('#datepicker').datepicker('setEndDate');
162
+ $('#datepicker').datepicker('setEndDate', null);
163
+ ```
164
+
165
+ ### Events
166
+
167
+ Datepicker class exposes a few events for manipulating the dates.
168
+
169
+ #### show
170
+
171
+ Fired when the date picker is displayed.
172
+
173
+ #### hide
174
+
175
+ Fired when the date picker is hidden.
176
+
177
+ #### changeDate
178
+
179
+ Fired when the date is changed.
180
+
181
+ ```javascript
182
+ $('#date-end')
183
+ .datepicker()
184
+ .on('changeDate', function(ev){
185
+ if (ev.date.valueOf() < date-start-display.valueOf()){
186
+ ....
187
+ }
188
+ });
189
+ ```
190
+
191
+ ## License
192
+ Copyright (c) 2011 Gonzalo Rodríguez-Baltanás Díaz
193
+
194
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
195
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
196
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require File.expand_path('../lib/bootstrap-datepicker-rails/version', __FILE__)
3
+
4
+ desc "Build the gem"
5
+ task "build" do
6
+ system("gem build bootstrap-datepicker-rails.gemspec")
7
+ end
8
+
9
+ desc "Publish the gem"
10
+ task 'publish' do
11
+ system("gem push bootstrap-datepicker-rails-#{BootstrapDatepickerRails::Rails::VERSION}.gem")
12
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bootstrap-datepicker-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gonzalo Rodríguez-Baltanás Díaz"]
6
+ gem.email = ["siotopo@gmail.com"]
7
+ gem.description = %q{A date picker for Twitter Bootstrap}
8
+ gem.homepage = "https://github.com/Nerian/bootstrap-datepicker-rails"
9
+ gem.summary = gem.description
10
+
11
+ gem.name = "bootstrap-datepicker-rails"
12
+ gem.require_paths = ["lib"]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.version = BootstrapDatepickerRails::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-datepicker-rails/version"
3
+
4
+ module BootstrapDatepickerRails
5
+ module Rails
6
+ if ::Rails.version < "3.1"
7
+ require "bootstrap-datepicker-rails/railtie"
8
+ else
9
+ require "bootstrap-datepicker-rails/engine"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module BootstrapDatepickerRails
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module BootstrapDatepickerRails
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module BootstrapDatepickerRails
2
+ module Rails
3
+ VERSION = "0.3"
4
+ end
5
+ end
@@ -0,0 +1,526 @@
1
+ /* =========================================================
2
+ * bootstrap-datepicker.js
3
+ * http://www.eyecon.ro/bootstrap-datepicker
4
+ * =========================================================
5
+ * Copyright 2012 Stefan Petre
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================= */
19
+
20
+ !function( $ ) {
21
+
22
+ // Picker object
23
+
24
+ var Datepicker = function(element, options){
25
+ this.element = $(element);
26
+ this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
27
+ this.picker = $(DPGlobal.template)
28
+ .appendTo('body')
29
+ .on({
30
+ click: $.proxy(this.click, this),
31
+ mousedown: $.proxy(this.mousedown, this)
32
+ });
33
+ this.isInput = this.element.is('input');
34
+ this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
35
+
36
+ if (this.isInput) {
37
+ this.element.on({
38
+ focus: $.proxy(this.show, this),
39
+ blur: $.proxy(this._hide, this),
40
+ keyup: $.proxy(this.update, this)
41
+ });
42
+ } else {
43
+ if (this.component){
44
+ this.component.on('click', $.proxy(this.show, this));
45
+ } else {
46
+ this.element.on('click', $.proxy(this.show, this));
47
+ }
48
+ }
49
+
50
+ this.viewMode = 0;
51
+ this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
52
+ this.weekEnd = this.weekStart == 0 ? 6 : this.weekStart - 1;
53
+ this.startDate = -Infinity;
54
+ this.endDate = Infinity;
55
+ this.setStartDate(options.startDate||this.element.data('date-startdate'));
56
+ this.setEndDate(options.endDate||this.element.data('date-enddate'));
57
+ this.fillDow();
58
+ this.fillMonths();
59
+ this.update();
60
+ this.showMode();
61
+ };
62
+
63
+ Datepicker.prototype = {
64
+ constructor: Datepicker,
65
+
66
+ show: function(e) {
67
+ this.picker.show();
68
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
69
+ this.place();
70
+ $(window).on('resize', $.proxy(this.place, this));
71
+ if (e ) {
72
+ e.stopPropagation();
73
+ e.preventDefault();
74
+ }
75
+ if (!this.isInput) {
76
+ $(document).on('mousedown', $.proxy(this.hide, this));
77
+ }
78
+ this.element.trigger({
79
+ type: 'show',
80
+ date: this.date
81
+ });
82
+ },
83
+
84
+ _hide: function(e){
85
+ // When going from the input to the picker, IE handles the blur/click
86
+ // events differently than other browsers, in such a way that the blur
87
+ // event triggers a hide before the click event can stop propagation.
88
+ if ($.browser.msie) {
89
+ var t = this, args = arguments;
90
+
91
+ function cancel_hide(){
92
+ clearTimeout(hide_timeout);
93
+ e.target.focus();
94
+ t.picker.off('click', cancel_hide);
95
+ }
96
+
97
+ function do_hide(){
98
+ t.hide.apply(t, args);
99
+ t.picker.off('click', cancel_hide);
100
+ }
101
+
102
+ this.picker.on('click', cancel_hide);
103
+ var hide_timeout = setTimeout(do_hide, 100);
104
+ } else {
105
+ return this.hide.apply(this, arguments);
106
+ }
107
+ },
108
+
109
+ hide: function(){
110
+ this.picker.hide();
111
+ $(window).off('resize', this.place);
112
+ this.viewMode = 0;
113
+ this.showMode();
114
+ if (!this.isInput) {
115
+ $(document).off('mousedown', this.hide);
116
+ }
117
+ this.setValue();
118
+ this.element.trigger({
119
+ type: 'hide',
120
+ date: this.date
121
+ });
122
+ },
123
+
124
+ setValue: function() {
125
+ var formated = DPGlobal.formatDate(this.date, this.format);
126
+ if (!this.isInput) {
127
+ if (this.component){
128
+ this.element.find('input').prop('value', formated);
129
+ }
130
+ this.element.data('date', formated);
131
+ } else {
132
+ this.element.prop('value', formated);
133
+ }
134
+ },
135
+
136
+ setStartDate: function(startDate){
137
+ this.startDate = startDate||-Infinity;
138
+ if (this.startDate !== -Infinity) {
139
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format);
140
+ }
141
+ this.update();
142
+ this.updateNavArrows();
143
+ },
144
+
145
+ setEndDate: function(endDate){
146
+ this.endDate = endDate||Infinity;
147
+ if (this.endDate !== Infinity) {
148
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format);
149
+ }
150
+ this.update();
151
+ this.updateNavArrows();
152
+ },
153
+
154
+ place: function(){
155
+ var offset = this.component ? this.component.offset() : this.element.offset();
156
+ this.picker.css({
157
+ top: offset.top + this.height,
158
+ left: offset.left
159
+ });
160
+ },
161
+
162
+ update: function(){
163
+ this.date = DPGlobal.parseDate(
164
+ this.isInput ? this.element.prop('value') : this.element.data('date'),
165
+ this.format
166
+ );
167
+ if (this.date < this.startDate) {
168
+ this.viewDate = new Date(this.startDate);
169
+ } else if (this.date > this.endDate) {
170
+ this.viewDate = new Date(this.endDate);
171
+ } else {
172
+ this.viewDate = new Date(this.date);
173
+ }
174
+ this.fill();
175
+ },
176
+
177
+ fillDow: function(){
178
+ var dowCnt = this.weekStart;
179
+ var html = '<tr>';
180
+ while (dowCnt < this.weekStart + 7) {
181
+ html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
182
+ }
183
+ html += '</tr>';
184
+ this.picker.find('.datepicker-days thead').append(html);
185
+ },
186
+
187
+ fillMonths: function(){
188
+ var html = '';
189
+ var i = 0
190
+ while (i < 12) {
191
+ html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
192
+ }
193
+ this.picker.find('.datepicker-months td').html(html);
194
+ },
195
+
196
+ fill: function() {
197
+ var d = new Date(this.viewDate),
198
+ year = d.getFullYear(),
199
+ month = d.getMonth(),
200
+ startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
201
+ startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
202
+ endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
203
+ endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
204
+ currentDate = this.date.valueOf();
205
+ this.picker.find('.datepicker-days th:eq(1)')
206
+ .text(DPGlobal.dates.months[month]+' '+year);
207
+ this.updateNavArrows();
208
+ this.fillMonths();
209
+ var prevMonth = new Date(year, month-1, 28,0,0,0,0),
210
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
211
+ prevMonth.setDate(day);
212
+ prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
213
+ var nextMonth = new Date(prevMonth);
214
+ nextMonth.setDate(nextMonth.getDate() + 42);
215
+ nextMonth = nextMonth.valueOf();
216
+ html = [];
217
+ var clsName;
218
+ while(prevMonth.valueOf() < nextMonth) {
219
+ if (prevMonth.getDay() == this.weekStart) {
220
+ html.push('<tr>');
221
+ }
222
+ clsName = '';
223
+ if (prevMonth.getFullYear() < year || (prevMonth.getFullYear() == year && prevMonth.getMonth() < month)) {
224
+ clsName += ' old';
225
+ } else if (prevMonth.getFullYear() > year || (prevMonth.getFullYear() == year && prevMonth.getMonth() > month)) {
226
+ clsName += ' new';
227
+ }
228
+ if (prevMonth.valueOf() == currentDate) {
229
+ clsName += ' active';
230
+ }
231
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate) {
232
+ clsName += ' disabled';
233
+ }
234
+ html.push('<td class="day'+clsName+'">'+prevMonth.getDate() + '</td>');
235
+ if (prevMonth.getDay() == this.weekEnd) {
236
+ html.push('</tr>');
237
+ }
238
+ prevMonth.setDate(prevMonth.getDate()+1);
239
+ }
240
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
241
+ var currentYear = this.date.getFullYear();
242
+
243
+ var months = this.picker.find('.datepicker-months')
244
+ .find('th:eq(1)')
245
+ .text(year)
246
+ .end()
247
+ .find('span').removeClass('active');
248
+ if (currentYear == year) {
249
+ months.eq(this.date.getMonth()).addClass('active');
250
+ }
251
+ if (year < startYear || year > endYear) {
252
+ months.addClass('disabled');
253
+ }
254
+ if (year == startYear) {
255
+ months.slice(0, startMonth).addClass('disabled');
256
+ }
257
+ if (year == endYear) {
258
+ months.slice(endMonth+1).addClass('disabled');
259
+ }
260
+
261
+ html = '';
262
+ year = parseInt(year/10, 10) * 10;
263
+ var yearCont = this.picker.find('.datepicker-years')
264
+ .find('th:eq(1)')
265
+ .text(year + '-' + (year + 9))
266
+ .end()
267
+ .find('td');
268
+ year -= 1;
269
+ for (var i = -1; i < 11; i++) {
270
+ html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
271
+ year += 1;
272
+ }
273
+ yearCont.html(html);
274
+ },
275
+
276
+ updateNavArrows: function() {
277
+ var d = new Date(this.viewDate),
278
+ year = d.getFullYear(),
279
+ month = d.getMonth();
280
+ switch (this.viewMode) {
281
+ case 0:
282
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
283
+ this.picker.find('.prev').css({visibility: 'hidden'});
284
+ } else {
285
+ this.picker.find('.prev').css({visibility: 'visible'});
286
+ }
287
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
288
+ this.picker.find('.next').css({visibility: 'hidden'});
289
+ } else {
290
+ this.picker.find('.next').css({visibility: 'visible'});
291
+ }
292
+ break;
293
+ case 1:
294
+ case 2:
295
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
296
+ this.picker.find('.prev').css({visibility: 'hidden'});
297
+ } else {
298
+ this.picker.find('.prev').css({visibility: 'visible'});
299
+ }
300
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
301
+ this.picker.find('.next').css({visibility: 'hidden'});
302
+ } else {
303
+ this.picker.find('.next').css({visibility: 'visible'});
304
+ }
305
+ break;
306
+ }
307
+ },
308
+
309
+ click: function(e) {
310
+ e.stopPropagation();
311
+ e.preventDefault();
312
+ var target = $(e.target).closest('span, td, th');
313
+ if (target.length == 1) {
314
+ switch(target[0].nodeName.toLowerCase()) {
315
+ case 'th':
316
+ switch(target[0].className) {
317
+ case 'switch':
318
+ this.showMode(1);
319
+ break;
320
+ case 'prev':
321
+ case 'next':
322
+ this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
323
+ this.viewDate,
324
+ this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
325
+ DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
326
+ );
327
+ this.fill();
328
+ break;
329
+ }
330
+ break;
331
+ case 'span':
332
+ if (!target.is('.disabled')) {
333
+ if (target.is('.month')) {
334
+ var month = target.parent().find('span').index(target);
335
+ this.viewDate.setMonth(month);
336
+ } else {
337
+ var year = parseInt(target.text(), 10)||0;
338
+ this.viewDate.setFullYear(year);
339
+ }
340
+ this.showMode(-1);
341
+ this.fill();
342
+ }
343
+ break;
344
+ case 'td':
345
+ if (target.is('.day') && !target.is('.disabled')){
346
+ var day = parseInt(target.text(), 10)||1;
347
+ var year = this.viewDate.getFullYear(),
348
+ month = this.viewDate.getMonth();
349
+ if (target.is('.old')) {
350
+ if (month == 0) {
351
+ month = 11;
352
+ year -= 1;
353
+ } else {
354
+ month -= 1;
355
+ }
356
+ } else if (target.is('.new')) {
357
+ if (month == 11) {
358
+ month = 0;
359
+ year += 1;
360
+ } else {
361
+ month += 1;
362
+ }
363
+ }
364
+ this.date = new Date(year, month, day,0,0,0,0);
365
+ this.viewDate = new Date(year, month, day,0,0,0,0);
366
+ this.fill();
367
+ this.setValue();
368
+ this.element.trigger({
369
+ type: 'changeDate',
370
+ date: this.date
371
+ });
372
+ if (this.isInput) {
373
+ this.element.change();
374
+ } else if (this.component){
375
+ this.element.find('input').change();
376
+ }
377
+ }
378
+ break;
379
+ }
380
+ }
381
+ },
382
+
383
+ mousedown: function(e){
384
+ e.stopPropagation();
385
+ e.preventDefault();
386
+ },
387
+
388
+ showMode: function(dir) {
389
+ if (dir) {
390
+ this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
391
+ }
392
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
393
+ this.updateNavArrows();
394
+ }
395
+ };
396
+
397
+ $.fn.datepicker = function ( option ) {
398
+ var args = Array.apply(null, arguments);
399
+ args.shift();
400
+ return this.each(function () {
401
+ var $this = $(this),
402
+ data = $this.data('datepicker'),
403
+ options = typeof option == 'object' && option;
404
+ if (!data) {
405
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
406
+ }
407
+ if (typeof option == 'string') data[option].apply(data, args);
408
+ });
409
+ };
410
+
411
+ $.fn.datepicker.defaults = {
412
+ };
413
+ $.fn.datepicker.Constructor = Datepicker;
414
+
415
+ var DPGlobal = {
416
+ modes: [
417
+ {
418
+ clsName: 'days',
419
+ navFnc: 'Month',
420
+ navStep: 1
421
+ },
422
+ {
423
+ clsName: 'months',
424
+ navFnc: 'FullYear',
425
+ navStep: 1
426
+ },
427
+ {
428
+ clsName: 'years',
429
+ navFnc: 'FullYear',
430
+ navStep: 10
431
+ }],
432
+ dates:{
433
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
434
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
435
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
436
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
437
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
438
+ },
439
+ isLeapYear: function (year) {
440
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
441
+ },
442
+ getDaysInMonth: function (year, month) {
443
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
444
+ },
445
+ parseFormat: function(format){
446
+ var separator = format.match(/[.\/-].*?/),
447
+ parts = format.split(/\W+/);
448
+ if (!separator || !parts || parts.length == 0){
449
+ throw new Error("Invalid date format.");
450
+ }
451
+ return {separator: separator, parts: parts};
452
+ },
453
+ parseDate: function(date, format) {
454
+ if (date instanceof Date) return date;
455
+ var parts = date.split(format.separator),
456
+ date = new Date(1970, 1, 1, 0, 0, 0),
457
+ val;
458
+ if (parts.length == format.parts.length) {
459
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
460
+ val = parseInt(parts[i], 10)||1;
461
+ switch(format.parts[i]) {
462
+ case 'dd':
463
+ case 'd':
464
+ date.setDate(val);
465
+ break;
466
+ case 'mm':
467
+ case 'm':
468
+ date.setMonth(val - 1);
469
+ break;
470
+ case 'yy':
471
+ date.setFullYear(2000 + val);
472
+ break;
473
+ case 'yyyy':
474
+ date.setFullYear(val);
475
+ break;
476
+ }
477
+ }
478
+ }
479
+ return date;
480
+ },
481
+ formatDate: function(date, format){
482
+ var val = {
483
+ d: date.getDate(),
484
+ m: date.getMonth() + 1,
485
+ yy: date.getFullYear().toString().substring(2),
486
+ yyyy: date.getFullYear()
487
+ };
488
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
489
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
490
+ var date = [];
491
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
492
+ date.push(val[format.parts[i]]);
493
+ }
494
+ return date.join(format.separator);
495
+ },
496
+ headTemplate: '<thead>'+
497
+ '<tr>'+
498
+ '<th class="prev"><i class="icon-arrow-left"/></th>'+
499
+ '<th colspan="5" class="switch"></th>'+
500
+ '<th class="next"><i class="icon-arrow-right"/></th>'+
501
+ '</tr>'+
502
+ '</thead>',
503
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
504
+ };
505
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
506
+ '<div class="datepicker-days">'+
507
+ '<table class=" table-condensed">'+
508
+ DPGlobal.headTemplate+
509
+ '<tbody></tbody>'+
510
+ '</table>'+
511
+ '</div>'+
512
+ '<div class="datepicker-months">'+
513
+ '<table class="table-condensed">'+
514
+ DPGlobal.headTemplate+
515
+ DPGlobal.contTemplate+
516
+ '</table>'+
517
+ '</div>'+
518
+ '<div class="datepicker-years">'+
519
+ '<table class="table-condensed">'+
520
+ DPGlobal.headTemplate+
521
+ DPGlobal.contTemplate+
522
+ '</table>'+
523
+ '</div>'+
524
+ '</div>';
525
+
526
+ }( window.jQuery )
@@ -0,0 +1,208 @@
1
+ /*!
2
+ * Datepicker for Bootstrap
3
+ *
4
+ * Copyright 2012 Stefan Petre
5
+ * Licensed under the Apache License v2.0
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ */
9
+ .datepicker {
10
+ top: 0;
11
+ left: 0;
12
+ padding: 4px;
13
+ margin-top: 1px;
14
+ -webkit-border-radius: 4px;
15
+ -moz-border-radius: 4px;
16
+ border-radius: 4px;
17
+ /*.dow {
18
+ border-top: 1px solid #ddd !important;
19
+ }*/
20
+ }
21
+ .datepicker:before {
22
+ content: '';
23
+ display: inline-block;
24
+ border-left: 7px solid transparent;
25
+ border-right: 7px solid transparent;
26
+ border-bottom: 7px solid #ccc;
27
+ border-bottom-color: rgba(0, 0, 0, 0.2);
28
+ position: absolute;
29
+ top: -7px;
30
+ left: 6px;
31
+ }
32
+ .datepicker:after {
33
+ content: '';
34
+ display: inline-block;
35
+ border-left: 6px solid transparent;
36
+ border-right: 6px solid transparent;
37
+ border-bottom: 6px solid #ffffff;
38
+ position: absolute;
39
+ top: -6px;
40
+ left: 7px;
41
+ }
42
+ .datepicker > div {
43
+ display: none;
44
+ }
45
+ .datepicker table {
46
+ width: 100%;
47
+ margin: 0;
48
+ }
49
+ .datepicker td, .datepicker th {
50
+ text-align: center;
51
+ width: 20px;
52
+ height: 20px;
53
+ -webkit-border-radius: 4px;
54
+ -moz-border-radius: 4px;
55
+ border-radius: 4px;
56
+ }
57
+ .datepicker td.day:hover {
58
+ background: #eeeeee;
59
+ cursor: pointer;
60
+ }
61
+ .datepicker td.old, .datepicker td.new {
62
+ color: #999999;
63
+ }
64
+ .datepicker td.disabled, .datepicker td.disabled:hover {
65
+ background: none;
66
+ color:#999999;
67
+ cursor: default;
68
+ }
69
+ .datepicker td.active,
70
+ .datepicker td.active:hover,
71
+ .datepicker td.active.disabled,
72
+ .datepicker td.active.disabled:hover {
73
+ background-color: #006dcc;
74
+ background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
75
+ background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
76
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
77
+ background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
78
+ background-image: -o-linear-gradient(top, #0088cc, #0044cc);
79
+ background-image: linear-gradient(top, #0088cc, #0044cc);
80
+ background-repeat: repeat-x;
81
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
82
+ border-color: #0044cc #0044cc #002a80;
83
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
84
+ filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
85
+ color: #fff;
86
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
87
+ }
88
+ .datepicker td.active:hover,
89
+ .datepicker td.active:hover:hover,
90
+ .datepicker td.active.disabled:hover,
91
+ .datepicker td.active.disabled:hover:hover,
92
+ .datepicker td.active:active,
93
+ .datepicker td.active:hover:active,
94
+ .datepicker td.active.disabled:active,
95
+ .datepicker td.active.disabled:hover:active,
96
+ .datepicker td.active.active,
97
+ .datepicker td.active:hover.active,
98
+ .datepicker td.active.disabled.active,
99
+ .datepicker td.active.disabled:hover.active,
100
+ .datepicker td.active.disabled,
101
+ .datepicker td.active:hover.disabled,
102
+ .datepicker td.active.disabled.disabled,
103
+ .datepicker td.active.disabled:hover.disabled,
104
+ .datepicker td.active[disabled],
105
+ .datepicker td.active:hover[disabled],
106
+ .datepicker td.active.disabled[disabled],
107
+ .datepicker td.active.disabled:hover[disabled] {
108
+ background-color: #0044cc;
109
+ }
110
+ .datepicker td.active:active,
111
+ .datepicker td.active:hover:active,
112
+ .datepicker td.active.disabled:active,
113
+ .datepicker td.active.disabled:hover:active,
114
+ .datepicker td.active.active,
115
+ .datepicker td.active:hover.active,
116
+ .datepicker td.active.disabled.active,
117
+ .datepicker td.active.disabled:hover.active {
118
+ background-color: #003399 \9;
119
+ }
120
+ .datepicker td span {
121
+ display: block;
122
+ width: 47px;
123
+ height: 54px;
124
+ line-height: 54px;
125
+ float: left;
126
+ margin: 2px;
127
+ cursor: pointer;
128
+ -webkit-border-radius: 4px;
129
+ -moz-border-radius: 4px;
130
+ border-radius: 4px;
131
+ }
132
+ .datepicker td span:hover {
133
+ background: #eeeeee;
134
+ }
135
+ .datepicker td span.disabled, .datepicker td span.disabled:hover {
136
+ background:none;
137
+ color: #999999;
138
+ cursor: default;
139
+ }
140
+ .datepicker td span.active,
141
+ .datepicker td span.active:hover,
142
+ .datepicker td span.active.disabled,
143
+ .datepicker td span.active.disabled:hover {
144
+ background-color: #006dcc;
145
+ background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
146
+ background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
147
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
148
+ background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
149
+ background-image: -o-linear-gradient(top, #0088cc, #0044cc);
150
+ background-image: linear-gradient(top, #0088cc, #0044cc);
151
+ background-repeat: repeat-x;
152
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
153
+ border-color: #0044cc #0044cc #002a80;
154
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
155
+ filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
156
+ color: #fff;
157
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
158
+ }
159
+ .datepicker td span.active:hover,
160
+ .datepicker td span.active:hover:hover,
161
+ .datepicker td span.active.disabled:hover,
162
+ .datepicker td span.active.disabled:hover:hover,
163
+ .datepicker td span.active:active,
164
+ .datepicker td span.active:hover:active,
165
+ .datepicker td span.active.disabled:active,
166
+ .datepicker td span.active.disabled:hover:active,
167
+ .datepicker td span.active.active,
168
+ .datepicker td span.active:hover.active,
169
+ .datepicker td span.active.disabled.active,
170
+ .datepicker td span.active.disabled:hover.active,
171
+ .datepicker td span.active.disabled,
172
+ .datepicker td span.active:hover.disabled,
173
+ .datepicker td span.active.disabled.disabled,
174
+ .datepicker td span.active.disabled:hover.disabled,
175
+ .datepicker td span.active[disabled],
176
+ .datepicker td span.active:hover[disabled],
177
+ .datepicker td span.active.disabled[disabled],
178
+ .datepicker td span.active.disabled:hover[disabled] {
179
+ background-color: #0044cc;
180
+ }
181
+ .datepicker td span.active:active,
182
+ .datepicker td span.active:hover:active,
183
+ .datepicker td span.active.disabled:active,
184
+ .datepicker td span.active.disabled:hover:active,
185
+ .datepicker td span.active.active,
186
+ .datepicker td span.active:hover.active,
187
+ .datepicker td span.active.disabled.active,
188
+ .datepicker td span.active.disabled:hover.active {
189
+ background-color: #003399 \9;
190
+ }
191
+ .datepicker td span.old {
192
+ color: #999999;
193
+ }
194
+ .datepicker th.switch {
195
+ width: 145px;
196
+ }
197
+ .datepicker thead tr:first-child th {
198
+ cursor: pointer;
199
+ }
200
+ .datepicker thead tr:first-child th:hover {
201
+ background: #eeeeee;
202
+ }
203
+ .input-append.date .add-on i, .input-prepend.date .add-on i {
204
+ display: block;
205
+ cursor: pointer;
206
+ width: 16px;
207
+ height: 16px;
208
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-datepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
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: 2012-03-09 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70175296096340 !ruby/object:Gem::Requirement
16
+ requirement: &70332582805880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70175296096340
24
+ version_requirements: *70332582805880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70175296095720 !ruby/object:Gem::Requirement
27
+ requirement: &70332582808440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70175296095720
35
+ version_requirements: *70332582808440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70175296095260 !ruby/object:Gem::Requirement
38
+ requirement: &70332582487200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,14 +43,25 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70175296095260
46
+ version_requirements: *70332582487200
47
47
  description: A date picker for Twitter Bootstrap
48
48
  email:
49
49
  - siotopo@gmail.com
50
50
  executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
- files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - bootstrap-datepicker-rails.gemspec
59
+ - lib/bootstrap-datepicker-rails.rb
60
+ - lib/bootstrap-datepicker-rails/engine.rb
61
+ - lib/bootstrap-datepicker-rails/railtie.rb
62
+ - lib/bootstrap-datepicker-rails/version.rb
63
+ - vendor/assets/javascripts/bootstrap-datepicker.js
64
+ - vendor/assets/stylesheets/bootstrap-datepicker.css
54
65
  homepage: https://github.com/Nerian/bootstrap-datepicker-rails
55
66
  licenses: []
56
67
  post_install_message:
@@ -65,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
76
  version: '0'
66
77
  segments:
67
78
  - 0
68
- hash: -1266021623769733465
79
+ hash: 65111314992475012
69
80
  required_rubygems_version: !ruby/object:Gem::Requirement
70
81
  none: false
71
82
  requirements:
@@ -74,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
85
  version: '0'
75
86
  segments:
76
87
  - 0
77
- hash: -1266021623769733465
88
+ hash: 65111314992475012
78
89
  requirements: []
79
90
  rubyforge_project:
80
91
  rubygems_version: 1.8.17