foundation-datepicker-rails 0.0.1

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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +42 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/foundation-datepicker-rails.gemspec +23 -0
  13. data/lib/foundation-datepicker-rails.rb +1 -0
  14. data/lib/foundation/datepicker/rails.rb +2 -0
  15. data/lib/foundation/datepicker/rails/engine.rb +11 -0
  16. data/lib/foundation/datepicker/rails/version.rb +7 -0
  17. data/vendor/assets/javascripts/foundation-datepicker.js +1325 -0
  18. data/vendor/assets/javascripts/foundation-datepicker.min.js +1 -0
  19. data/vendor/assets/javascripts/locales/foundation-datepicker.ar.js +15 -0
  20. data/vendor/assets/javascripts/locales/foundation-datepicker.az.js +12 -0
  21. data/vendor/assets/javascripts/locales/foundation-datepicker.bg.js +14 -0
  22. data/vendor/assets/javascripts/locales/foundation-datepicker.bs.js +15 -0
  23. data/vendor/assets/javascripts/locales/foundation-datepicker.ca.js +17 -0
  24. data/vendor/assets/javascripts/locales/foundation-datepicker.cs.js +14 -0
  25. data/vendor/assets/javascripts/locales/foundation-datepicker.cy.js +14 -0
  26. data/vendor/assets/javascripts/locales/foundation-datepicker.da.js +14 -0
  27. data/vendor/assets/javascripts/locales/foundation-datepicker.de.js +14 -0
  28. data/vendor/assets/javascripts/locales/foundation-datepicker.el.js +13 -0
  29. data/vendor/assets/javascripts/locales/foundation-datepicker.en-GB.js +17 -0
  30. data/vendor/assets/javascripts/locales/foundation-datepicker.eo.js +17 -0
  31. data/vendor/assets/javascripts/locales/foundation-datepicker.es.js +14 -0
  32. data/vendor/assets/javascripts/locales/foundation-datepicker.et.js +18 -0
  33. data/vendor/assets/javascripts/locales/foundation-datepicker.eu.js +15 -0
  34. data/vendor/assets/javascripts/locales/foundation-datepicker.fa.js +17 -0
  35. data/vendor/assets/javascripts/locales/foundation-datepicker.fi.js +14 -0
  36. data/vendor/assets/javascripts/locales/foundation-datepicker.fo.js +15 -0
  37. data/vendor/assets/javascripts/locales/foundation-datepicker.fr-CH.js +20 -0
  38. data/vendor/assets/javascripts/locales/foundation-datepicker.fr.js +14 -0
  39. data/vendor/assets/javascripts/locales/foundation-datepicker.gl.js +13 -0
  40. data/vendor/assets/javascripts/locales/foundation-datepicker.he.js +15 -0
  41. data/vendor/assets/javascripts/locales/foundation-datepicker.hr.js +13 -0
  42. data/vendor/assets/javascripts/locales/foundation-datepicker.hu.js +13 -0
  43. data/vendor/assets/javascripts/locales/foundation-datepicker.hy.js +17 -0
  44. data/vendor/assets/javascripts/locales/foundation-datepicker.id.js +13 -0
  45. data/vendor/assets/javascripts/locales/foundation-datepicker.is.js +14 -0
  46. data/vendor/assets/javascripts/locales/foundation-datepicker.it-CH.js +20 -0
  47. data/vendor/assets/javascripts/locales/foundation-datepicker.it.js +14 -0
  48. data/vendor/assets/javascripts/locales/foundation-datepicker.ja.js +16 -0
  49. data/vendor/assets/javascripts/locales/foundation-datepicker.ka.js +17 -0
  50. data/vendor/assets/javascripts/locales/foundation-datepicker.kh.js +15 -0
  51. data/vendor/assets/javascripts/locales/foundation-datepicker.kk.js +15 -0
  52. data/vendor/assets/javascripts/locales/foundation-datepicker.ko.js +18 -0
  53. data/vendor/assets/javascripts/locales/foundation-datepicker.kr.js +13 -0
  54. data/vendor/assets/javascripts/locales/foundation-datepicker.lt.js +16 -0
  55. data/vendor/assets/javascripts/locales/foundation-datepicker.lv.js +16 -0
  56. data/vendor/assets/javascripts/locales/foundation-datepicker.me.js +17 -0
  57. data/vendor/assets/javascripts/locales/foundation-datepicker.mk.js +15 -0
  58. data/vendor/assets/javascripts/locales/foundation-datepicker.mn.js +17 -0
  59. data/vendor/assets/javascripts/locales/foundation-datepicker.ms.js +14 -0
  60. data/vendor/assets/javascripts/locales/foundation-datepicker.nb.js +14 -0
  61. data/vendor/assets/javascripts/locales/foundation-datepicker.nl-BE.js +17 -0
  62. data/vendor/assets/javascripts/locales/foundation-datepicker.nl.js +14 -0
  63. data/vendor/assets/javascripts/locales/foundation-datepicker.no.js +13 -0
  64. data/vendor/assets/javascripts/locales/foundation-datepicker.pl.js +15 -0
  65. data/vendor/assets/javascripts/locales/foundation-datepicker.pt-br.js +14 -0
  66. data/vendor/assets/javascripts/locales/foundation-datepicker.pt.js +14 -0
  67. data/vendor/assets/javascripts/locales/foundation-datepicker.ro.js +15 -0
  68. data/vendor/assets/javascripts/locales/foundation-datepicker.rs-latin.js +14 -0
  69. data/vendor/assets/javascripts/locales/foundation-datepicker.rs.js +14 -0
  70. data/vendor/assets/javascripts/locales/foundation-datepicker.ru.js +14 -0
  71. data/vendor/assets/javascripts/locales/foundation-datepicker.sk.js +14 -0
  72. data/vendor/assets/javascripts/locales/foundation-datepicker.sl.js +14 -0
  73. data/vendor/assets/javascripts/locales/foundation-datepicker.sq.js +15 -0
  74. data/vendor/assets/javascripts/locales/foundation-datepicker.sr-latin.js +16 -0
  75. data/vendor/assets/javascripts/locales/foundation-datepicker.sr.js +16 -0
  76. data/vendor/assets/javascripts/locales/foundation-datepicker.sv.js +14 -0
  77. data/vendor/assets/javascripts/locales/foundation-datepicker.sw.js +15 -0
  78. data/vendor/assets/javascripts/locales/foundation-datepicker.th.js +14 -0
  79. data/vendor/assets/javascripts/locales/foundation-datepicker.tr.js +15 -0
  80. data/vendor/assets/javascripts/locales/foundation-datepicker.uk.js +14 -0
  81. data/vendor/assets/javascripts/locales/foundation-datepicker.vi.js +15 -0
  82. data/vendor/assets/javascripts/locales/foundation-datepicker.zh-CN.js +14 -0
  83. data/vendor/assets/javascripts/locales/foundation-datepicker.zh-TW.js +14 -0
  84. data/vendor/assets/stylesheets/foundation-datepicker.css +148 -0
  85. data/vendor/assets/stylesheets/foundation-datepicker.css.map +7 -0
  86. data/vendor/assets/stylesheets/foundation-datepicker.min.css +1 -0
  87. metadata +173 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64af78d12657bb68a03b8d5cd3e676579ee96f82
4
+ data.tar.gz: 144e00f2f41e38fa0cef650eb7242749b899353d
5
+ SHA512:
6
+ metadata.gz: 10f7440a34fbc883c4c3cb700ade060f040f19f88efc5a6d2c1c0f6dc8366750d4ee316e9816a3f4bb9808d1cc0910a54b3a884fe3d011ea7a26e315f81836e8
7
+ data.tar.gz: 3a9d4a6d255aaeaad96daa4aad3292f46b879113bb24e12f1d372f5de93fd901fa018fef5fd3ac3282d31a42f8daf0168ad650fca984e1e7933b79519e0e2416
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at peeyush.hsuyeep@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foundation-datepicker-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Peeyush Kumar
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.
@@ -0,0 +1,42 @@
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 foundation-datepicker
24
+ */
25
+ ```
26
+
27
+ Include this lines in `app/assets/javascripts/application.js`:
28
+
29
+ ```
30
+ //
31
+ //= require foundation-datepicker
32
+ //
33
+ ```
34
+
35
+ Note: to see the arrows and icons, please include [font-awesome](https://github.com/bokmann/font-awesome-rails) or [foundation-icons-sass-rails](https://github.com/zaiste/foundation-icons-sass-rails)
36
+
37
+ Next, call the datepicker via javascript:
38
+
39
+
40
+ `$('.datepicker').fdatepicker()`
41
+
42
+ There are numerous options for the datepicker. You can find them [here](http://foundation-datepicker.peterbeno.com/example.html).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "foundation/datepicker/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foundation/datepicker/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foundation-datepicker-rails"
8
+ spec.version = Foundation::Datepicker::Rails::VERSION
9
+ spec.authors = ["Kurt Mueller", "Peeyush Kumar"]
10
+ spec.email = ["mueller.128@osu.edu", "peeyush.hsuyeep@gmail.com"]
11
+ spec.homepage = "http://github.com/KurtRMueller/foundation_datepicker_rails"
12
+ spec.summary = "Rails gem for foundation-datepicker."
13
+ spec.description = "A simple assets gem for foundation-datepicker, whose documentation can be found here: http://foundation-datepicker.peterbeno.com/example.html"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
@@ -0,0 +1 @@
1
+ require 'foundation/datepicker/rails'
@@ -0,0 +1,2 @@
1
+ require "foundation/datepicker/rails/version"
2
+ require 'foundation/datepicker/rails/engine'
@@ -0,0 +1,11 @@
1
+ require "rails"
2
+
3
+ module Foundation
4
+ module Datepicker
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace Foundation::Datepicker::Rails
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Foundation
2
+ module Datepicker
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,1325 @@
1
+ /* =========================================================
2
+ * foundation-datepicker.js
3
+ * Copyright 2015 Peter Beno, najlepsiwebdesigner@gmail.com, @benopeter
4
+ * project website http://foundation-datepicker.peterbeno.com
5
+ * ========================================================= */
6
+ ! function($) {
7
+
8
+ function UTCDate() {
9
+ return new Date(Date.UTC.apply(Date, arguments));
10
+ }
11
+
12
+ function UTCToday() {
13
+ var today = new Date();
14
+ return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
15
+ }
16
+
17
+ var Datepicker = function(element, options) {
18
+ var that = this;
19
+
20
+ this.element = $(element);
21
+ this.autoShow = options.autoShow || true;
22
+ this.appendTo = options.appendTo || 'body';
23
+ this.closeButton = options.closeButton;
24
+ this.language = options.language || this.element.data('date-language') || "en";
25
+ 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"
26
+ this.language = this.language in dates ? this.language : "en";
27
+ this.isRTL = dates[this.language].rtl || false;
28
+ this.format = DPGlobal.parseFormat(options.format || this.element.data('date-format') || dates[this.language].format || 'mm/dd/yyyy');
29
+ this.isInline = false;
30
+ this.isInput = this.element.is('input');
31
+ this.component = this.element.is('.date') ? this.element.find('.prefix, .postfix') : false;
32
+ this.hasInput = this.component && this.element.find('input').length;
33
+ this.disableDblClickSelection = options.disableDblClickSelection;
34
+ this.onRender = options.onRender || function() {};
35
+ if (this.component && this.component.length === 0) {
36
+ this.component = false;
37
+ }
38
+ this.linkField = options.linkField || this.element.data('link-field') || false;
39
+ this.linkFormat = DPGlobal.parseFormat(options.linkFormat || this.element.data('link-format') || 'yyyy-mm-dd hh:ii:ss');
40
+ this.minuteStep = options.minuteStep || this.element.data('minute-step') || 5;
41
+ this.pickerPosition = options.pickerPosition || this.element.data('picker-position') || 'bottom-right';
42
+
43
+ this._attachEvents();
44
+
45
+
46
+ this.minView = 0;
47
+ if ('minView' in options) {
48
+ this.minView = options.minView;
49
+ } else if ('minView' in this.element.data()) {
50
+ this.minView = this.element.data('min-view');
51
+ }
52
+ this.minView = DPGlobal.convertViewMode(this.minView);
53
+
54
+ this.maxView = DPGlobal.modes.length - 1;
55
+ if ('maxView' in options) {
56
+ this.maxView = options.maxView;
57
+ } else if ('maxView' in this.element.data()) {
58
+ this.maxView = this.element.data('max-view');
59
+ }
60
+ this.maxView = DPGlobal.convertViewMode(this.maxView);
61
+
62
+ this.startViewMode = 'month';
63
+ if ('startView' in options) {
64
+ this.startViewMode = options.startView;
65
+ } else if ('startView' in this.element.data()) {
66
+ this.startViewMode = this.element.data('start-view');
67
+ }
68
+ this.startViewMode = DPGlobal.convertViewMode(this.startViewMode);
69
+ this.viewMode = this.startViewMode;
70
+
71
+ if (!('minView' in options) && !('maxView' in options) && !(this.element.data('min-view') && !(this.element.data('max-view')))) {
72
+ this.pickTime = false;
73
+ if ('pickTime' in options) {
74
+ this.pickTime = options.pickTime;
75
+ }
76
+ if (this.pickTime == true) {
77
+ this.minView = 0;
78
+ this.maxView = 4;
79
+ } else {
80
+ this.minView = 2;
81
+ this.maxView = 4;
82
+ }
83
+ }
84
+
85
+ this.forceParse = true;
86
+ if ('forceParse' in options) {
87
+ this.forceParse = options.forceParse;
88
+ } else if ('dateForceParse' in this.element.data()) {
89
+ this.forceParse = this.element.data('date-force-parse');
90
+ }
91
+
92
+
93
+ this.picker = $(DPGlobal.template)
94
+ .appendTo(this.isInline ? this.element : this.appendTo)
95
+ .on({
96
+ click: $.proxy(this.click, this),
97
+ mousedown: $.proxy(this.mousedown, this)
98
+ });
99
+ if (this.closeButton) {
100
+ this.picker.find('a.datepicker-close').show();
101
+ } else {
102
+ this.picker.find('a.datepicker-close').hide();
103
+ }
104
+
105
+ if (this.isInline) {
106
+ this.picker.addClass('datepicker-inline');
107
+ } else {
108
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
109
+ }
110
+ if (this.isRTL) {
111
+ this.picker.addClass('datepicker-rtl');
112
+ this.picker.find('.prev i, .next i')
113
+ .toggleClass('fa fa-chevron-left fa-chevron-right').toggleClass('fa-chevron-left fa-chevron-right');
114
+ }
115
+ $(document).on('mousedown', function(e) {
116
+ // Clicked outside the datepicker, hide it
117
+ if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
118
+ that.hide();
119
+ }
120
+ });
121
+
122
+ this.autoclose = true;
123
+ if ('autoclose' in options) {
124
+ this.autoclose = options.autoclose;
125
+ } else if ('dateAutoclose' in this.element.data()) {
126
+ this.autoclose = this.element.data('date-autoclose');
127
+ }
128
+
129
+ this.keyboardNavigation = true;
130
+ if ('keyboardNavigation' in options) {
131
+ this.keyboardNavigation = options.keyboardNavigation;
132
+ } else if ('dateKeyboardNavigation' in this.element.data()) {
133
+ this.keyboardNavigation = this.element.data('date-keyboard-navigation');
134
+ }
135
+
136
+ this.todayBtn = (options.todayBtn || this.element.data('date-today-btn') || false);
137
+ this.todayHighlight = (options.todayHighlight || this.element.data('date-today-highlight') || false);
138
+
139
+ this.calendarWeeks = false;
140
+ if ('calendarWeeks' in options) {
141
+ this.calendarWeeks = options.calendarWeeks;
142
+ } else if ('dateCalendarWeeks' in this.element.data()) {
143
+ this.calendarWeeks = this.element.data('date-calendar-weeks');
144
+ }
145
+ if (this.calendarWeeks)
146
+ this.picker.find('tfoot th.today')
147
+ .attr('colspan', function(i, val) {
148
+ return parseInt(val) + 1;
149
+ });
150
+
151
+ this.weekStart = ((options.weekStart || this.element.data('date-weekstart') || dates[this.language].weekStart || 0) % 7);
152
+ this.weekEnd = ((this.weekStart + 6) % 7);
153
+ this.startDate = -Infinity;
154
+ this.endDate = Infinity;
155
+ this.daysOfWeekDisabled = [];
156
+ this.setStartDate(options.startDate || this.element.data('date-startdate'));
157
+ this.setEndDate(options.endDate || this.element.data('date-enddate'));
158
+ this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled'));
159
+
160
+ this.fillDow();
161
+ this.fillMonths();
162
+ this.update();
163
+
164
+ this.showMode();
165
+
166
+ if (this.isInline) {
167
+ this.show();
168
+ }
169
+ };
170
+
171
+ Datepicker.prototype = {
172
+ constructor: Datepicker,
173
+
174
+ _events: [],
175
+ _attachEvents: function() {
176
+ this._detachEvents();
177
+ if (this.isInput) { // single input
178
+ this._events = [
179
+ [this.element, {
180
+ focus: (this.autoShow) ? $.proxy(this.show, this) : function() {},
181
+ keyup: $.proxy(this.update, this),
182
+ keydown: $.proxy(this.keydown, this)
183
+ }]
184
+ ];
185
+ } else if (this.component && this.hasInput) { // component: input + button
186
+ this._events = [
187
+ // For components that are not readonly, allow keyboard nav
188
+ [this.element.find('input'), {
189
+ focus: (this.autoShow) ? $.proxy(this.show, this) : function() {},
190
+ keyup: $.proxy(this.update, this),
191
+ keydown: $.proxy(this.keydown, this)
192
+ }],
193
+ [this.component, {
194
+ click: $.proxy(this.show, this)
195
+ }]
196
+ ];
197
+ } else if (this.element.is('div')) { // inline datepicker
198
+ this.isInline = true;
199
+ } else {
200
+ this._events = [
201
+ [this.element, {
202
+ click: $.proxy(this.show, this)
203
+ }]
204
+ ];
205
+ }
206
+
207
+ if (this.disableDblClickSelection) {
208
+ this._events[this._events.length] = [
209
+ this.element, {
210
+ dblclick: function(e) {
211
+ e.preventDefault();
212
+ e.stopPropagation();
213
+ $(this).blur()
214
+ }
215
+ }
216
+ ];
217
+ }
218
+
219
+ for (var i = 0, el, ev; i < this._events.length; i++) {
220
+ el = this._events[i][0];
221
+ ev = this._events[i][1];
222
+ el.on(ev);
223
+ }
224
+ },
225
+ _detachEvents: function() {
226
+ for (var i = 0, el, ev; i < this._events.length; i++) {
227
+ el = this._events[i][0];
228
+ ev = this._events[i][1];
229
+ el.off(ev);
230
+ }
231
+ this._events = [];
232
+ },
233
+
234
+ show: function(e) {
235
+ this.picker.show();
236
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
237
+ this.update();
238
+ this.place();
239
+ $(window).on('resize', $.proxy(this.place, this));
240
+ if (e) {
241
+ e.stopPropagation();
242
+ e.preventDefault();
243
+ }
244
+ this.element.trigger({
245
+ type: 'show',
246
+ date: this.date
247
+ });
248
+ },
249
+
250
+ hide: function(e) {
251
+ if (this.isInline) return;
252
+ if (!this.picker.is(':visible')) return;
253
+ this.picker.hide();
254
+ $(window).off('resize', this.place);
255
+ this.viewMode = this.startViewMode;
256
+ this.showMode();
257
+ if (!this.isInput) {
258
+ $(document).off('mousedown', this.hide);
259
+ }
260
+
261
+ if (
262
+ this.forceParse &&
263
+ (
264
+ this.isInput && this.element.val() ||
265
+ this.hasInput && this.element.find('input').val()
266
+ )
267
+ )
268
+ this.setValue();
269
+ this.element.trigger({
270
+ type: 'hide',
271
+ date: this.date
272
+ });
273
+ },
274
+
275
+ remove: function() {
276
+ this._detachEvents();
277
+ this.picker.remove();
278
+ delete this.element.data().datepicker;
279
+ },
280
+
281
+ getDate: function() {
282
+ var d = this.getUTCDate();
283
+ return new Date(d.getTime() + (d.getTimezoneOffset() * 60000));
284
+ },
285
+
286
+ getUTCDate: function() {
287
+ return this.date;
288
+ },
289
+
290
+ setDate: function(d) {
291
+ this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset() * 60000)));
292
+ },
293
+
294
+ setUTCDate: function(d) {
295
+ this.date = d;
296
+ this.setValue();
297
+ },
298
+
299
+ setValue: function() {
300
+ var formatted = this.getFormattedDate();
301
+ if (!this.isInput) {
302
+ if (this.component) {
303
+ this.element.find('input').val(formatted);
304
+ }
305
+ this.element.data('date', formatted);
306
+ } else {
307
+ this.element.val(formatted);
308
+ }
309
+ },
310
+
311
+ getFormattedDate: function(format) {
312
+ if (format === undefined)
313
+ format = this.format;
314
+ return DPGlobal.formatDate(this.date, format, this.language);
315
+ },
316
+
317
+ setStartDate: function(startDate) {
318
+ this.startDate = startDate || -Infinity;
319
+ if (this.startDate !== -Infinity) {
320
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
321
+ }
322
+ this.update();
323
+ this.updateNavArrows();
324
+ },
325
+
326
+ setEndDate: function(endDate) {
327
+ this.endDate = endDate || Infinity;
328
+ if (this.endDate !== Infinity) {
329
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
330
+ }
331
+ this.update();
332
+ this.updateNavArrows();
333
+ },
334
+
335
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled) {
336
+ this.daysOfWeekDisabled = daysOfWeekDisabled || [];
337
+ if (!$.isArray(this.daysOfWeekDisabled)) {
338
+ this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
339
+ }
340
+ this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function(d) {
341
+ return parseInt(d, 10);
342
+ });
343
+ this.update();
344
+ this.updateNavArrows();
345
+ },
346
+
347
+ place: function() {
348
+ if (this.isInline) return;
349
+ var zIndex = parseInt(this.element.parents().filter(function() {
350
+ return $(this).css('z-index') != 'auto';
351
+ }).first().css('z-index')) + 10;
352
+ var textbox = this.component ? this.component : this.element;
353
+ var offset = textbox.offset();
354
+ var height = textbox.outerHeight() + parseInt(textbox.css('margin-top'));
355
+ var width = textbox.outerWidth() + parseInt(textbox.css('margin-left'));
356
+ var fullOffsetTop = offset.top + height;
357
+ var offsetLeft = offset.left;
358
+ // if the datepicker is going to be below the window, show it on top of the input
359
+ if ((fullOffsetTop + this.picker.outerHeight()) >= $(window).scrollTop() + $(window).height()) {
360
+ fullOffsetTop = offset.top - this.picker.outerHeight();
361
+ }
362
+
363
+ // if the datepicker is going to go past the right side of the window, we want
364
+ // to set the right position so the datepicker lines up with the textbox
365
+ if (offset.left + this.picker.width() >= $(window).width()) {
366
+ offsetLeft = (offset.left + width) - this.picker.width();
367
+ }
368
+ this.picker.css({
369
+ top: fullOffsetTop,
370
+ left: offsetLeft,
371
+ zIndex: zIndex
372
+ });
373
+ },
374
+
375
+ update: function() {
376
+ var date, fromArgs = false;
377
+ if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
378
+ date = arguments[0];
379
+ fromArgs = true;
380
+ } else {
381
+ date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
382
+ }
383
+
384
+ this.date = DPGlobal.parseDate(date, this.format, this.language);
385
+
386
+ if (fromArgs) this.setValue();
387
+
388
+ if (this.date < this.startDate) {
389
+ this.viewDate = new Date(this.startDate.valueOf());
390
+ } else if (this.date > this.endDate) {
391
+ this.viewDate = new Date(this.endDate.valueOf());
392
+ } else {
393
+ this.viewDate = new Date(this.date.valueOf());
394
+ }
395
+ this.fill();
396
+ },
397
+
398
+ fillDow: function() {
399
+ var dowCnt = this.weekStart,
400
+ html = '<tr>';
401
+ if (this.calendarWeeks) {
402
+ var cell = '<th class="cw">&nbsp;</th>';
403
+ html += cell;
404
+ this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
405
+ }
406
+ while (dowCnt < this.weekStart + 7) {
407
+ html += '<th class="dow">' + dates[this.language].daysMin[(dowCnt++) % 7] + '</th>';
408
+ }
409
+ html += '</tr>';
410
+ this.picker.find('.datepicker-days thead').append(html);
411
+ },
412
+
413
+ fillMonths: function() {
414
+ var html = '',
415
+ i = 0;
416
+ while (i < 12) {
417
+ html += '<span class="month">' + dates[this.language].monthsShort[i++] + '</span>';
418
+ }
419
+ this.picker.find('.datepicker-months td').html(html);
420
+ },
421
+
422
+ fill: function() {
423
+ if (this.date == null || this.viewDate == null) {
424
+ return;
425
+ }
426
+
427
+ var d = new Date(this.viewDate.valueOf()),
428
+ year = d.getUTCFullYear(),
429
+ month = d.getUTCMonth(),
430
+ dayMonth = d.getUTCDate(),
431
+ hours = d.getUTCHours(),
432
+ minutes = d.getUTCMinutes(),
433
+ startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
434
+ startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
435
+ endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
436
+ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
437
+ currentDate = this.date && this.date.valueOf(),
438
+ today = new Date(),
439
+ titleFormat = dates[this.language].titleFormat || dates['en'].titleFormat;
440
+ // this.picker.find('.datepicker-days thead th.date-switch')
441
+ // .text(DPGlobal.formatDate(new UTCDate(year, month), titleFormat, this.language));
442
+
443
+ this.picker.find('.datepicker-days thead th:eq(1)')
444
+ .text(dates[this.language].months[month] + ' ' + year);
445
+ this.picker.find('.datepicker-hours thead th:eq(1)')
446
+ .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
447
+ this.picker.find('.datepicker-minutes thead th:eq(1)')
448
+ .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
449
+
450
+
451
+ this.picker.find('tfoot th.today')
452
+ .text(dates[this.language].today)
453
+ .toggle(this.todayBtn !== false);
454
+ this.updateNavArrows();
455
+ this.fillMonths();
456
+ var prevMonth = UTCDate(year, month - 1, 28, 0, 0, 0, 0),
457
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
458
+ prevMonth.setUTCDate(day);
459
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7) % 7);
460
+ var nextMonth = new Date(prevMonth.valueOf());
461
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
462
+ nextMonth = nextMonth.valueOf();
463
+ var html = [];
464
+ var clsName;
465
+ while (prevMonth.valueOf() < nextMonth) {
466
+ if (prevMonth.getUTCDay() == this.weekStart) {
467
+ html.push('<tr>');
468
+ if (this.calendarWeeks) {
469
+ // adapted from https://github.com/timrwood/moment/blob/master/moment.js#L128
470
+ var a = new Date(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth(), prevMonth.getUTCDate() - prevMonth.getDay() + 10 - (this.weekStart && this.weekStart % 7 < 5 && 7)),
471
+ b = new Date(a.getFullYear(), 0, 4),
472
+ calWeek = ~~((a - b) / 864e5 / 7 + 1.5);
473
+ html.push('<td class="cw">' + calWeek + '</td>');
474
+ }
475
+ }
476
+ clsName = ' ' + this.onRender(prevMonth) + ' ';
477
+ if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
478
+ clsName += ' old';
479
+ } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
480
+ clsName += ' new';
481
+ }
482
+ // Compare internal UTC date with local today, not UTC today
483
+ if (this.todayHighlight &&
484
+ prevMonth.getUTCFullYear() == today.getFullYear() &&
485
+ prevMonth.getUTCMonth() == today.getMonth() &&
486
+ prevMonth.getUTCDate() == today.getDate()) {
487
+ clsName += ' today';
488
+ }
489
+ if (currentDate && prevMonth.valueOf() == currentDate) {
490
+ clsName += ' active';
491
+ }
492
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
493
+ $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
494
+ clsName += ' disabled';
495
+ }
496
+ html.push('<td class="day' + clsName + '">' + prevMonth.getUTCDate() + '</td>');
497
+ if (prevMonth.getUTCDay() == this.weekEnd) {
498
+ html.push('</tr>');
499
+ }
500
+ prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
501
+ }
502
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
503
+
504
+ html = [];
505
+ for (var i = 0; i < 24; i++) {
506
+ var actual = UTCDate(year, month, dayMonth, i);
507
+ clsName = '';
508
+ // We want the previous hour for the startDate
509
+ if ((actual.valueOf() + 3600000) < this.startDate || actual.valueOf() > this.endDate) {
510
+ clsName += ' disabled';
511
+ } else if (hours == i) {
512
+ clsName += ' active';
513
+ }
514
+ html.push('<span class="hour' + clsName + '">' + i + ':00</span>');
515
+ }
516
+ this.picker.find('.datepicker-hours td').html(html.join(''));
517
+
518
+ html = [];
519
+ for (var i = 0; i < 60; i += this.minuteStep) {
520
+ var actual = UTCDate(year, month, dayMonth, hours, i);
521
+ clsName = '';
522
+ if (actual.valueOf() < this.startDate || actual.valueOf() > this.endDate) {
523
+ clsName += ' disabled';
524
+ } else if (Math.floor(minutes / this.minuteStep) == Math.floor(i / this.minuteStep)) {
525
+ clsName += ' active';
526
+ }
527
+ html.push('<span class="minute' + clsName + '">' + hours + ':' + (i < 10 ? '0' + i : i) + '</span>');
528
+ }
529
+ this.picker.find('.datepicker-minutes td').html(html.join(''));
530
+
531
+
532
+ var currentYear = this.date && this.date.getUTCFullYear();
533
+ var months = this.picker.find('.datepicker-months')
534
+ .find('th:eq(1)')
535
+ .text(year)
536
+ .end()
537
+ .find('span').removeClass('active');
538
+ if (currentYear && currentYear == year) {
539
+ months.eq(this.date.getUTCMonth()).addClass('active');
540
+ }
541
+ if (year < startYear || year > endYear) {
542
+ months.addClass('disabled');
543
+ }
544
+ if (year == startYear) {
545
+ months.slice(0, startMonth).addClass('disabled');
546
+ }
547
+ if (year == endYear) {
548
+ months.slice(endMonth + 1).addClass('disabled');
549
+ }
550
+
551
+ html = '';
552
+ year = parseInt(year / 10, 10) * 10;
553
+ var yearCont = this.picker.find('.datepicker-years')
554
+ .find('th:eq(1)')
555
+ .text(year + '-' + (year + 9))
556
+ .end()
557
+ .find('td');
558
+ year -= 1;
559
+ for (var i = -1; i < 11; i++) {
560
+ html += '<span class="year' + (i == -1 || i == 10 ? ' old' : '') + (currentYear == year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : '') + '">' + year + '</span>';
561
+ year += 1;
562
+ }
563
+ yearCont.html(html);
564
+ },
565
+
566
+ updateNavArrows: function() {
567
+ var d = new Date(this.viewDate),
568
+ year = d.getUTCFullYear(),
569
+ month = d.getUTCMonth(),
570
+ day = d.getUTCDate(),
571
+ hour = d.getUTCHours();
572
+ switch (this.viewMode) {
573
+ case 0:
574
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate() && hour <= this.startDate.getUTCHours()) {
575
+ this.picker.find('.prev').css({
576
+ visibility: 'hidden'
577
+ });
578
+ } else {
579
+ this.picker.find('.prev').css({
580
+ visibility: 'visible'
581
+ });
582
+ }
583
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate() && hour >= this.endDate.getUTCHours()) {
584
+ this.picker.find('.next').css({
585
+ visibility: 'hidden'
586
+ });
587
+ } else {
588
+ this.picker.find('.next').css({
589
+ visibility: 'visible'
590
+ });
591
+ }
592
+ break;
593
+ case 1:
594
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate()) {
595
+ this.picker.find('.prev').css({
596
+ visibility: 'hidden'
597
+ });
598
+ } else {
599
+ this.picker.find('.prev').css({
600
+ visibility: 'visible'
601
+ });
602
+ }
603
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate()) {
604
+ this.picker.find('.next').css({
605
+ visibility: 'hidden'
606
+ });
607
+ } else {
608
+ this.picker.find('.next').css({
609
+ visibility: 'visible'
610
+ });
611
+ }
612
+ break;
613
+ case 2:
614
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
615
+ this.picker.find('.prev').css({
616
+ visibility: 'hidden'
617
+ });
618
+ } else {
619
+ this.picker.find('.prev').css({
620
+ visibility: 'visible'
621
+ });
622
+ }
623
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
624
+ this.picker.find('.next').css({
625
+ visibility: 'hidden'
626
+ });
627
+ } else {
628
+ this.picker.find('.next').css({
629
+ visibility: 'visible'
630
+ });
631
+ }
632
+ break;
633
+ case 3:
634
+ case 4:
635
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
636
+ this.picker.find('.prev').css({
637
+ visibility: 'hidden'
638
+ });
639
+ } else {
640
+ this.picker.find('.prev').css({
641
+ visibility: 'visible'
642
+ });
643
+ }
644
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
645
+ this.picker.find('.next').css({
646
+ visibility: 'hidden'
647
+ });
648
+ } else {
649
+ this.picker.find('.next').css({
650
+ visibility: 'visible'
651
+ });
652
+ }
653
+ break;
654
+ }
655
+ },
656
+
657
+ click: function(e) {
658
+ e.stopPropagation();
659
+ e.preventDefault();
660
+
661
+ if ($(e.target).hasClass('datepicker-close') || $(e.target).parent().hasClass('datepicker-close')) {
662
+ this.hide();
663
+ }
664
+
665
+ var target = $(e.target).closest('span, td, th');
666
+ if (target.length == 1) {
667
+ if (target.is('.disabled')) {
668
+ this.element.trigger({
669
+ type: 'outOfRange',
670
+ date: this.viewDate,
671
+ startDate: this.startDate,
672
+ endDate: this.endDate
673
+ });
674
+ return;
675
+ }
676
+
677
+ switch (target[0].nodeName.toLowerCase()) {
678
+ case 'th':
679
+ switch (target[0].className) {
680
+ case 'date-switch':
681
+ this.showMode(1);
682
+ break;
683
+ case 'prev':
684
+ case 'next':
685
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
686
+ switch (this.viewMode) {
687
+ case 0:
688
+ this.viewDate = this.moveHour(this.viewDate, dir);
689
+ break;
690
+ case 1:
691
+ this.viewDate = this.moveDate(this.viewDate, dir);
692
+ break;
693
+ case 2:
694
+ this.viewDate = this.moveMonth(this.viewDate, dir);
695
+ break;
696
+ case 3:
697
+ case 4:
698
+ this.viewDate = this.moveYear(this.viewDate, dir);
699
+ break;
700
+ }
701
+ this.fill();
702
+ break;
703
+ case 'today':
704
+ var date = new Date();
705
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
706
+
707
+ this.viewMode = this.startViewMode;
708
+ this.showMode(0);
709
+ this._setDate(date);
710
+ break;
711
+ }
712
+ break;
713
+ case 'span':
714
+ if (!target.is('.disabled')) {
715
+ if (target.is('.month')) {
716
+ this.viewDate.setUTCDate(1);
717
+ var month = target.parent().find('span').index(target);
718
+ this.viewDate.setUTCMonth(month);
719
+ this.element.trigger({
720
+ type: 'changeMonth',
721
+ date: this.viewDate
722
+ });
723
+ } else if (target.is('.year')) {
724
+ this.viewDate.setUTCDate(1);
725
+ var year = parseInt(target.text(), 10) || 0;
726
+ this.viewDate.setUTCFullYear(year);
727
+ this.element.trigger({
728
+ type: 'changeYear',
729
+ date: this.viewDate
730
+ });
731
+ } else if (target.is('.hour')) {
732
+ var hours = parseInt(target.text(), 10) || 0;
733
+ var year = this.viewDate.getUTCFullYear(),
734
+ month = this.viewDate.getUTCMonth(),
735
+ day = this.viewDate.getUTCDate(),
736
+ minutes = this.viewDate.getUTCMinutes(),
737
+ seconds = this.viewDate.getUTCSeconds();
738
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
739
+ } else if (target.is('.minute')) {
740
+ var minutes = parseInt(target.text().substr(target.text().indexOf(':') + 1), 10) || 0;
741
+ var year = this.viewDate.getUTCFullYear(),
742
+ month = this.viewDate.getUTCMonth(),
743
+ day = this.viewDate.getUTCDate(),
744
+ hours = this.viewDate.getUTCHours(),
745
+ seconds = this.viewDate.getUTCSeconds();
746
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
747
+ }
748
+
749
+
750
+
751
+ if (this.viewMode != 0) {
752
+
753
+
754
+
755
+ var oldViewMode = this.viewMode;
756
+ this.showMode(-1);
757
+ this.fill();
758
+ if (oldViewMode == this.viewMode && this.autoclose) {
759
+ this.hide();
760
+ }
761
+ } else {
762
+ this.fill();
763
+ if (this.autoclose) {
764
+ this.hide();
765
+ }
766
+ }
767
+ }
768
+ break;
769
+ case 'td':
770
+
771
+
772
+
773
+ if (target.is('.day') && !target.is('.disabled')) {
774
+ var day = parseInt(target.text(), 10) || 1;
775
+ var year = this.viewDate.getUTCFullYear(),
776
+ month = this.viewDate.getUTCMonth(),
777
+ hours = this.viewDate.getUTCHours(),
778
+ minutes = this.viewDate.getUTCMinutes(),
779
+ seconds = this.viewDate.getUTCSeconds();
780
+ if (target.is('.old')) {
781
+ if (month === 0) {
782
+ month = 11;
783
+ year -= 1;
784
+ } else {
785
+ month -= 1;
786
+ }
787
+ } else if (target.is('.new')) {
788
+ if (month == 11) {
789
+ month = 0;
790
+ year += 1;
791
+ } else {
792
+ month += 1;
793
+ }
794
+ }
795
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
796
+ }
797
+
798
+
799
+
800
+ var oldViewMode = this.viewMode;
801
+
802
+
803
+ this.showMode(-1);
804
+
805
+
806
+ this.fill();
807
+ if (oldViewMode == this.viewMode && this.autoclose) {
808
+ this.hide();
809
+ }
810
+ break;
811
+ }
812
+ }
813
+ },
814
+
815
+ _setDate: function(date, which) {
816
+
817
+ if (!which || which == 'date')
818
+ this.date = date;
819
+ if (!which || which == 'view')
820
+ this.viewDate = date;
821
+ this.fill();
822
+ this.setValue();
823
+ this.element.trigger({
824
+ type: 'changeDate',
825
+ date: this.date
826
+ });
827
+ var element;
828
+ if (this.isInput) {
829
+ element = this.element;
830
+ } else if (this.component) {
831
+ element = this.element.find('input');
832
+ }
833
+ if (element) {
834
+ element.change();
835
+ if (this.autoclose && (!which || which == 'date')) {
836
+ // this.hide();
837
+ }
838
+ }
839
+ },
840
+
841
+ moveHour: function(date, dir) {
842
+ if (!dir) return date;
843
+ var new_date = new Date(date.valueOf());
844
+ dir = dir > 0 ? 1 : -1;
845
+ new_date.setUTCHours(new_date.getUTCHours() + dir);
846
+ return new_date;
847
+ },
848
+
849
+ moveDate: function(date, dir) {
850
+ if (!dir) return date;
851
+ var new_date = new Date(date.valueOf());
852
+ dir = dir > 0 ? 1 : -1;
853
+ new_date.setUTCDate(new_date.getUTCDate() + dir);
854
+ return new_date;
855
+ },
856
+
857
+ moveMonth: function(date, dir) {
858
+ if (!dir) return date;
859
+ var new_date = new Date(date.valueOf()),
860
+ day = new_date.getUTCDate(),
861
+ month = new_date.getUTCMonth(),
862
+ mag = Math.abs(dir),
863
+ new_month, test;
864
+ dir = dir > 0 ? 1 : -1;
865
+ if (mag == 1) {
866
+ test = dir == -1
867
+ // If going back one month, make sure month is not current month
868
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
869
+ ? function() {
870
+ return new_date.getUTCMonth() == month;
871
+ }
872
+ // If going forward one month, make sure month is as expected
873
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
874
+ : function() {
875
+ return new_date.getUTCMonth() != new_month;
876
+ };
877
+ new_month = month + dir;
878
+ new_date.setUTCMonth(new_month);
879
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
880
+ if (new_month < 0 || new_month > 11)
881
+ new_month = (new_month + 12) % 12;
882
+ } else {
883
+ // For magnitudes >1, move one month at a time...
884
+ for (var i = 0; i < mag; i++)
885
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
886
+ new_date = this.moveMonth(new_date, dir);
887
+ // ...then reset the day, keeping it in the new month
888
+ new_month = new_date.getUTCMonth();
889
+ new_date.setUTCDate(day);
890
+ test = function() {
891
+ return new_month != new_date.getUTCMonth();
892
+ };
893
+ }
894
+ // Common date-resetting loop -- if date is beyond end of month, make it
895
+ // end of month
896
+ while (test()) {
897
+ new_date.setUTCDate(--day);
898
+ new_date.setUTCMonth(new_month);
899
+ }
900
+ return new_date;
901
+ },
902
+
903
+ moveYear: function(date, dir) {
904
+ return this.moveMonth(date, dir * 12);
905
+ },
906
+
907
+ dateWithinRange: function(date) {
908
+ return date >= this.startDate && date <= this.endDate;
909
+ },
910
+
911
+ keydown: function(e) {
912
+ if (this.picker.is(':not(:visible)')) {
913
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
914
+ this.show();
915
+ return;
916
+ }
917
+ var dateChanged = false,
918
+ dir, day, month,
919
+ newDate, newViewDate;
920
+ switch (e.keyCode) {
921
+ case 27: // escape
922
+ this.hide();
923
+ e.preventDefault();
924
+ break;
925
+ case 37: // left
926
+ case 39: // right
927
+ if (!this.keyboardNavigation) break;
928
+ dir = e.keyCode == 37 ? -1 : 1;
929
+ if (e.ctrlKey) {
930
+ newDate = this.moveYear(this.date, dir);
931
+ newViewDate = this.moveYear(this.viewDate, dir);
932
+ } else if (e.shiftKey) {
933
+ newDate = this.moveMonth(this.date, dir);
934
+ newViewDate = this.moveMonth(this.viewDate, dir);
935
+ } else {
936
+ newDate = new Date(this.date.valueOf());
937
+ newDate.setUTCDate(this.date.getUTCDate() + dir);
938
+ newViewDate = new Date(this.viewDate.valueOf());
939
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
940
+ }
941
+ if (this.dateWithinRange(newDate)) {
942
+ this.date = newDate;
943
+ this.viewDate = newViewDate;
944
+ this.setValue();
945
+ this.update();
946
+ e.preventDefault();
947
+ dateChanged = true;
948
+ }
949
+ break;
950
+ case 38: // up
951
+ case 40: // down
952
+ if (!this.keyboardNavigation) break;
953
+ dir = e.keyCode == 38 ? -1 : 1;
954
+ if (e.ctrlKey) {
955
+ newDate = this.moveYear(this.date, dir);
956
+ newViewDate = this.moveYear(this.viewDate, dir);
957
+ } else if (e.shiftKey) {
958
+ newDate = this.moveMonth(this.date, dir);
959
+ newViewDate = this.moveMonth(this.viewDate, dir);
960
+ } else {
961
+ newDate = new Date(this.date.valueOf());
962
+ newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
963
+ newViewDate = new Date(this.viewDate.valueOf());
964
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
965
+ }
966
+ if (this.dateWithinRange(newDate)) {
967
+ this.date = newDate;
968
+ this.viewDate = newViewDate;
969
+ this.setValue();
970
+ this.update();
971
+ e.preventDefault();
972
+ dateChanged = true;
973
+ }
974
+ break;
975
+ case 13: // enter
976
+ this.hide();
977
+ e.preventDefault();
978
+ break;
979
+ case 9: // tab
980
+ this.hide();
981
+ break;
982
+ }
983
+ if (dateChanged) {
984
+ this.element.trigger({
985
+ type: 'changeDate',
986
+ date: this.date
987
+ });
988
+ var element;
989
+ if (this.isInput) {
990
+ element = this.element;
991
+ } else if (this.component) {
992
+ element = this.element.find('input');
993
+ }
994
+ if (element) {
995
+ element.change();
996
+ }
997
+ }
998
+ },
999
+
1000
+ showMode: function(dir) {
1001
+
1002
+ if (dir) {
1003
+ var newViewMode = Math.max(0, Math.min(DPGlobal.modes.length - 1, this.viewMode + dir));
1004
+ if (newViewMode >= this.minView && newViewMode <= this.maxView) {
1005
+ this.viewMode = newViewMode;
1006
+ }
1007
+ }
1008
+ /*
1009
+ vitalets: fixing bug of very special conditions:
1010
+ jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
1011
+ Method show() does not set display css correctly and datepicker is not shown.
1012
+ Changed to .css('display', 'block') solve the problem.
1013
+ See https://github.com/vitalets/x-editable/issues/37
1014
+
1015
+ In jquery 1.7.2+ everything works fine.
1016
+ */
1017
+ //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
1018
+ this.picker.find('>div').hide().filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
1019
+ this.updateNavArrows();
1020
+ },
1021
+ reset: function(e) {
1022
+ this._setDate(null, 'date');
1023
+ }
1024
+ };
1025
+
1026
+ $.fn.fdatepicker = function(option) {
1027
+ var args = Array.apply(null, arguments);
1028
+ args.shift();
1029
+ return this.each(function() {
1030
+ var $this = $(this),
1031
+ data = $this.data('datepicker'),
1032
+ options = typeof option == 'object' && option;
1033
+ if (!data) {
1034
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.fdatepicker.defaults, options))));
1035
+ }
1036
+ if (typeof option == 'string' && typeof data[option] == 'function') {
1037
+ data[option].apply(data, args);
1038
+ }
1039
+ });
1040
+ };
1041
+
1042
+ $.fn.fdatepicker.defaults = {
1043
+ onRender: function(date) {
1044
+ return '';
1045
+ }
1046
+ };
1047
+ $.fn.fdatepicker.Constructor = Datepicker;
1048
+ var dates = $.fn.fdatepicker.dates = {
1049
+ 'en': {
1050
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
1051
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1052
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
1053
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1054
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
1055
+ today: "Today",
1056
+ titleFormat: "MM yyyy"
1057
+ }
1058
+ };
1059
+
1060
+ var DPGlobal = {
1061
+ modes: [{
1062
+ clsName: 'minutes',
1063
+ navFnc: 'Hours',
1064
+ navStep: 1
1065
+ }, {
1066
+ clsName: 'hours',
1067
+ navFnc: 'Date',
1068
+ navStep: 1
1069
+ }, {
1070
+ clsName: 'days',
1071
+ navFnc: 'Month',
1072
+ navStep: 1
1073
+ }, {
1074
+ clsName: 'months',
1075
+ navFnc: 'FullYear',
1076
+ navStep: 1
1077
+ }, {
1078
+ clsName: 'years',
1079
+ navFnc: 'FullYear',
1080
+ navStep: 10
1081
+ }],
1082
+ isLeapYear: function(year) {
1083
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1084
+ },
1085
+ getDaysInMonth: function(year, month) {
1086
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1087
+ },
1088
+ validParts: /hh?|ii?|ss?|dd?|mm?|MM?|yy(?:yy)?/g,
1089
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1090
+ parseFormat: function(format) {
1091
+ // IE treats \0 as a string end in inputs (truncating the value),
1092
+ // so it's a bad format delimiter, anyway
1093
+ var separators = format.replace(this.validParts, '\0').split('\0'),
1094
+ parts = format.match(this.validParts);
1095
+ if (!separators || !separators.length || !parts || parts.length === 0) {
1096
+ throw new Error("Invalid date format.");
1097
+ }
1098
+ return {
1099
+ separators: separators,
1100
+ parts: parts
1101
+ };
1102
+ },
1103
+ parseDate: function(date, format, language) {
1104
+ if (date instanceof Date) return new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
1105
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(date)) {
1106
+ format = this.parseFormat('yyyy-mm-dd');
1107
+ }
1108
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}$/.test(date)) {
1109
+ format = this.parseFormat('yyyy-mm-dd hh:ii');
1110
+ }
1111
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}\:\d{1,2}[Z]{0,1}$/.test(date)) {
1112
+ format = this.parseFormat('yyyy-mm-dd hh:ii:ss');
1113
+ }
1114
+ if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
1115
+ var part_re = /([-+]\d+)([dmwy])/,
1116
+ parts = date.match(/([-+]\d+)([dmwy])/g),
1117
+ part, dir;
1118
+ date = new Date();
1119
+ for (var i = 0; i < parts.length; i++) {
1120
+ part = part_re.exec(parts[i]);
1121
+ dir = parseInt(part[1]);
1122
+ switch (part[2]) {
1123
+ case 'd':
1124
+ date.setUTCDate(date.getUTCDate() + dir);
1125
+ break;
1126
+ case 'm':
1127
+ date = Datetimepicker.prototype.moveMonth.call(Datetimepicker.prototype, date, dir);
1128
+ break;
1129
+ case 'w':
1130
+ date.setUTCDate(date.getUTCDate() + dir * 7);
1131
+ break;
1132
+ case 'y':
1133
+ date = Datetimepicker.prototype.moveYear.call(Datetimepicker.prototype, date, dir);
1134
+ break;
1135
+ }
1136
+ }
1137
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
1138
+ }
1139
+ var parts = date && date.match(this.nonpunctuation) || [],
1140
+ date = new Date(),
1141
+ parsed = {},
1142
+ setters_order = ['hh', 'h', 'ii', 'i', 'ss', 's', 'yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1143
+ setters_map = {
1144
+ hh: function(d, v) {
1145
+ return d.setUTCHours(v);
1146
+ },
1147
+ h: function(d, v) {
1148
+ return d.setUTCHours(v);
1149
+ },
1150
+ ii: function(d, v) {
1151
+ return d.setUTCMinutes(v);
1152
+ },
1153
+ i: function(d, v) {
1154
+ return d.setUTCMinutes(v);
1155
+ },
1156
+ ss: function(d, v) {
1157
+ return d.setUTCSeconds(v);
1158
+ },
1159
+ s: function(d, v) {
1160
+ return d.setUTCSeconds(v);
1161
+ },
1162
+ yyyy: function(d, v) {
1163
+ return d.setUTCFullYear(v);
1164
+ },
1165
+ yy: function(d, v) {
1166
+ return d.setUTCFullYear(2000 + v);
1167
+ },
1168
+ m: function(d, v) {
1169
+ v -= 1;
1170
+ while (v < 0) v += 12;
1171
+ v %= 12;
1172
+ d.setUTCMonth(v);
1173
+ while (d.getUTCMonth() != v)
1174
+ d.setUTCDate(d.getUTCDate() - 1);
1175
+ return d;
1176
+ },
1177
+ d: function(d, v) {
1178
+ return d.setUTCDate(v);
1179
+ }
1180
+ },
1181
+ val, filtered, part;
1182
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1183
+ setters_map['dd'] = setters_map['d'];
1184
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); //date.getHours(), date.getMinutes(), date.getSeconds());
1185
+ if (parts.length == format.parts.length) {
1186
+ for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
1187
+ val = parseInt(parts[i], 10);
1188
+ part = format.parts[i];
1189
+ if (isNaN(val)) {
1190
+ switch (part) {
1191
+ case 'MM':
1192
+ filtered = $(dates[language].months).filter(function() {
1193
+ var m = this.slice(0, parts[i].length),
1194
+ p = parts[i].slice(0, m.length);
1195
+ return m == p;
1196
+ });
1197
+ val = $.inArray(filtered[0], dates[language].months) + 1;
1198
+ break;
1199
+ case 'M':
1200
+ filtered = $(dates[language].monthsShort).filter(function() {
1201
+ var m = this.slice(0, parts[i].length),
1202
+ p = parts[i].slice(0, m.length);
1203
+ return m == p;
1204
+ });
1205
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1206
+ break;
1207
+ }
1208
+ }
1209
+ parsed[part] = val;
1210
+ }
1211
+ for (var i = 0, s; i < setters_order.length; i++) {
1212
+ s = setters_order[i];
1213
+ if (s in parsed && !isNaN(parsed[s]))
1214
+ setters_map[s](date, parsed[s])
1215
+ }
1216
+ }
1217
+ return date;
1218
+ },
1219
+ formatDate: function(date, format, language) {
1220
+ if (date == null) {
1221
+ return '';
1222
+ }
1223
+ var val = {
1224
+ h: date.getUTCHours(),
1225
+ i: date.getUTCMinutes(),
1226
+ s: date.getUTCSeconds(),
1227
+ d: date.getUTCDate(),
1228
+ m: date.getUTCMonth() + 1,
1229
+ M: dates[language].monthsShort[date.getUTCMonth()],
1230
+ MM: dates[language].months[date.getUTCMonth()],
1231
+ yy: date.getUTCFullYear().toString().substring(2),
1232
+ yyyy: date.getUTCFullYear()
1233
+ };
1234
+ val.hh = (val.h < 10 ? '0' : '') + val.h;
1235
+ val.ii = (val.i < 10 ? '0' : '') + val.i;
1236
+ val.ss = (val.s < 10 ? '0' : '') + val.s;
1237
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1238
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1239
+ var date = [],
1240
+ seps = $.extend([], format.separators);
1241
+ for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
1242
+ if (seps.length)
1243
+ date.push(seps.shift())
1244
+ date.push(val[format.parts[i]]);
1245
+ }
1246
+ return date.join('');
1247
+ },
1248
+ convertViewMode: function(viewMode) {
1249
+ switch (viewMode) {
1250
+ case 4:
1251
+ case 'decade':
1252
+ viewMode = 4;
1253
+ break;
1254
+ case 3:
1255
+ case 'year':
1256
+ viewMode = 3;
1257
+ break;
1258
+ case 2:
1259
+ case 'month':
1260
+ viewMode = 2;
1261
+ break;
1262
+ case 1:
1263
+ case 'day':
1264
+ viewMode = 1;
1265
+ break;
1266
+ case 0:
1267
+ case 'hour':
1268
+ viewMode = 0;
1269
+ break;
1270
+ }
1271
+
1272
+ return viewMode;
1273
+ },
1274
+ headTemplate: '<thead>' +
1275
+ '<tr>' +
1276
+ '<th class="prev"><i class="fa fa-chevron-left fi-arrow-left"/></th>' +
1277
+ '<th colspan="5" class="date-switch"></th>' +
1278
+ '<th class="next"><i class="fa fa-chevron-right fi-arrow-right"/></th>' +
1279
+ '</tr>' +
1280
+ '</thead>',
1281
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1282
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1283
+ };
1284
+ DPGlobal.template = '<div class="datepicker">' +
1285
+ '<div class="datepicker-minutes">' +
1286
+ '<table class=" table-condensed">' +
1287
+ DPGlobal.headTemplate +
1288
+ DPGlobal.contTemplate +
1289
+ DPGlobal.footTemplate +
1290
+ '</table>' +
1291
+ '</div>' +
1292
+ '<div class="datepicker-hours">' +
1293
+ '<table class=" table-condensed">' +
1294
+ DPGlobal.headTemplate +
1295
+ DPGlobal.contTemplate +
1296
+ DPGlobal.footTemplate +
1297
+ '</table>' +
1298
+ '</div>' +
1299
+ '<div class="datepicker-days">' +
1300
+ '<table class=" table-condensed">' +
1301
+ DPGlobal.headTemplate +
1302
+ '<tbody></tbody>' +
1303
+ DPGlobal.footTemplate +
1304
+ '</table>' +
1305
+ '</div>' +
1306
+ '<div class="datepicker-months">' +
1307
+ '<table class="table-condensed">' +
1308
+ DPGlobal.headTemplate +
1309
+ DPGlobal.contTemplate +
1310
+ DPGlobal.footTemplate +
1311
+ '</table>' +
1312
+ '</div>' +
1313
+ '<div class="datepicker-years">' +
1314
+ '<table class="table-condensed">' +
1315
+ DPGlobal.headTemplate +
1316
+ DPGlobal.contTemplate +
1317
+ DPGlobal.footTemplate +
1318
+ '</table>' +
1319
+ '</div>' +
1320
+ '<a class="button datepicker-close tiny alert right" style="width:auto;"><i class="fa fa-remove fa-times fi-x"></i></a>' +
1321
+ '</div>';
1322
+
1323
+ $.fn.fdatepicker.DPGlobal = DPGlobal;
1324
+
1325
+ }(window.jQuery);