jqtools-rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/jqtools-rails.gemspec +81 -0
- data/lib/jqtools-rails.rb +5 -0
- data/spec/jqtools-rails_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/assets/javascripts/dateinput/dateinput.js +791 -0
- data/vendor/assets/javascripts/jquery.tools.min.js +39 -0
- data/vendor/assets/javascripts/overlay/overlay.apple.js +155 -0
- data/vendor/assets/javascripts/overlay/overlay.js +293 -0
- data/vendor/assets/javascripts/rangeinput/rangeinput.js +471 -0
- data/vendor/assets/javascripts/scrollable/scrollable.autoscroll.js +96 -0
- data/vendor/assets/javascripts/scrollable/scrollable.js +368 -0
- data/vendor/assets/javascripts/scrollable/scrollable.navigator.js +134 -0
- data/vendor/assets/javascripts/tabs/tabs.js +319 -0
- data/vendor/assets/javascripts/tabs/tabs.slideshow.js +191 -0
- data/vendor/assets/javascripts/toolbox/toolbox.expose.js +224 -0
- data/vendor/assets/javascripts/toolbox/toolbox.flashembed.js +301 -0
- data/vendor/assets/javascripts/toolbox/toolbox.history.js +108 -0
- data/vendor/assets/javascripts/toolbox/toolbox.mousewheel.js +65 -0
- data/vendor/assets/javascripts/tooltip/tooltip.dynamic.js +154 -0
- data/vendor/assets/javascripts/tooltip/tooltip.js +358 -0
- data/vendor/assets/javascripts/tooltip/tooltip.slide.js +78 -0
- data/vendor/assets/javascripts/validator/validator.js +598 -0
- metadata +135 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
# Add dependencies to develop your gem here.
|
4
|
+
# Include everything needed to run rake, tests, features, etc.
|
5
|
+
group :development do
|
6
|
+
gem "rspec", "~> 2.8.0"
|
7
|
+
gem "rdoc", "~> 3.12"
|
8
|
+
gem "bundler", ">= 1.0.0"
|
9
|
+
gem "jeweler", ">= 1.8.3"
|
10
|
+
gem "simplecov",">= 0.5"
|
11
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.6.5)
|
12
|
+
multi_json (1.1.0)
|
13
|
+
rake (0.9.2.2)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.8.0)
|
17
|
+
rspec-core (~> 2.8.0)
|
18
|
+
rspec-expectations (~> 2.8.0)
|
19
|
+
rspec-mocks (~> 2.8.0)
|
20
|
+
rspec-core (2.8.0)
|
21
|
+
rspec-expectations (2.8.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.8.0)
|
24
|
+
simplecov (0.6.1)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
simplecov-html (~> 0.5.3)
|
27
|
+
simplecov-html (0.5.3)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (>= 1.0.0)
|
34
|
+
jeweler (>= 1.8.3)
|
35
|
+
rdoc (~> 3.12)
|
36
|
+
rspec (~> 2.8.0)
|
37
|
+
simplecov (>= 0.5)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= jqtools-rails
|
2
|
+
|
3
|
+
This gem is a Rails engine and is configured to integrate with Rails asset pipeline.
|
4
|
+
|
5
|
+
Simply add to Gemfile and bundle:
|
6
|
+
|
7
|
+
gem 'jqtools-rails'
|
8
|
+
|
9
|
+
You can choose to use either the minified js for all the tools:
|
10
|
+
|
11
|
+
//= require_tree .
|
12
|
+
//= require jquery.tools.min
|
13
|
+
|
14
|
+
Or the tools individually
|
15
|
+
|
16
|
+
//= require_tree .
|
17
|
+
//= require rangeinput/rangeinput.js
|
18
|
+
//= require dateinput/dateinput.js
|
19
|
+
|
20
|
+
== Contributing to jqtools-rails
|
21
|
+
|
22
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
23
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
24
|
+
* Fork the project.
|
25
|
+
* Start a feature/bugfix branch.
|
26
|
+
* Commit and push until you are happy with your contribution.
|
27
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
28
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
29
|
+
|
30
|
+
== Copyright
|
31
|
+
|
32
|
+
Copyright (c) 2012 Kristian Mandrup. See LICENSE.txt for
|
33
|
+
further details.
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "jqtools-rails"
|
18
|
+
gem.homepage = "http://github.com/kristianmandrup/jqtools-rails"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{jQuery tools wrapped as a Rails 3 gem}
|
21
|
+
gem.description = %Q{Gem is an engine and is configured to integrate with Rails asset pipeline}
|
22
|
+
gem.email = "kmandrup@gmail.com"
|
23
|
+
gem.authors = ["Kristian Mandrup"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "jqtools-rails #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "jqtools-rails"
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = "2012-03-21"
|
13
|
+
s.description = "Gem is an engine and is configured to integrate with Rails asset pipeline"
|
14
|
+
s.email = "kmandrup@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"jqtools-rails.gemspec",
|
29
|
+
"lib/jqtools-rails.rb",
|
30
|
+
"spec/jqtools-rails_spec.rb",
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"vendor/assets/javascripts/dateinput/dateinput.js",
|
33
|
+
"vendor/assets/javascripts/jquery.tools.min.js",
|
34
|
+
"vendor/assets/javascripts/overlay/overlay.apple.js",
|
35
|
+
"vendor/assets/javascripts/overlay/overlay.js",
|
36
|
+
"vendor/assets/javascripts/rangeinput/rangeinput.js",
|
37
|
+
"vendor/assets/javascripts/scrollable/scrollable.autoscroll.js",
|
38
|
+
"vendor/assets/javascripts/scrollable/scrollable.js",
|
39
|
+
"vendor/assets/javascripts/scrollable/scrollable.navigator.js",
|
40
|
+
"vendor/assets/javascripts/tabs/tabs.js",
|
41
|
+
"vendor/assets/javascripts/tabs/tabs.slideshow.js",
|
42
|
+
"vendor/assets/javascripts/toolbox/toolbox.expose.js",
|
43
|
+
"vendor/assets/javascripts/toolbox/toolbox.flashembed.js",
|
44
|
+
"vendor/assets/javascripts/toolbox/toolbox.history.js",
|
45
|
+
"vendor/assets/javascripts/toolbox/toolbox.mousewheel.js",
|
46
|
+
"vendor/assets/javascripts/tooltip/tooltip.dynamic.js",
|
47
|
+
"vendor/assets/javascripts/tooltip/tooltip.js",
|
48
|
+
"vendor/assets/javascripts/tooltip/tooltip.slide.js",
|
49
|
+
"vendor/assets/javascripts/validator/validator.js"
|
50
|
+
]
|
51
|
+
s.homepage = "http://github.com/kristianmandrup/jqtools-rails"
|
52
|
+
s.licenses = ["MIT"]
|
53
|
+
s.require_paths = ["lib"]
|
54
|
+
s.rubygems_version = "1.8.10"
|
55
|
+
s.summary = "jQuery tools wrapped as a Rails 3 gem"
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
s.specification_version = 3
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
64
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
|
65
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.5"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
69
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
71
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
75
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'jqtools-rails'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,791 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* jQuery Tools @VERSION Dateinput - <input type="date" /> for humans
|
4
|
+
*
|
5
|
+
* NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
|
6
|
+
*
|
7
|
+
* http://flowplayer.org/tools/form/dateinput/
|
8
|
+
*
|
9
|
+
* Since: Mar 2010
|
10
|
+
* Date: @DATE
|
11
|
+
*/
|
12
|
+
(function($, undefined) {
|
13
|
+
|
14
|
+
/* TODO:
|
15
|
+
preserve today highlighted
|
16
|
+
*/
|
17
|
+
|
18
|
+
$.tools = $.tools || {version: '@VERSION'};
|
19
|
+
|
20
|
+
var instances = [],
|
21
|
+
tool,
|
22
|
+
|
23
|
+
// h=72, j=74, k=75, l=76, down=40, left=37, up=38, right=39
|
24
|
+
KEYS = [75, 76, 38, 39, 74, 72, 40, 37],
|
25
|
+
LABELS = {};
|
26
|
+
|
27
|
+
tool = $.tools.dateinput = {
|
28
|
+
|
29
|
+
conf: {
|
30
|
+
format: 'mm/dd/yy',
|
31
|
+
selectors: false,
|
32
|
+
yearRange: [-5, 5],
|
33
|
+
lang: 'en',
|
34
|
+
offset: [0, 0],
|
35
|
+
speed: 0,
|
36
|
+
firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
|
37
|
+
min: undefined,
|
38
|
+
max: undefined,
|
39
|
+
trigger: 0,
|
40
|
+
toggle: 0,
|
41
|
+
editable: 0,
|
42
|
+
|
43
|
+
css: {
|
44
|
+
|
45
|
+
prefix: 'cal',
|
46
|
+
input: 'date',
|
47
|
+
|
48
|
+
// ids
|
49
|
+
root: 0,
|
50
|
+
head: 0,
|
51
|
+
title: 0,
|
52
|
+
prev: 0,
|
53
|
+
next: 0,
|
54
|
+
month: 0,
|
55
|
+
year: 0,
|
56
|
+
days: 0,
|
57
|
+
|
58
|
+
body: 0,
|
59
|
+
weeks: 0,
|
60
|
+
today: 0,
|
61
|
+
current: 0,
|
62
|
+
|
63
|
+
// classnames
|
64
|
+
week: 0,
|
65
|
+
off: 0,
|
66
|
+
sunday: 0,
|
67
|
+
focus: 0,
|
68
|
+
disabled: 0,
|
69
|
+
trigger: 0
|
70
|
+
}
|
71
|
+
},
|
72
|
+
|
73
|
+
localize: function(language, labels) {
|
74
|
+
$.each(labels, function(key, val) {
|
75
|
+
labels[key] = val.split(",");
|
76
|
+
});
|
77
|
+
LABELS[language] = labels;
|
78
|
+
}
|
79
|
+
|
80
|
+
};
|
81
|
+
|
82
|
+
tool.localize("en", {
|
83
|
+
months: 'January,February,March,April,May,June,July,August,September,October,November,December',
|
84
|
+
shortMonths: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
|
85
|
+
days: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday',
|
86
|
+
shortDays: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'
|
87
|
+
});
|
88
|
+
|
89
|
+
|
90
|
+
//{{{ private functions
|
91
|
+
|
92
|
+
|
93
|
+
// @return amount of days in certain month
|
94
|
+
function dayAm(year, month) {
|
95
|
+
return new Date(year, month + 1, 0).getDate();
|
96
|
+
}
|
97
|
+
|
98
|
+
function zeropad(val, len) {
|
99
|
+
val = '' + val;
|
100
|
+
len = len || 2;
|
101
|
+
while (val.length < len) { val = "0" + val; }
|
102
|
+
return val;
|
103
|
+
}
|
104
|
+
|
105
|
+
// thanks: http://stevenlevithan.com/assets/misc/date.format.js
|
106
|
+
var Re = /d{1,4}|m{1,4}|yy(?:yy)?|"[^"]*"|'[^']*'/g, tmpTag = $("<a/>");
|
107
|
+
|
108
|
+
function format(date, fmt, lang) {
|
109
|
+
|
110
|
+
var d = date.getDate(),
|
111
|
+
D = date.getDay(),
|
112
|
+
m = date.getMonth(),
|
113
|
+
y = date.getFullYear(),
|
114
|
+
|
115
|
+
flags = {
|
116
|
+
d: d,
|
117
|
+
dd: zeropad(d),
|
118
|
+
ddd: LABELS[lang].shortDays[D],
|
119
|
+
dddd: LABELS[lang].days[D],
|
120
|
+
m: m + 1,
|
121
|
+
mm: zeropad(m + 1),
|
122
|
+
mmm: LABELS[lang].shortMonths[m],
|
123
|
+
mmmm: LABELS[lang].months[m],
|
124
|
+
yy: String(y).slice(2),
|
125
|
+
yyyy: y
|
126
|
+
};
|
127
|
+
|
128
|
+
var ret = fmt.replace(Re, function ($0) {
|
129
|
+
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
|
130
|
+
});
|
131
|
+
|
132
|
+
// a small trick to handle special characters
|
133
|
+
return tmpTag.html(ret).html();
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
function integer(val) {
|
138
|
+
return parseInt(val, 10);
|
139
|
+
}
|
140
|
+
|
141
|
+
function isSameDay(d1, d2) {
|
142
|
+
return d1.getFullYear() === d2.getFullYear() &&
|
143
|
+
d1.getMonth() == d2.getMonth() &&
|
144
|
+
d1.getDate() == d2.getDate();
|
145
|
+
}
|
146
|
+
|
147
|
+
function parseDate(val) {
|
148
|
+
|
149
|
+
if (val === undefined) { return; }
|
150
|
+
if (val.constructor == Date) { return val; }
|
151
|
+
|
152
|
+
if (typeof val == 'string') {
|
153
|
+
|
154
|
+
// rfc3339?
|
155
|
+
var els = val.split("-");
|
156
|
+
if (els.length == 3) {
|
157
|
+
return new Date(integer(els[0]), integer(els[1]) -1, integer(els[2]));
|
158
|
+
}
|
159
|
+
|
160
|
+
// invalid offset
|
161
|
+
if ( !(/^-?\d+$/).test(val) ) { return; }
|
162
|
+
|
163
|
+
// convert to integer
|
164
|
+
val = integer(val);
|
165
|
+
}
|
166
|
+
|
167
|
+
var date = new Date;
|
168
|
+
date.setDate(date.getDate() + val);
|
169
|
+
return date;
|
170
|
+
}
|
171
|
+
|
172
|
+
//}}}
|
173
|
+
|
174
|
+
|
175
|
+
function Dateinput(input, conf) {
|
176
|
+
|
177
|
+
// variables
|
178
|
+
var self = this,
|
179
|
+
now = new Date,
|
180
|
+
yearNow = now.getFullYear(),
|
181
|
+
css = conf.css,
|
182
|
+
labels = LABELS[conf.lang],
|
183
|
+
root = $("#" + css.root),
|
184
|
+
title = root.find("#" + css.title),
|
185
|
+
trigger,
|
186
|
+
pm, nm,
|
187
|
+
currYear, currMonth, currDay,
|
188
|
+
value = input.attr("data-value") || conf.value || input.val(),
|
189
|
+
min = input.attr("min") || conf.min,
|
190
|
+
max = input.attr("max") || conf.max,
|
191
|
+
opened,
|
192
|
+
original;
|
193
|
+
|
194
|
+
// zero min is not undefined
|
195
|
+
if (min === 0) { min = "0"; }
|
196
|
+
|
197
|
+
// use sane values for value, min & max
|
198
|
+
value = parseDate(value) || now;
|
199
|
+
|
200
|
+
min = parseDate(min || new Date(yearNow + conf.yearRange[0], 1, 1));
|
201
|
+
max = parseDate(max || new Date( yearNow + conf.yearRange[1]+ 1, 1, -1));
|
202
|
+
|
203
|
+
|
204
|
+
// check that language exists
|
205
|
+
if (!labels) { throw "Dateinput: invalid language: " + conf.lang; }
|
206
|
+
|
207
|
+
// Replace built-in date input: NOTE: input.attr("type", "text") throws exception by the browser
|
208
|
+
if (input.attr("type") == 'date') {
|
209
|
+
var original = input.clone(),
|
210
|
+
def = original.wrap("<div/>").parent().html(),
|
211
|
+
clone = $(def.replace(/type/i, "type=text data-orig-type"));
|
212
|
+
|
213
|
+
if (conf.value) clone.val(conf.value); // jquery 1.6.2 val(undefined) will clear val()
|
214
|
+
|
215
|
+
input.replaceWith(clone);
|
216
|
+
input = clone;
|
217
|
+
}
|
218
|
+
|
219
|
+
input.addClass(css.input);
|
220
|
+
|
221
|
+
var fire = input.add(self);
|
222
|
+
|
223
|
+
// construct layout
|
224
|
+
if (!root.length) {
|
225
|
+
|
226
|
+
// root
|
227
|
+
root = $('<div><div><a/><div/><a/></div><div><div/><div/></div></div>')
|
228
|
+
.hide().css({position: 'absolute'}).attr("id", css.root);
|
229
|
+
|
230
|
+
// elements
|
231
|
+
root.children()
|
232
|
+
.eq(0).attr("id", css.head).end()
|
233
|
+
.eq(1).attr("id", css.body).children()
|
234
|
+
.eq(0).attr("id", css.days).end()
|
235
|
+
.eq(1).attr("id", css.weeks).end().end().end()
|
236
|
+
.find("a").eq(0).attr("id", css.prev).end().eq(1).attr("id", css.next);
|
237
|
+
|
238
|
+
// title
|
239
|
+
title = root.find("#" + css.head).find("div").attr("id", css.title);
|
240
|
+
|
241
|
+
// year & month selectors
|
242
|
+
if (conf.selectors) {
|
243
|
+
var monthSelector = $("<select/>").attr("id", css.month),
|
244
|
+
yearSelector = $("<select/>").attr("id", css.year);
|
245
|
+
title.html(monthSelector.add(yearSelector));
|
246
|
+
}
|
247
|
+
|
248
|
+
// day titles
|
249
|
+
var days = root.find("#" + css.days);
|
250
|
+
|
251
|
+
// days of the week
|
252
|
+
for (var d = 0; d < 7; d++) {
|
253
|
+
days.append($("<span/>").text(labels.shortDays[(d + conf.firstDay) % 7]));
|
254
|
+
}
|
255
|
+
|
256
|
+
$("body").append(root);
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
// trigger icon
|
261
|
+
if (conf.trigger) {
|
262
|
+
trigger = $("<a/>").attr("href", "#").addClass(css.trigger).click(function(e) {
|
263
|
+
conf.toggle ? self.toggle() : self.show();
|
264
|
+
return e.preventDefault();
|
265
|
+
}).insertAfter(input);
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
// layout elements
|
270
|
+
var weeks = root.find("#" + css.weeks);
|
271
|
+
yearSelector = root.find("#" + css.year);
|
272
|
+
monthSelector = root.find("#" + css.month);
|
273
|
+
|
274
|
+
|
275
|
+
//{{{ pick
|
276
|
+
|
277
|
+
function select(date, conf, e) {
|
278
|
+
|
279
|
+
// current value
|
280
|
+
value = date;
|
281
|
+
currYear = date.getFullYear();
|
282
|
+
currMonth = date.getMonth();
|
283
|
+
currDay = date.getDate();
|
284
|
+
|
285
|
+
// focus the input after selection (doesn't work in IE)
|
286
|
+
if (e.type == "click" && !$.browser.msie) {
|
287
|
+
input.focus();
|
288
|
+
}
|
289
|
+
|
290
|
+
// beforChange
|
291
|
+
e = e || $.Event("api");
|
292
|
+
e.type = "beforeChange";
|
293
|
+
|
294
|
+
fire.trigger(e, [date]);
|
295
|
+
if (e.isDefaultPrevented()) { return; }
|
296
|
+
|
297
|
+
// formatting
|
298
|
+
input.val(format(date, conf.format, conf.lang));
|
299
|
+
|
300
|
+
// change
|
301
|
+
e.type = "change";
|
302
|
+
fire.trigger(e);
|
303
|
+
|
304
|
+
// store value into input
|
305
|
+
input.data("date", date);
|
306
|
+
|
307
|
+
self.hide(e);
|
308
|
+
}
|
309
|
+
//}}}
|
310
|
+
|
311
|
+
|
312
|
+
//{{{ onShow
|
313
|
+
|
314
|
+
function onShow(ev) {
|
315
|
+
|
316
|
+
ev.type = "onShow";
|
317
|
+
fire.trigger(ev);
|
318
|
+
|
319
|
+
$(document).bind("keydown.d", function(e) {
|
320
|
+
|
321
|
+
if (e.ctrlKey) { return true; }
|
322
|
+
var key = e.keyCode;
|
323
|
+
|
324
|
+
// backspace or delete clears the value
|
325
|
+
if (key == 8 || key == 46) {
|
326
|
+
input.val("");
|
327
|
+
return self.hide(e);
|
328
|
+
}
|
329
|
+
|
330
|
+
// esc or tab key exits
|
331
|
+
if (key == 27 || key == 9) { return self.hide(e); }
|
332
|
+
|
333
|
+
if ($(KEYS).index(key) >= 0) {
|
334
|
+
|
335
|
+
if (!opened) {
|
336
|
+
self.show(e);
|
337
|
+
return e.preventDefault();
|
338
|
+
}
|
339
|
+
|
340
|
+
var days = $("#" + css.weeks + " a"),
|
341
|
+
el = $("." + css.focus),
|
342
|
+
index = days.index(el);
|
343
|
+
|
344
|
+
el.removeClass(css.focus);
|
345
|
+
|
346
|
+
if (key == 74 || key == 40) { index += 7; }
|
347
|
+
else if (key == 75 || key == 38) { index -= 7; }
|
348
|
+
else if (key == 76 || key == 39) { index += 1; }
|
349
|
+
else if (key == 72 || key == 37) { index -= 1; }
|
350
|
+
|
351
|
+
|
352
|
+
if (index > 41) {
|
353
|
+
self.addMonth();
|
354
|
+
el = $("#" + css.weeks + " a:eq(" + (index-42) + ")");
|
355
|
+
} else if (index < 0) {
|
356
|
+
self.addMonth(-1);
|
357
|
+
el = $("#" + css.weeks + " a:eq(" + (index+42) + ")");
|
358
|
+
} else {
|
359
|
+
el = days.eq(index);
|
360
|
+
}
|
361
|
+
|
362
|
+
el.addClass(css.focus);
|
363
|
+
return e.preventDefault();
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
// pageUp / pageDown
|
368
|
+
if (key == 34) { return self.addMonth(); }
|
369
|
+
if (key == 33) { return self.addMonth(-1); }
|
370
|
+
|
371
|
+
// home
|
372
|
+
if (key == 36) { return self.today(); }
|
373
|
+
|
374
|
+
// enter
|
375
|
+
if (key == 13) {
|
376
|
+
if (!$(e.target).is("select")) {
|
377
|
+
$("." + css.focus).click();
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
return $([16, 17, 18, 9]).index(key) >= 0;
|
382
|
+
});
|
383
|
+
|
384
|
+
|
385
|
+
// click outside dateinput
|
386
|
+
$(document).bind("click.d", function(e) {
|
387
|
+
var el = e.target;
|
388
|
+
|
389
|
+
if (!$(el).parents("#" + css.root).length && el != input[0] && (!trigger || el != trigger[0])) {
|
390
|
+
self.hide(e);
|
391
|
+
}
|
392
|
+
|
393
|
+
});
|
394
|
+
}
|
395
|
+
//}}}
|
396
|
+
|
397
|
+
|
398
|
+
$.extend(self, {
|
399
|
+
|
400
|
+
|
401
|
+
/**
|
402
|
+
* @public
|
403
|
+
* Show the calendar
|
404
|
+
*/
|
405
|
+
show: function(e) {
|
406
|
+
|
407
|
+
if (input.attr("readonly") || input.attr("disabled") || opened) { return; }
|
408
|
+
|
409
|
+
// onBeforeShow
|
410
|
+
e = e || $.Event();
|
411
|
+
e.type = "onBeforeShow";
|
412
|
+
fire.trigger(e);
|
413
|
+
if (e.isDefaultPrevented()) { return; }
|
414
|
+
|
415
|
+
$.each(instances, function() {
|
416
|
+
this.hide();
|
417
|
+
});
|
418
|
+
|
419
|
+
opened = true;
|
420
|
+
|
421
|
+
// month selector
|
422
|
+
monthSelector.unbind("change").change(function() {
|
423
|
+
self.setValue(yearSelector.val(), $(this).val());
|
424
|
+
});
|
425
|
+
|
426
|
+
// year selector
|
427
|
+
yearSelector.unbind("change").change(function() {
|
428
|
+
self.setValue($(this).val(), monthSelector.val());
|
429
|
+
});
|
430
|
+
|
431
|
+
// prev / next month
|
432
|
+
pm = root.find("#" + css.prev).unbind("click").click(function(e) {
|
433
|
+
if (!pm.hasClass(css.disabled)) {
|
434
|
+
self.addMonth(-1);
|
435
|
+
}
|
436
|
+
return false;
|
437
|
+
});
|
438
|
+
|
439
|
+
nm = root.find("#" + css.next).unbind("click").click(function(e) {
|
440
|
+
if (!nm.hasClass(css.disabled)) {
|
441
|
+
self.addMonth();
|
442
|
+
}
|
443
|
+
return false;
|
444
|
+
});
|
445
|
+
|
446
|
+
// set date
|
447
|
+
self.setValue(value);
|
448
|
+
|
449
|
+
// show calendar
|
450
|
+
var pos = input.offset();
|
451
|
+
|
452
|
+
// iPad position fix
|
453
|
+
if (/iPad/i.test(navigator.userAgent)) {
|
454
|
+
pos.top -= $(window).scrollTop();
|
455
|
+
}
|
456
|
+
|
457
|
+
root.css({
|
458
|
+
top: pos.top + input.outerHeight({margins: true}) + conf.offset[0],
|
459
|
+
left: pos.left + conf.offset[1]
|
460
|
+
});
|
461
|
+
|
462
|
+
if (conf.speed) {
|
463
|
+
root.show(conf.speed, function() {
|
464
|
+
onShow(e);
|
465
|
+
});
|
466
|
+
} else {
|
467
|
+
root.show();
|
468
|
+
onShow(e);
|
469
|
+
}
|
470
|
+
|
471
|
+
return self;
|
472
|
+
},
|
473
|
+
|
474
|
+
/**
|
475
|
+
* @public
|
476
|
+
*
|
477
|
+
* Set the value of the dateinput
|
478
|
+
*/
|
479
|
+
setValue: function(year, month, day) {
|
480
|
+
|
481
|
+
var date = integer(month) >= -1 ? new Date(integer(year), integer(month), integer(day == undefined || isNaN(day) ? 1 : day)) :
|
482
|
+
year || value;
|
483
|
+
|
484
|
+
if (date < min) { date = min; }
|
485
|
+
else if (date > max) { date = max; }
|
486
|
+
|
487
|
+
// date given as ISO string
|
488
|
+
if (typeof year == 'string') { date = parseDate(year); }
|
489
|
+
|
490
|
+
year = date.getFullYear();
|
491
|
+
month = date.getMonth();
|
492
|
+
day = date.getDate();
|
493
|
+
|
494
|
+
|
495
|
+
// roll year & month
|
496
|
+
if (month == -1) {
|
497
|
+
month = 11;
|
498
|
+
year--;
|
499
|
+
} else if (month == 12) {
|
500
|
+
month = 0;
|
501
|
+
year++;
|
502
|
+
}
|
503
|
+
|
504
|
+
if (!opened) {
|
505
|
+
select(date, conf);
|
506
|
+
return self;
|
507
|
+
}
|
508
|
+
|
509
|
+
currMonth = month;
|
510
|
+
currYear = year;
|
511
|
+
currDay = day;
|
512
|
+
|
513
|
+
// variables
|
514
|
+
var tmp = new Date(year, month, 1 - conf.firstDay), begin = tmp.getDay(),
|
515
|
+
days = dayAm(year, month),
|
516
|
+
prevDays = dayAm(year, month - 1),
|
517
|
+
week;
|
518
|
+
|
519
|
+
// selectors
|
520
|
+
if (conf.selectors) {
|
521
|
+
|
522
|
+
// month selector
|
523
|
+
monthSelector.empty();
|
524
|
+
$.each(labels.months, function(i, m) {
|
525
|
+
if (min < new Date(year, i + 1, 1) && max > new Date(year, i, 0)) {
|
526
|
+
monthSelector.append($("<option/>").html(m).attr("value", i));
|
527
|
+
}
|
528
|
+
});
|
529
|
+
|
530
|
+
// year selector
|
531
|
+
yearSelector.empty();
|
532
|
+
var yearNow = now.getFullYear();
|
533
|
+
|
534
|
+
for (var i = yearNow + conf.yearRange[0]; i < yearNow + conf.yearRange[1]; i++) {
|
535
|
+
if (min < new Date(i + 1, 0, 1) && max > new Date(i, 0, 0)) {
|
536
|
+
yearSelector.append($("<option/>").text(i));
|
537
|
+
}
|
538
|
+
}
|
539
|
+
|
540
|
+
monthSelector.val(month);
|
541
|
+
yearSelector.val(year);
|
542
|
+
|
543
|
+
// title
|
544
|
+
} else {
|
545
|
+
title.html(labels.months[month] + " " + year);
|
546
|
+
}
|
547
|
+
|
548
|
+
// populate weeks
|
549
|
+
weeks.empty();
|
550
|
+
pm.add(nm).removeClass(css.disabled);
|
551
|
+
|
552
|
+
// !begin === "sunday"
|
553
|
+
for (var j = !begin ? -7 : 0, a, num; j < (!begin ? 35 : 42); j++) {
|
554
|
+
|
555
|
+
a = $("<a/>");
|
556
|
+
|
557
|
+
if (j % 7 === 0) {
|
558
|
+
week = $("<div/>").addClass(css.week);
|
559
|
+
weeks.append(week);
|
560
|
+
}
|
561
|
+
|
562
|
+
if (j < begin) {
|
563
|
+
a.addClass(css.off);
|
564
|
+
num = prevDays - begin + j + 1;
|
565
|
+
date = new Date(year, month-1, num);
|
566
|
+
|
567
|
+
} else if (j >= begin + days) {
|
568
|
+
a.addClass(css.off);
|
569
|
+
num = j - days - begin + 1;
|
570
|
+
date = new Date(year, month+1, num);
|
571
|
+
|
572
|
+
} else {
|
573
|
+
num = j - begin + 1;
|
574
|
+
date = new Date(year, month, num);
|
575
|
+
|
576
|
+
// current date
|
577
|
+
if (isSameDay(value, date)) {
|
578
|
+
a.attr("id", css.current).addClass(css.focus);
|
579
|
+
|
580
|
+
// today
|
581
|
+
} else if (isSameDay(now, date)) {
|
582
|
+
a.attr("id", css.today);
|
583
|
+
}
|
584
|
+
}
|
585
|
+
|
586
|
+
// disabled
|
587
|
+
if (min && date < min) {
|
588
|
+
a.add(pm).addClass(css.disabled);
|
589
|
+
}
|
590
|
+
|
591
|
+
if (max && date > max) {
|
592
|
+
a.add(nm).addClass(css.disabled);
|
593
|
+
}
|
594
|
+
|
595
|
+
a.attr("href", "#" + num).text(num).data("date", date);
|
596
|
+
|
597
|
+
week.append(a);
|
598
|
+
}
|
599
|
+
|
600
|
+
// date picking
|
601
|
+
weeks.find("a").click(function(e) {
|
602
|
+
var el = $(this);
|
603
|
+
if (!el.hasClass(css.disabled)) {
|
604
|
+
$("#" + css.current).removeAttr("id");
|
605
|
+
el.attr("id", css.current);
|
606
|
+
select(el.data("date"), conf, e);
|
607
|
+
}
|
608
|
+
return false;
|
609
|
+
});
|
610
|
+
|
611
|
+
// sunday
|
612
|
+
if (css.sunday) {
|
613
|
+
weeks.find(css.week).each(function() {
|
614
|
+
var beg = conf.firstDay ? 7 - conf.firstDay : 0;
|
615
|
+
$(this).children().slice(beg, beg + 1).addClass(css.sunday);
|
616
|
+
});
|
617
|
+
}
|
618
|
+
|
619
|
+
return self;
|
620
|
+
},
|
621
|
+
//}}}
|
622
|
+
|
623
|
+
setMin: function(val, fit) {
|
624
|
+
min = parseDate(val);
|
625
|
+
if (fit && value < min) { self.setValue(min); }
|
626
|
+
return self;
|
627
|
+
},
|
628
|
+
|
629
|
+
setMax: function(val, fit) {
|
630
|
+
max = parseDate(val);
|
631
|
+
if (fit && value > max) { self.setValue(max); }
|
632
|
+
return self;
|
633
|
+
},
|
634
|
+
|
635
|
+
today: function() {
|
636
|
+
return self.setValue(now);
|
637
|
+
},
|
638
|
+
|
639
|
+
addDay: function(amount) {
|
640
|
+
return this.setValue(currYear, currMonth, currDay + (amount || 1));
|
641
|
+
},
|
642
|
+
|
643
|
+
addMonth: function(amount) {
|
644
|
+
var targetMonth = currMonth + (amount || 1),
|
645
|
+
daysInTargetMonth = dayAm(currYear, targetMonth),
|
646
|
+
targetDay = currDay <= daysInTargetMonth ? currDay : daysInTargetMonth;
|
647
|
+
|
648
|
+
return this.setValue(currYear, targetMonth, targetDay);
|
649
|
+
},
|
650
|
+
|
651
|
+
addYear: function(amount) {
|
652
|
+
return this.setValue(currYear + (amount || 1), currMonth, currDay);
|
653
|
+
},
|
654
|
+
|
655
|
+
destroy: function() {
|
656
|
+
input.add(document).unbind("click.d").unbind("keydown.d");
|
657
|
+
root.add(trigger).remove();
|
658
|
+
input.removeData("dateinput").removeClass(css.input);
|
659
|
+
if (original) { input.replaceWith(original); }
|
660
|
+
},
|
661
|
+
|
662
|
+
hide: function(e) {
|
663
|
+
|
664
|
+
if (opened) {
|
665
|
+
|
666
|
+
// onHide
|
667
|
+
e = $.Event();
|
668
|
+
e.type = "onHide";
|
669
|
+
fire.trigger(e);
|
670
|
+
|
671
|
+
// cancelled ?
|
672
|
+
if (e.isDefaultPrevented()) { return; }
|
673
|
+
|
674
|
+
$(document).unbind("click.d").unbind("keydown.d");
|
675
|
+
|
676
|
+
// do the hide
|
677
|
+
root.hide();
|
678
|
+
opened = false;
|
679
|
+
}
|
680
|
+
|
681
|
+
return self;
|
682
|
+
},
|
683
|
+
|
684
|
+
toggle: function(){
|
685
|
+
return self.isOpen() ? self.hide() : self.show();
|
686
|
+
},
|
687
|
+
|
688
|
+
getConf: function() {
|
689
|
+
return conf;
|
690
|
+
},
|
691
|
+
|
692
|
+
getInput: function() {
|
693
|
+
return input;
|
694
|
+
},
|
695
|
+
|
696
|
+
getCalendar: function() {
|
697
|
+
return root;
|
698
|
+
},
|
699
|
+
|
700
|
+
getValue: function(dateFormat) {
|
701
|
+
return dateFormat ? format(value, dateFormat, conf.lang) : value;
|
702
|
+
},
|
703
|
+
|
704
|
+
isOpen: function() {
|
705
|
+
return opened;
|
706
|
+
}
|
707
|
+
|
708
|
+
});
|
709
|
+
|
710
|
+
// callbacks
|
711
|
+
$.each(['onBeforeShow','onShow','change','onHide'], function(i, name) {
|
712
|
+
|
713
|
+
// configuration
|
714
|
+
if ($.isFunction(conf[name])) {
|
715
|
+
$(self).bind(name, conf[name]);
|
716
|
+
}
|
717
|
+
|
718
|
+
// API methods
|
719
|
+
self[name] = function(fn) {
|
720
|
+
if (fn) { $(self).bind(name, fn); }
|
721
|
+
return self;
|
722
|
+
};
|
723
|
+
});
|
724
|
+
|
725
|
+
if (!conf.editable) {
|
726
|
+
|
727
|
+
// show dateinput & assign keyboard shortcuts
|
728
|
+
input.bind("focus.d click.d", self.show).keydown(function(e) {
|
729
|
+
|
730
|
+
var key = e.keyCode;
|
731
|
+
|
732
|
+
// open dateinput with navigation keyw
|
733
|
+
if (!opened && $(KEYS).index(key) >= 0) {
|
734
|
+
self.show(e);
|
735
|
+
return e.preventDefault();
|
736
|
+
|
737
|
+
// clear value on backspace or delete
|
738
|
+
} else if (key == 8 || key == 46) {
|
739
|
+
input.val("");
|
740
|
+
}
|
741
|
+
|
742
|
+
// allow tab
|
743
|
+
return e.shiftKey || e.ctrlKey || e.altKey || key == 9 ? true : e.preventDefault();
|
744
|
+
|
745
|
+
});
|
746
|
+
}
|
747
|
+
|
748
|
+
// initial value
|
749
|
+
if (parseDate(input.val())) {
|
750
|
+
select(value, conf);
|
751
|
+
}
|
752
|
+
|
753
|
+
}
|
754
|
+
|
755
|
+
$.expr[':'].date = function(el) {
|
756
|
+
var type = el.getAttribute("type");
|
757
|
+
return type && type == 'date' || !!$(el).data("dateinput");
|
758
|
+
};
|
759
|
+
|
760
|
+
|
761
|
+
$.fn.dateinput = function(conf) {
|
762
|
+
|
763
|
+
// already instantiated
|
764
|
+
if (this.data("dateinput")) { return this; }
|
765
|
+
|
766
|
+
// configuration
|
767
|
+
conf = $.extend(true, {}, tool.conf, conf);
|
768
|
+
|
769
|
+
// CSS prefix
|
770
|
+
$.each(conf.css, function(key, val) {
|
771
|
+
if (!val && key != 'prefix') {
|
772
|
+
conf.css[key] = (conf.css.prefix || '') + (val || key);
|
773
|
+
}
|
774
|
+
});
|
775
|
+
|
776
|
+
var els;
|
777
|
+
|
778
|
+
this.each(function() {
|
779
|
+
var el = new Dateinput($(this), conf);
|
780
|
+
instances.push(el);
|
781
|
+
var input = el.getInput().data("dateinput", el);
|
782
|
+
els = els ? els.add(input) : input;
|
783
|
+
});
|
784
|
+
|
785
|
+
return els ? els : this;
|
786
|
+
};
|
787
|
+
|
788
|
+
|
789
|
+
}) (jQuery);
|
790
|
+
|
791
|
+
|