foundation_datepicker_rails 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 092254f1a97ba84ee05d55756f55dcf1b74c0a7f
4
+ data.tar.gz: c8ecbdb84a20f9b2d1ecfa9c2d2ef686289ec95d
5
+ SHA512:
6
+ metadata.gz: 91ac0a2be45a3c4e8d26f34270edb47e143d31287a7387fc50b37f918869e8a2a71891ff5563560f66da17b2b516e2d3cc0dc522a9b0a730b1dbffc54b3d62b2
7
+ data.tar.gz: 17a5aca11f24e390de20b5e9e905add839b7ff98bd73c906d675a54a7384339094de417ce969739de07b824e4987785f02b73a8982c0bd3d91f3865c7a93f09f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in foundation_datepicker_rails.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ foundation_datepicker_rails (0.0.1)
5
+ rails (~> 4.0.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.2)
11
+ actionpack (= 4.0.2)
12
+ mail (~> 2.5.4)
13
+ actionpack (4.0.2)
14
+ activesupport (= 4.0.2)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.2)
20
+ activesupport (= 4.0.2)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.2)
23
+ activemodel (= 4.0.2)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.2)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activesupport (4.0.2)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ arel (4.0.1)
35
+ atomic (1.1.14)
36
+ builder (3.1.4)
37
+ erubis (2.7.0)
38
+ hike (1.2.3)
39
+ i18n (0.6.9)
40
+ mail (2.5.4)
41
+ mime-types (~> 1.16)
42
+ treetop (~> 1.4.8)
43
+ mime-types (1.25.1)
44
+ minitest (4.7.5)
45
+ multi_json (1.8.4)
46
+ polyglot (0.3.3)
47
+ rack (1.5.2)
48
+ rack-test (0.6.2)
49
+ rack (>= 1.0)
50
+ rails (4.0.2)
51
+ actionmailer (= 4.0.2)
52
+ actionpack (= 4.0.2)
53
+ activerecord (= 4.0.2)
54
+ activesupport (= 4.0.2)
55
+ bundler (>= 1.3.0, < 2.0)
56
+ railties (= 4.0.2)
57
+ sprockets-rails (~> 2.0.0)
58
+ railties (4.0.2)
59
+ actionpack (= 4.0.2)
60
+ activesupport (= 4.0.2)
61
+ rake (>= 0.8.7)
62
+ thor (>= 0.18.1, < 2.0)
63
+ rake (10.1.1)
64
+ sprockets (2.10.1)
65
+ hike (~> 1.2)
66
+ multi_json (~> 1.0)
67
+ rack (~> 1.0)
68
+ tilt (~> 1.1, != 1.3.0)
69
+ sprockets-rails (2.0.1)
70
+ actionpack (>= 3.0)
71
+ activesupport (>= 3.0)
72
+ sprockets (~> 2.8)
73
+ sqlite3 (1.3.8)
74
+ thor (0.18.1)
75
+ thread_safe (0.1.3)
76
+ atomic
77
+ tilt (1.4.1)
78
+ treetop (1.4.15)
79
+ polyglot
80
+ polyglot (>= 0.3.1)
81
+ tzinfo (0.3.38)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ foundation_datepicker_rails!
88
+ sqlite3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <2014> <Kurt Mueller>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ foundation_datepicker_rails
2
+ ===
3
+
4
+ A ruby gem that implements the `foundation-datepicker` functionality. The project can be found on its [Github](https://github.com/najlepsiwebdesigner/foundation-datepicker) page.
5
+
6
+
7
+
8
+ ##Installation
9
+ Add this to your Gemfile:
10
+
11
+ ```
12
+ gem 'foundation_datepicker_rails'
13
+ ```
14
+
15
+ and run `bundle install`.
16
+
17
+
18
+ ##Usage
19
+ Include these lines in `app/assets/stylesheets/application.css.scss`:
20
+
21
+ ```
22
+ /*
23
+ *= require font-awesome
24
+ *= require foundation-datepicker
25
+ */
26
+ ```
27
+
28
+ Include this lines in `app/assets/javascripts/application.js`:
29
+
30
+ ```
31
+ //
32
+ //= require foundation-datepicker
33
+ //
34
+ ```
35
+
36
+ Next, call the datepicker via javascript:
37
+
38
+
39
+ `$('.datepicker').fdatepicker()`
40
+
41
+ There are numerous options for the datepicker. You can find them [here](http://foundation-datepicker.peterbeno.com/example/example.html).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FoundationDatepickerRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "foundation_datepicker_rails/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "foundation_datepicker_rails"
9
+ s.version = FoundationDatepickerRails::VERSION
10
+ s.authors = ["Kurt Mueller"]
11
+ s.email = ["mueller.128@osu.edu"]
12
+ s.homepage = "http://github.com/KurtRMueller/foundation_datepicker_rails"
13
+ s.summary = "Rails gem for foundation-datepicker."
14
+ s.description = "A simple assets gem for foundation-datepicker, whose documentation can be found here: http://foundation-datepicker.peterbeno.com/example/example.html"
15
+ s.license = 'GPLv2'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- test/*`.split("\n")
19
+
20
+ s.add_runtime_dependency "rails", "~> 4.0"
21
+ s.add_runtime_dependency "foundation-rails", "~> 5.0"
22
+ s.add_runtime_dependency "font-awesome-rails", "~> 4.0"
23
+
24
+ s.add_development_dependency "pry", '~> 0.9'
25
+ s.add_development_dependency "sqlite3", '~> 1.3'
26
+ end
@@ -0,0 +1,4 @@
1
+ require "foundation_datepicker_rails/engine"
2
+
3
+ module FoundationDatepickerRails
4
+ end
@@ -0,0 +1,7 @@
1
+ module FoundationDatepickerRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace FoundationDatepickerRails
4
+
5
+ require 'font-awesome-rails'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module FoundationDatepickerRails
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :foundation_datepicker_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class FoundationDatepickerRailsTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, FoundationDatepickerRails
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,1049 @@
1
+ /* =========================================================
2
+ * foundation-datepicker.js
3
+ * Copyright 2013 Peter Beno, najlepsiwebdesigner@gmail.com, @benopeter
4
+ * project website http://foundation-datepicker.peterbeno.com
5
+ *
6
+ * original project:
7
+ * bootstrap-datepicker.js
8
+ * http://www.eyecon.ro/bootstrap-datepicker
9
+ * =========================================================
10
+ * Copyright 2012 Stefan Petre
11
+ * Improvements by Andrew Rowls
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ * ========================================================= */
25
+
26
+ !function( $ ) {
27
+
28
+ function UTCDate(){
29
+ return new Date(Date.UTC.apply(Date, arguments));
30
+ }
31
+ function UTCToday(){
32
+ var today = new Date();
33
+ return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
34
+ }
35
+
36
+ // Picker object
37
+
38
+ var Datepicker = function(element, options) {
39
+ var that = this;
40
+
41
+ this.element = $(element);
42
+ this.closeButton = options.closeButton;
43
+ this.language = options.language||this.element.data('date-language')||"en";
44
+ this.language = this.language in dates ? this.language : this.language.split('-')[0]; //Check if "de-DE" style date is available, if not language should fallback to 2 letter code eg "de"
45
+ this.language = this.language in dates ? this.language : "en";
46
+ this.isRTL = dates[this.language].rtl||false;
47
+ this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
48
+ this.isInline = false;
49
+ this.isInput = this.element.is('input');
50
+ this.component = this.element.is('.date') ? this.element.find('.prefix, .postfix') : false;
51
+ this.hasInput = this.component && this.element.find('input').length;
52
+
53
+
54
+ this.onRender = options.onRender || function () {};
55
+ if(this.component && this.component.length === 0)
56
+ this.component = false;
57
+
58
+ this._attachEvents();
59
+
60
+ this.forceParse = true;
61
+ if ('forceParse' in options) {
62
+ this.forceParse = options.forceParse;
63
+ } else if ('dateForceParse' in this.element.data()) {
64
+ this.forceParse = this.element.data('date-force-parse');
65
+ }
66
+
67
+
68
+ this.picker = $(DPGlobal.template)
69
+ .appendTo(this.isInline ? this.element : 'body')
70
+ .on({
71
+ click: $.proxy(this.click, this),
72
+ mousedown: $.proxy(this.mousedown, this)
73
+ });
74
+ if (this.closeButton){
75
+ this.picker.find('a.datepicker-close').show();
76
+ }
77
+
78
+ if(this.isInline) {
79
+ this.picker.addClass('datepicker-inline');
80
+ } else {
81
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
82
+ }
83
+ if (this.isRTL){
84
+ this.picker.addClass('datepicker-rtl');
85
+ this.picker.find('.prev i, .next i')
86
+ .toggleClass('icon-chevron-left icon-chevron-right').toggleClass('fa-chevron-left fa-chevron-right');
87
+ }
88
+ $(document).on('mousedown', function (e) {
89
+ // Clicked outside the datepicker, hide it
90
+ if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
91
+ that.hide();
92
+ }
93
+ });
94
+
95
+ this.autoclose = true;
96
+ if ('autoclose' in options) {
97
+ this.autoclose = options.autoclose;
98
+ } else if ('dateAutoclose' in this.element.data()) {
99
+ this.autoclose = this.element.data('date-autoclose');
100
+ }
101
+
102
+ this.keyboardNavigation = true;
103
+ if ('keyboardNavigation' in options) {
104
+ this.keyboardNavigation = options.keyboardNavigation;
105
+ } else if ('dateKeyboardNavigation' in this.element.data()) {
106
+ this.keyboardNavigation = this.element.data('date-keyboard-navigation');
107
+ }
108
+
109
+ this.viewMode = this.startViewMode = 0;
110
+ switch(options.startView || this.element.data('date-start-view')){
111
+ case 2:
112
+ case 'decade':
113
+ this.viewMode = this.startViewMode = 2;
114
+ break;
115
+ case 1:
116
+ case 'year':
117
+ this.viewMode = this.startViewMode = 1;
118
+ break;
119
+ }
120
+
121
+ this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
122
+ this.todayHighlight = (options.todayHighlight||this.element.data('date-today-highlight')||false);
123
+
124
+ this.calendarWeeks = false;
125
+ if ('calendarWeeks' in options) {
126
+ this.calendarWeeks = options.calendarWeeks;
127
+ } else if ('dateCalendarWeeks' in this.element.data()) {
128
+ this.calendarWeeks = this.element.data('date-calendar-weeks');
129
+ }
130
+ if (this.calendarWeeks)
131
+ this.picker.find('tfoot th.today')
132
+ .attr('colspan', function(i, val){
133
+ return parseInt(val) + 1;
134
+ });
135
+
136
+ this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
137
+ this.weekEnd = ((this.weekStart + 6) % 7);
138
+ this.startDate = -Infinity;
139
+ this.endDate = Infinity;
140
+ this.daysOfWeekDisabled = [];
141
+ this.setStartDate(options.startDate||this.element.data('date-startdate'));
142
+ this.setEndDate(options.endDate||this.element.data('date-enddate'));
143
+ this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
144
+
145
+ this.fillDow();
146
+ this.fillMonths();
147
+ this.update();
148
+ this.showMode();
149
+
150
+ if(this.isInline) {
151
+ this.show();
152
+ }
153
+ };
154
+
155
+ Datepicker.prototype = {
156
+ constructor: Datepicker,
157
+
158
+ _events: [],
159
+ _attachEvents: function(){
160
+ this._detachEvents();
161
+ if (this.isInput) { // single input
162
+ this._events = [
163
+ [this.element, {
164
+ focus: $.proxy(this.show, this),
165
+ keyup: $.proxy(this.update, this),
166
+ keydown: $.proxy(this.keydown, this)
167
+ }]
168
+ ];
169
+ }
170
+ else if (this.component && this.hasInput){ // component: input + button
171
+ this._events = [
172
+ // For components that are not readonly, allow keyboard nav
173
+ [this.element.find('input'), {
174
+ focus: $.proxy(this.show, this),
175
+ keyup: $.proxy(this.update, this),
176
+ keydown: $.proxy(this.keydown, this)
177
+ }],
178
+ [this.component, {
179
+ click: $.proxy(this.show, this)
180
+ }]
181
+ ];
182
+ }
183
+ else if (this.element.is('div')) { // inline datepicker
184
+ this.isInline = true;
185
+ }
186
+ else {
187
+ this._events = [
188
+ [this.element, {
189
+ click: $.proxy(this.show, this)
190
+ }]
191
+ ];
192
+ }
193
+ for (var i=0, el, ev; i<this._events.length; i++){
194
+ el = this._events[i][0];
195
+ ev = this._events[i][1];
196
+ el.on(ev);
197
+ }
198
+ },
199
+ _detachEvents: function(){
200
+ for (var i=0, el, ev; i<this._events.length; i++){
201
+ el = this._events[i][0];
202
+ ev = this._events[i][1];
203
+ el.off(ev);
204
+ }
205
+ this._events = [];
206
+ },
207
+
208
+ show: function(e) {
209
+ this.picker.show();
210
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
211
+ this.update();
212
+ this.place();
213
+ $(window).on('resize', $.proxy(this.place, this));
214
+ if (e ) {
215
+ e.stopPropagation();
216
+ e.preventDefault();
217
+ }
218
+ this.element.trigger({
219
+ type: 'show',
220
+ date: this.date
221
+ });
222
+ },
223
+
224
+ hide: function(e){
225
+ if(this.isInline) return;
226
+ if (!this.picker.is(':visible')) return;
227
+ this.picker.hide();
228
+ $(window).off('resize', this.place);
229
+ this.viewMode = this.startViewMode;
230
+ this.showMode();
231
+ if (!this.isInput) {
232
+ $(document).off('mousedown', this.hide);
233
+ }
234
+
235
+ if (
236
+ this.forceParse &&
237
+ (
238
+ this.isInput && this.element.val() ||
239
+ this.hasInput && this.element.find('input').val()
240
+ )
241
+ )
242
+ this.setValue();
243
+ this.element.trigger({
244
+ type: 'hide',
245
+ date: this.date
246
+ });
247
+ },
248
+
249
+ remove: function() {
250
+ this._detachEvents();
251
+ this.picker.remove();
252
+ delete this.element.data().datepicker;
253
+ },
254
+
255
+ getDate: function() {
256
+ var d = this.getUTCDate();
257
+ return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
258
+ },
259
+
260
+ getUTCDate: function() {
261
+ return this.date;
262
+ },
263
+
264
+ setDate: function(d) {
265
+ this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
266
+ },
267
+
268
+ setUTCDate: function(d) {
269
+ this.date = d;
270
+ this.setValue();
271
+ },
272
+
273
+ setValue: function() {
274
+ var formatted = this.getFormattedDate();
275
+ if (!this.isInput) {
276
+ if (this.component){
277
+ this.element.find('input').val(formatted);
278
+ }
279
+ this.element.data('date', formatted);
280
+ } else {
281
+ this.element.val(formatted);
282
+ }
283
+ },
284
+
285
+ getFormattedDate: function(format) {
286
+ if (format === undefined)
287
+ format = this.format;
288
+ return DPGlobal.formatDate(this.date, format, this.language);
289
+ },
290
+
291
+ setStartDate: function(startDate){
292
+ this.startDate = startDate||-Infinity;
293
+ if (this.startDate !== -Infinity) {
294
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
295
+ }
296
+ this.update();
297
+ this.updateNavArrows();
298
+ },
299
+
300
+ setEndDate: function(endDate){
301
+ this.endDate = endDate||Infinity;
302
+ if (this.endDate !== Infinity) {
303
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
304
+ }
305
+ this.update();
306
+ this.updateNavArrows();
307
+ },
308
+
309
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled){
310
+ this.daysOfWeekDisabled = daysOfWeekDisabled||[];
311
+ if (!$.isArray(this.daysOfWeekDisabled)) {
312
+ this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
313
+ }
314
+ this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
315
+ return parseInt(d, 10);
316
+ });
317
+ this.update();
318
+ this.updateNavArrows();
319
+ },
320
+
321
+ place: function(){
322
+ if(this.isInline) return;
323
+ var zIndex = parseInt(this.element.parents().filter(function() {
324
+ return $(this).css('z-index') != 'auto';
325
+ }).first().css('z-index'))+10;
326
+ var textbox = this.component ? this.component : this.element;
327
+ var offset = textbox.offset();
328
+ var height = textbox.outerHeight() + parseInt(textbox.css('margin-top'));
329
+ var width = textbox.outerWidth() + parseInt(textbox.css('margin-left'));
330
+ var fullOffsetTop = offset.top + height;
331
+ var offsetLeft = offset.left;
332
+ // if the datepicker is going to be below the window, show it on top of the input
333
+ if((fullOffsetTop + this.picker.height()) >= $(window).scrollTop() + $(window).height()){
334
+ fullOffsetTop = offset.top - height - this.picker.height();
335
+ }
336
+
337
+ // if the datepicker is going to go past the right side of the window, we want
338
+ // to set the right position so the datepicker lines up with the textbox
339
+ if(offset.left + this.picker.width() >= $(window).width()){
340
+ offsetLeft = (offset.left + width) - this.picker.width();
341
+ }
342
+ this.picker.css({
343
+ top: fullOffsetTop,
344
+ left: offsetLeft,
345
+ zIndex: zIndex
346
+ });
347
+ },
348
+
349
+ update: function(){
350
+ var date, fromArgs = false;
351
+ if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
352
+ date = arguments[0];
353
+ fromArgs = true;
354
+ } else {
355
+ date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
356
+ }
357
+
358
+ this.date = DPGlobal.parseDate(date, this.format, this.language);
359
+
360
+ if(fromArgs) this.setValue();
361
+
362
+ if (this.date < this.startDate) {
363
+ this.viewDate = new Date(this.startDate.valueOf());
364
+ } else if (this.date > this.endDate) {
365
+ this.viewDate = new Date(this.endDate.valueOf());
366
+ } else {
367
+ this.viewDate = new Date(this.date.valueOf());
368
+ }
369
+ this.fill();
370
+ },
371
+
372
+ fillDow: function(){
373
+ var dowCnt = this.weekStart,
374
+ html = '<tr>';
375
+ if(this.calendarWeeks){
376
+ var cell = '<th class="cw">&nbsp;</th>';
377
+ html += cell;
378
+ this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
379
+ }
380
+ while (dowCnt < this.weekStart + 7) {
381
+ html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
382
+ }
383
+ html += '</tr>';
384
+ this.picker.find('.datepicker-days thead').append(html);
385
+ },
386
+
387
+ fillMonths: function(){
388
+ var html = '',
389
+ i = 0;
390
+ while (i < 12) {
391
+ html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
392
+ }
393
+ this.picker.find('.datepicker-months td').html(html);
394
+ },
395
+
396
+ fill: function() {
397
+ var d = new Date(this.viewDate.valueOf()),
398
+ year = d.getUTCFullYear(),
399
+ month = d.getUTCMonth(),
400
+ startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
401
+ startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
402
+ endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
403
+ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
404
+ currentDate = this.date && this.date.valueOf(),
405
+ today = new Date();
406
+ this.picker.find('.datepicker-days thead th.date-switch')
407
+ .text(dates[this.language].months[month]+' '+year);
408
+ this.picker.find('tfoot th.today')
409
+ .text(dates[this.language].today)
410
+ .toggle(this.todayBtn !== false);
411
+ this.updateNavArrows();
412
+ this.fillMonths();
413
+ var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
414
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
415
+ prevMonth.setUTCDate(day);
416
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
417
+ var nextMonth = new Date(prevMonth.valueOf());
418
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
419
+ nextMonth = nextMonth.valueOf();
420
+ var html = [];
421
+ var clsName;
422
+ while(prevMonth.valueOf() < nextMonth) {
423
+ if (prevMonth.getUTCDay() == this.weekStart) {
424
+ html.push('<tr>');
425
+ if(this.calendarWeeks){
426
+ // adapted from https://github.com/timrwood/moment/blob/master/moment.js#L128
427
+ var a = new Date(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth(), prevMonth.getUTCDate() - prevMonth.getDay() + 10 - (this.weekStart && this.weekStart%7 < 5 && 7)),
428
+ b = new Date(a.getFullYear(), 0, 4),
429
+ calWeek = ~~((a - b) / 864e5 / 7 + 1.5);
430
+ html.push('<td class="cw">'+ calWeek +'</td>');
431
+ }
432
+ }
433
+ clsName = ' '+this.onRender(prevMonth)+' ';
434
+ if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
435
+ clsName += ' old';
436
+ } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
437
+ clsName += ' new';
438
+ }
439
+ // Compare internal UTC date with local today, not UTC today
440
+ if (this.todayHighlight &&
441
+ prevMonth.getUTCFullYear() == today.getFullYear() &&
442
+ prevMonth.getUTCMonth() == today.getMonth() &&
443
+ prevMonth.getUTCDate() == today.getDate()) {
444
+ clsName += ' today';
445
+ }
446
+ if (currentDate && prevMonth.valueOf() == currentDate) {
447
+ clsName += ' active';
448
+ }
449
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
450
+ $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
451
+ clsName += ' disabled';
452
+ }
453
+ html.push('<td class="day'+clsName+'">'+prevMonth.getUTCDate() + '</td>');
454
+ if (prevMonth.getUTCDay() == this.weekEnd) {
455
+ html.push('</tr>');
456
+ }
457
+ prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
458
+ }
459
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
460
+ var currentYear = this.date && this.date.getUTCFullYear();
461
+
462
+ var months = this.picker.find('.datepicker-months')
463
+ .find('th:eq(1)')
464
+ .text(year)
465
+ .end()
466
+ .find('span').removeClass('active');
467
+ if (currentYear && currentYear == year) {
468
+ months.eq(this.date.getUTCMonth()).addClass('active');
469
+ }
470
+ if (year < startYear || year > endYear) {
471
+ months.addClass('disabled');
472
+ }
473
+ if (year == startYear) {
474
+ months.slice(0, startMonth).addClass('disabled');
475
+ }
476
+ if (year == endYear) {
477
+ months.slice(endMonth+1).addClass('disabled');
478
+ }
479
+
480
+ html = '';
481
+ year = parseInt(year/10, 10) * 10;
482
+ var yearCont = this.picker.find('.datepicker-years')
483
+ .find('th:eq(1)')
484
+ .text(year + '-' + (year + 9))
485
+ .end()
486
+ .find('td');
487
+ year -= 1;
488
+ for (var i = -1; i < 11; i++) {
489
+ html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
490
+ year += 1;
491
+ }
492
+ yearCont.html(html);
493
+ },
494
+
495
+ updateNavArrows: function() {
496
+ var d = new Date(this.viewDate.valueOf()),
497
+ year = d.getUTCFullYear(),
498
+ month = d.getUTCMonth();
499
+ switch (this.viewMode) {
500
+ case 0:
501
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
502
+ this.picker.find('.prev').css({visibility: 'hidden'});
503
+ } else {
504
+ this.picker.find('.prev').css({visibility: 'visible'});
505
+ }
506
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
507
+ this.picker.find('.next').css({visibility: 'hidden'});
508
+ } else {
509
+ this.picker.find('.next').css({visibility: 'visible'});
510
+ }
511
+ break;
512
+ case 1:
513
+ case 2:
514
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
515
+ this.picker.find('.prev').css({visibility: 'hidden'});
516
+ } else {
517
+ this.picker.find('.prev').css({visibility: 'visible'});
518
+ }
519
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
520
+ this.picker.find('.next').css({visibility: 'hidden'});
521
+ } else {
522
+ this.picker.find('.next').css({visibility: 'visible'});
523
+ }
524
+ break;
525
+ }
526
+ },
527
+
528
+ click: function(e) {
529
+ e.stopPropagation();
530
+ e.preventDefault();
531
+
532
+ if ($(e.target).hasClass('datepicker-close')){
533
+ this.hide();
534
+ }
535
+
536
+ var target = $(e.target).closest('span, td, th');
537
+ if (target.length == 1) {
538
+ switch(target[0].nodeName.toLowerCase()) {
539
+ case 'th':
540
+ switch(target[0].className) {
541
+ case 'date-switch':
542
+ this.showMode(1);
543
+ break;
544
+ case 'prev':
545
+ case 'next':
546
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
547
+ switch(this.viewMode){
548
+ case 0:
549
+ this.viewDate = this.moveMonth(this.viewDate, dir);
550
+ break;
551
+ case 1:
552
+ case 2:
553
+ this.viewDate = this.moveYear(this.viewDate, dir);
554
+ break;
555
+ }
556
+ this.fill();
557
+ break;
558
+ case 'today':
559
+ var date = new Date();
560
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
561
+
562
+ this.showMode(-2);
563
+ var which = this.todayBtn == 'linked' ? null : 'view';
564
+ this._setDate(date, which);
565
+ break;
566
+ }
567
+ break;
568
+ case 'span':
569
+ if (!target.is('.disabled')) {
570
+ this.viewDate.setUTCDate(1);
571
+ if (target.is('.month')) {
572
+ var month = target.parent().find('span').index(target);
573
+ this.viewDate.setUTCMonth(month);
574
+ this.element.trigger({
575
+ type: 'changeMonth',
576
+ date: this.viewDate
577
+ });
578
+ } else {
579
+ var year = parseInt(target.text(), 10)||0;
580
+ this.viewDate.setUTCFullYear(year);
581
+ this.element.trigger({
582
+ type: 'changeYear',
583
+ date: this.viewDate
584
+ });
585
+ }
586
+ this.showMode(-1);
587
+ this.fill();
588
+ }
589
+ break;
590
+ case 'td':
591
+ if (target.is('.day') && !target.is('.disabled')){
592
+ var day = parseInt(target.text(), 10)||1;
593
+ var year = this.viewDate.getUTCFullYear(),
594
+ month = this.viewDate.getUTCMonth();
595
+ if (target.is('.old')) {
596
+ if (month === 0) {
597
+ month = 11;
598
+ year -= 1;
599
+ } else {
600
+ month -= 1;
601
+ }
602
+ } else if (target.is('.new')) {
603
+ if (month == 11) {
604
+ month = 0;
605
+ year += 1;
606
+ } else {
607
+ month += 1;
608
+ }
609
+ }
610
+ this._setDate(UTCDate(year, month, day,0,0,0,0));
611
+ }
612
+ break;
613
+ }
614
+ }
615
+ },
616
+
617
+ _setDate: function(date, which){
618
+ if (!which || which == 'date')
619
+ this.date = date;
620
+ if (!which || which == 'view')
621
+ this.viewDate = date;
622
+ this.fill();
623
+ this.setValue();
624
+ this.element.trigger({
625
+ type: 'changeDate',
626
+ date: this.date
627
+ });
628
+ var element;
629
+ if (this.isInput) {
630
+ element = this.element;
631
+ } else if (this.component){
632
+ element = this.element.find('input');
633
+ }
634
+ if (element) {
635
+ element.change();
636
+ if (this.autoclose && (!which || which == 'date')) {
637
+ this.hide();
638
+ }
639
+ }
640
+ },
641
+
642
+ moveMonth: function(date, dir){
643
+ if (!dir) return date;
644
+ var new_date = new Date(date.valueOf()),
645
+ day = new_date.getUTCDate(),
646
+ month = new_date.getUTCMonth(),
647
+ mag = Math.abs(dir),
648
+ new_month, test;
649
+ dir = dir > 0 ? 1 : -1;
650
+ if (mag == 1){
651
+ test = dir == -1
652
+ // If going back one month, make sure month is not current month
653
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
654
+ ? function(){ return new_date.getUTCMonth() == month; }
655
+ // If going forward one month, make sure month is as expected
656
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
657
+ : function(){ return new_date.getUTCMonth() != new_month; };
658
+ new_month = month + dir;
659
+ new_date.setUTCMonth(new_month);
660
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
661
+ if (new_month < 0 || new_month > 11)
662
+ new_month = (new_month + 12) % 12;
663
+ } else {
664
+ // For magnitudes >1, move one month at a time...
665
+ for (var i=0; i<mag; i++)
666
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
667
+ new_date = this.moveMonth(new_date, dir);
668
+ // ...then reset the day, keeping it in the new month
669
+ new_month = new_date.getUTCMonth();
670
+ new_date.setUTCDate(day);
671
+ test = function(){ return new_month != new_date.getUTCMonth(); };
672
+ }
673
+ // Common date-resetting loop -- if date is beyond end of month, make it
674
+ // end of month
675
+ while (test()){
676
+ new_date.setUTCDate(--day);
677
+ new_date.setUTCMonth(new_month);
678
+ }
679
+ return new_date;
680
+ },
681
+
682
+ moveYear: function(date, dir){
683
+ return this.moveMonth(date, dir*12);
684
+ },
685
+
686
+ dateWithinRange: function(date){
687
+ return date >= this.startDate && date <= this.endDate;
688
+ },
689
+
690
+ keydown: function(e){
691
+ if (this.picker.is(':not(:visible)')){
692
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
693
+ this.show();
694
+ return;
695
+ }
696
+ var dateChanged = false,
697
+ dir, day, month,
698
+ newDate, newViewDate;
699
+ switch(e.keyCode){
700
+ case 27: // escape
701
+ this.hide();
702
+ e.preventDefault();
703
+ break;
704
+ case 37: // left
705
+ case 39: // right
706
+ if (!this.keyboardNavigation) break;
707
+ dir = e.keyCode == 37 ? -1 : 1;
708
+ if (e.ctrlKey){
709
+ newDate = this.moveYear(this.date, dir);
710
+ newViewDate = this.moveYear(this.viewDate, dir);
711
+ } else if (e.shiftKey){
712
+ newDate = this.moveMonth(this.date, dir);
713
+ newViewDate = this.moveMonth(this.viewDate, dir);
714
+ } else {
715
+ newDate = new Date(this.date.valueOf());
716
+ newDate.setUTCDate(this.date.getUTCDate() + dir);
717
+ newViewDate = new Date(this.viewDate.valueOf());
718
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
719
+ }
720
+ if (this.dateWithinRange(newDate)){
721
+ this.date = newDate;
722
+ this.viewDate = newViewDate;
723
+ this.setValue();
724
+ this.update();
725
+ e.preventDefault();
726
+ dateChanged = true;
727
+ }
728
+ break;
729
+ case 38: // up
730
+ case 40: // down
731
+ if (!this.keyboardNavigation) break;
732
+ dir = e.keyCode == 38 ? -1 : 1;
733
+ if (e.ctrlKey){
734
+ newDate = this.moveYear(this.date, dir);
735
+ newViewDate = this.moveYear(this.viewDate, dir);
736
+ } else if (e.shiftKey){
737
+ newDate = this.moveMonth(this.date, dir);
738
+ newViewDate = this.moveMonth(this.viewDate, dir);
739
+ } else {
740
+ newDate = new Date(this.date.valueOf());
741
+ newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
742
+ newViewDate = new Date(this.viewDate.valueOf());
743
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
744
+ }
745
+ if (this.dateWithinRange(newDate)){
746
+ this.date = newDate;
747
+ this.viewDate = newViewDate;
748
+ this.setValue();
749
+ this.update();
750
+ e.preventDefault();
751
+ dateChanged = true;
752
+ }
753
+ break;
754
+ case 13: // enter
755
+ this.hide();
756
+ e.preventDefault();
757
+ break;
758
+ case 9: // tab
759
+ this.hide();
760
+ break;
761
+ }
762
+ if (dateChanged){
763
+ this.element.trigger({
764
+ type: 'changeDate',
765
+ date: this.date
766
+ });
767
+ var element;
768
+ if (this.isInput) {
769
+ element = this.element;
770
+ } else if (this.component){
771
+ element = this.element.find('input');
772
+ }
773
+ if (element) {
774
+ element.change();
775
+ }
776
+ }
777
+ },
778
+
779
+ showMode: function(dir) {
780
+ if (dir) {
781
+ this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
782
+ }
783
+ /*
784
+ vitalets: fixing bug of very special conditions:
785
+ jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
786
+ Method show() does not set display css correctly and datepicker is not shown.
787
+ Changed to .css('display', 'block') solve the problem.
788
+ See https://github.com/vitalets/x-editable/issues/37
789
+
790
+ In jquery 1.7.2+ everything works fine.
791
+ */
792
+ //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
793
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
794
+ this.updateNavArrows();
795
+ }
796
+ };
797
+
798
+ $.fn.fdatepicker = function ( option ) {
799
+ var args = Array.apply(null, arguments);
800
+ args.shift();
801
+ return this.each(function () {
802
+ var $this = $(this),
803
+ data = $this.data('datepicker'),
804
+ options = typeof option == 'object' && option;
805
+ if (!data) {
806
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.fdatepicker.defaults,options))));
807
+ }
808
+ if (typeof option == 'string' && typeof data[option] == 'function') {
809
+ data[option].apply(data, args);
810
+ }
811
+ });
812
+ };
813
+
814
+ $.fn.fdatepicker.defaults = {
815
+ onRender: function(date) {
816
+ return '';
817
+ }
818
+ };
819
+ $.fn.fdatepicker.Constructor = Datepicker;
820
+ var dates = $.fn.fdatepicker.dates = {
821
+ en: {
822
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
823
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
824
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
825
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
826
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
827
+ today: "Today"
828
+ },
829
+ pl: {
830
+ days: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota", "Niedziela"],
831
+ daysShort: ["Nie", "Pon", "Wt", "Śr", "Czw", "Pt", "Sob", "Nie"],
832
+ daysMin: ["Nd", "Po", "Wt", "Śr", "Czw", "Pt", "So", "Nd"],
833
+ months: ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"],
834
+ monthsShort: ["Sty", "Lut", "Mar", "Kwi", "Maj", "Cze", "Lip", "Sie", "Wrz", "Paź", "Lit", "Gru"],
835
+ today: "Dzisiaj"
836
+ },
837
+ es: {
838
+ days: ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"],
839
+ daysShort: ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab", "Dom"],
840
+ daysMin: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
841
+ months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Deciembre"],
842
+ monthsShort: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
843
+ today: "Hoy"
844
+ },
845
+ pt: {
846
+ days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo"],
847
+ daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"],
848
+ daysMin: ["Do", "Se", "Te", "Qu", "Qu", "Se", "Sá", "Do"],
849
+ months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
850
+ monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
851
+ today: "Hoje"
852
+ },
853
+ it: {
854
+ days: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato", "Domenica"],
855
+ daysShort: ["Dom", "Lun", "Mar", "Mer", "Gio", "Veb", "Sab", "Dom"],
856
+ daysMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"],
857
+ months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
858
+ monthsShort: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
859
+ today: "Oggi"
860
+ }
861
+ };
862
+
863
+ var DPGlobal = {
864
+ modes: [
865
+ {
866
+ clsName: 'days',
867
+ navFnc: 'Month',
868
+ navStep: 1
869
+ },
870
+ {
871
+ clsName: 'months',
872
+ navFnc: 'FullYear',
873
+ navStep: 1
874
+ },
875
+ {
876
+ clsName: 'years',
877
+ navFnc: 'FullYear',
878
+ navStep: 10
879
+ }],
880
+ isLeapYear: function (year) {
881
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
882
+ },
883
+ getDaysInMonth: function (year, month) {
884
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
885
+ },
886
+ validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
887
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
888
+ parseFormat: function(format){
889
+ // IE treats \0 as a string end in inputs (truncating the value),
890
+ // so it's a bad format delimiter, anyway
891
+ var separators = format.replace(this.validParts, '\0').split('\0'),
892
+ parts = format.match(this.validParts);
893
+ if (!separators || !separators.length || !parts || parts.length === 0){
894
+ throw new Error("Invalid date format.");
895
+ }
896
+ return {separators: separators, parts: parts};
897
+ },
898
+ parseDate: function(date, format, language) {
899
+ if (date instanceof Date) return date;
900
+ if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
901
+ var part_re = /([\-+]\d+)([dmwy])/,
902
+ parts = date.match(/([\-+]\d+)([dmwy])/g),
903
+ part, dir;
904
+ date = new Date();
905
+ for (var i=0; i<parts.length; i++) {
906
+ part = part_re.exec(parts[i]);
907
+ dir = parseInt(part[1]);
908
+ switch(part[2]){
909
+ case 'd':
910
+ date.setUTCDate(date.getUTCDate() + dir);
911
+ break;
912
+ case 'm':
913
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
914
+ break;
915
+ case 'w':
916
+ date.setUTCDate(date.getUTCDate() + dir * 7);
917
+ break;
918
+ case 'y':
919
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
920
+ break;
921
+ }
922
+ }
923
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
924
+ }
925
+ var parts = date && date.match(this.nonpunctuation) || [],
926
+ date = new Date(),
927
+ parsed = {},
928
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
929
+ setters_map = {
930
+ yyyy: function(d,v){ return d.setUTCFullYear(v); },
931
+ yy: function(d,v){ return d.setUTCFullYear(2000+v); },
932
+ m: function(d,v){
933
+ v -= 1;
934
+ while (v<0) v += 12;
935
+ v %= 12;
936
+ d.setUTCMonth(v);
937
+ while (d.getUTCMonth() != v)
938
+ d.setUTCDate(d.getUTCDate()-1);
939
+ return d;
940
+ },
941
+ d: function(d,v){ return d.setUTCDate(v); }
942
+ },
943
+ val, filtered, part;
944
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
945
+ setters_map['dd'] = setters_map['d'];
946
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
947
+ var fparts = format.parts.slice();
948
+ // Remove noop parts
949
+ if (parts.length != fparts.length) {
950
+ fparts = $(fparts).filter(function(i,p){
951
+ return $.inArray(p, setters_order) !== -1;
952
+ }).toArray();
953
+ }
954
+ // Process remainder
955
+ if (parts.length == fparts.length) {
956
+ for (var i=0, cnt = fparts.length; i < cnt; i++) {
957
+ val = parseInt(parts[i], 10);
958
+ part = fparts[i];
959
+ if (isNaN(val)) {
960
+ switch(part) {
961
+ case 'MM':
962
+ filtered = $(dates[language].months).filter(function(){
963
+ var m = this.slice(0, parts[i].length),
964
+ p = parts[i].slice(0, m.length);
965
+ return m == p;
966
+ });
967
+ val = $.inArray(filtered[0], dates[language].months) + 1;
968
+ break;
969
+ case 'M':
970
+ filtered = $(dates[language].monthsShort).filter(function(){
971
+ var m = this.slice(0, parts[i].length),
972
+ p = parts[i].slice(0, m.length);
973
+ return m == p;
974
+ });
975
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
976
+ break;
977
+ }
978
+ }
979
+ parsed[part] = val;
980
+ }
981
+ for (var i=0, s; i<setters_order.length; i++){
982
+ s = setters_order[i];
983
+ if (s in parsed && !isNaN(parsed[s]))
984
+ setters_map[s](date, parsed[s]);
985
+ }
986
+ }
987
+ return date;
988
+ },
989
+ formatDate: function(date, format, language){
990
+ var val = {
991
+ d: date.getUTCDate(),
992
+ D: dates[language].daysShort[date.getUTCDay()],
993
+ DD: dates[language].days[date.getUTCDay()],
994
+ m: date.getUTCMonth() + 1,
995
+ M: dates[language].monthsShort[date.getUTCMonth()],
996
+ MM: dates[language].months[date.getUTCMonth()],
997
+ yy: date.getUTCFullYear().toString().substring(2),
998
+ yyyy: date.getUTCFullYear()
999
+ };
1000
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1001
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1002
+ var date = [],
1003
+ seps = $.extend([], format.separators);
1004
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
1005
+ if (seps.length)
1006
+ date.push(seps.shift());
1007
+ date.push(val[format.parts[i]]);
1008
+ }
1009
+ return date.join('');
1010
+ },
1011
+ headTemplate: '<thead>'+
1012
+ '<tr>'+
1013
+ '<th class="prev"><i class="icon-chevron-left fa fa-chevron-left"/></th>'+
1014
+ '<th colspan="5" class="date-switch"></th>'+
1015
+ '<th class="next"><i class="icon-chevron-right fa fa-chevron-right"/></th>'+
1016
+ '</tr>'+
1017
+ '</thead>',
1018
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1019
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1020
+ };
1021
+ DPGlobal.template = '<div class="datepicker">'+
1022
+
1023
+ '<div class="datepicker-days">'+
1024
+ '<table class=" table-condensed">'+
1025
+ DPGlobal.headTemplate+
1026
+ '<tbody></tbody>'+
1027
+ DPGlobal.footTemplate+
1028
+ '</table>'+
1029
+ '</div>'+
1030
+ '<div class="datepicker-months">'+
1031
+ '<table class="table-condensed">'+
1032
+ DPGlobal.headTemplate+
1033
+ DPGlobal.contTemplate+
1034
+ DPGlobal.footTemplate+
1035
+ '</table>'+
1036
+ '</div>'+
1037
+ '<div class="datepicker-years">'+
1038
+ '<table class="table-condensed">'+
1039
+ DPGlobal.headTemplate+
1040
+ DPGlobal.contTemplate+
1041
+ DPGlobal.footTemplate+
1042
+ '</table>'+
1043
+ '</div>'+
1044
+ '<a class="button datepicker-close small alert right" style="width:auto;"><i class="icon-remove fa fa-times"></i></a>'+
1045
+ '</div>';
1046
+
1047
+ $.fn.fdatepicker.DPGlobal = DPGlobal;
1048
+
1049
+ }( window.jQuery );