input_calendar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +70 -0
- data/Rakefile +17 -0
- data/example.png +0 -0
- data/input_calendar.gemspec +20 -0
- data/lib/input_calendar.rb +12 -0
- data/lib/input_calendar/tasks/copy_files.rake +25 -0
- data/lib/input_calendar/version.rb +3 -0
- data/src/calendar.coffee +154 -0
- data/vendor/assets/javascripts/input_calendar.js +228 -0
- data/vendor/assets/stylesheets/input_calendar.css +54 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Josh Goebel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# input_calendar
|
2
|
+
|
3
|
+
At the current time __input_calendar__ is optimized for static calendars that stay in place and are used in place (how I usually prefer a calendar in apps). No reason it couldn't be enhanced to hide/show dynamically and support visible date fields.
|
4
|
+
|
5
|
+
Interesting in patches to make it more configurable as long as it stays simple and elegant.
|
6
|
+
|
7
|
+
## How to use
|
8
|
+
|
9
|
+
In your view:
|
10
|
+
|
11
|
+
<% form_for @event do |f| %>
|
12
|
+
<%= f.hidden_field :date, :class => "calendar" %>
|
13
|
+
<%= javascript_tag "Calendar.attach('event_date')" %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
Or avoid the inline JS with some jQuery (coffeescript) somewhere:
|
17
|
+
|
18
|
+
$(document).ready ->
|
19
|
+
$("input.calendar").each (i, o) ->
|
20
|
+
Calendar.attach(o)
|
21
|
+
|
22
|
+
## Options you can pass attach
|
23
|
+
|
24
|
+
TODO: Write up options here
|
25
|
+
|
26
|
+
## Installing
|
27
|
+
|
28
|
+
### Requirements
|
29
|
+
|
30
|
+
Requires jQuery and underscore.js.
|
31
|
+
|
32
|
+
* http://jquery.com/
|
33
|
+
* http://documentcloud.github.com/underscore/
|
34
|
+
|
35
|
+
|
36
|
+
### Rails 3.1
|
37
|
+
|
38
|
+
You'll need to add input_calendar to your Gemfile and then the asset pipeline will see that the appropriate JS and CSS files are included in your app.
|
39
|
+
|
40
|
+
Add to your Gemfile:
|
41
|
+
|
42
|
+
gem "input_calendar"
|
43
|
+
|
44
|
+
And install:
|
45
|
+
|
46
|
+
bundle install
|
47
|
+
|
48
|
+
|
49
|
+
### Rails 3.0 (using Bundler)
|
50
|
+
|
51
|
+
A rake task is included to copy the JS and CSS files into your public folder.
|
52
|
+
|
53
|
+
Add to your Gemfile:
|
54
|
+
|
55
|
+
gem "input_calendar"
|
56
|
+
|
57
|
+
Then copy the files locally:
|
58
|
+
|
59
|
+
bundle install
|
60
|
+
bundle exec rake input_calendar:copy_files
|
61
|
+
|
62
|
+
Should give you:
|
63
|
+
|
64
|
+
create public/javascripts/input_calendar.js
|
65
|
+
create public/stylesheets/input_calendar.css
|
66
|
+
|
67
|
+
|
68
|
+
### Rails 2.x
|
69
|
+
|
70
|
+
TODO: Add directions here.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
task :default => [:compile]
|
6
|
+
|
7
|
+
task :compile do
|
8
|
+
`coffee -c -o vendor/assets/javascripts src/*.coffee`
|
9
|
+
FileUtils.mv("vendor/assets/javascripts/calendar.js",
|
10
|
+
"vendor/assets/javascripts/input_calendar.js")
|
11
|
+
end
|
12
|
+
|
13
|
+
task :build => :compile
|
14
|
+
|
15
|
+
task :watch do
|
16
|
+
exec "zsh -c 'coffee -c -w -o vendor/assets/javascripts src/*.coffee '"
|
17
|
+
end
|
data/example.png
ADDED
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "input_calendar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "input_calendar"
|
7
|
+
s.version = InputCalendar::VERSION
|
8
|
+
s.authors = ["Josh Goebel"]
|
9
|
+
s.email = ["me@joshgoebel.com"]
|
10
|
+
s.homepage = "http://github.com/yyyc514/input_calendar"
|
11
|
+
s.summary = %q{Simple and clean JS calendar to enter dates on forms}
|
12
|
+
s.description = %q{Simple and clean JS calendar to enter dates on forms}
|
13
|
+
|
14
|
+
s.rubyforge_project = "input_calendar"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'thor/group'
|
2
|
+
|
3
|
+
class CopyFiles < Thor::Group
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.join(File.dirname(__FILE__),"../../..")
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_files
|
11
|
+
assets="vendor/assets"
|
12
|
+
copy_file "#{assets}/javascripts/input_calendar.js", "public/javascripts/input_calendar.js"
|
13
|
+
copy_file "#{assets}/stylesheets/input_calendar.css", "public/stylesheets/input_calendar.css"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :input_calendar do
|
19
|
+
|
20
|
+
desc "Copy the input_calendar files into public/javascripts, etc..."
|
21
|
+
task :copy_files do
|
22
|
+
CopyFiles.start
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/src/calendar.coffee
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
$ = jQuery
|
2
|
+
|
3
|
+
class @Calendar
|
4
|
+
# only syntax takes both the id and field
|
5
|
+
constructor: (@id, @field, @options = {}) ->
|
6
|
+
@field=$("##{@field}")
|
7
|
+
if @id?
|
8
|
+
@element=$("##{@id}")
|
9
|
+
else
|
10
|
+
@element=$("<div>").insertAfter(@field)
|
11
|
+
@show()
|
12
|
+
@getDateFromField()
|
13
|
+
@pager_date = new Date(@date)
|
14
|
+
@redraw()
|
15
|
+
# new syntax, just attach to a form field and let us do the rest
|
16
|
+
@attach: (field, options) ->
|
17
|
+
new Calendar(null, field, options)
|
18
|
+
|
19
|
+
getDateFromField: () ->
|
20
|
+
@date = new Date
|
21
|
+
return if @field.val() == ""
|
22
|
+
[year, month, day] = @parseIncomingDate()
|
23
|
+
@date = new Date(year, month-1, day)
|
24
|
+
|
25
|
+
# should override this in a subclass if you're date string looks different
|
26
|
+
parseIncomingDate: () ->
|
27
|
+
# cut off the time element
|
28
|
+
date=@field.val().split(" ")[0]
|
29
|
+
date.split("-").map (x) -> parseInt(x)
|
30
|
+
|
31
|
+
show: () -> @element.show()
|
32
|
+
hide: () -> @element.hide()
|
33
|
+
label: () ->
|
34
|
+
@MONTHS[@pager_date.getMonth()].label + " " +
|
35
|
+
@pager_date.getFullYear();
|
36
|
+
|
37
|
+
MONTHS: [
|
38
|
+
{ label : 'January', days : 31 }
|
39
|
+
{ label : 'February', days : 28 }
|
40
|
+
{ label : 'March', days : 31 }
|
41
|
+
{ label : 'April', days : 30 }
|
42
|
+
{ label : 'May', days : 31 }
|
43
|
+
{ label : 'June', days : 30 }
|
44
|
+
{ label : 'July', days : 31 }
|
45
|
+
{ label : 'August', days : 31 }
|
46
|
+
{ label : 'September', days : 30 }
|
47
|
+
{ label : 'October', days : 31 }
|
48
|
+
{ label : 'November', days : 30 }
|
49
|
+
{ label : 'December', days : 31 }]
|
50
|
+
|
51
|
+
DAYS: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
52
|
+
|
53
|
+
dayRows: () ->
|
54
|
+
("<th>#{day[0..0]}</th>" for day in @DAYS).join ""
|
55
|
+
|
56
|
+
forward: () ->
|
57
|
+
dh(@pager_date).forward_a_month()
|
58
|
+
@redraw()
|
59
|
+
false
|
60
|
+
|
61
|
+
back: () ->
|
62
|
+
dh(@pager_date).back_a_month()
|
63
|
+
@redraw()
|
64
|
+
false
|
65
|
+
|
66
|
+
days_in_month : (date) ->
|
67
|
+
[ month, year ] = [date.getMonth(), date.getFullYear()]
|
68
|
+
length = @MONTHS[month].days
|
69
|
+
`(month == 1 && (year % 4 == 0) && (year % 100 != 0)) ? 29 : length;`
|
70
|
+
|
71
|
+
buildDateCells: () ->
|
72
|
+
date = dh(new Date(@pager_date))
|
73
|
+
date.setDate(1)
|
74
|
+
month = @pager_date.getMonth()
|
75
|
+
first_day = date.getDay()
|
76
|
+
for i in [1..first_day]
|
77
|
+
date.go_yesterday()
|
78
|
+
html = ""
|
79
|
+
i = 0
|
80
|
+
while i < @days_in_month(date) + first_day - 1
|
81
|
+
html += "<tr>"
|
82
|
+
for day in @DAYS
|
83
|
+
html += @buildDayCell(date, month)
|
84
|
+
date.go_tomorrow()
|
85
|
+
i+=1
|
86
|
+
html += "</tr>"
|
87
|
+
html
|
88
|
+
|
89
|
+
buildDayCell: (date, month) ->
|
90
|
+
classes = []
|
91
|
+
classes.push("day")
|
92
|
+
classes.push("othermonth") if date.getMonth() != month
|
93
|
+
classes.push("today") if date.same_as(new Date())
|
94
|
+
classes.push("selected") if date.same_as(@date)
|
95
|
+
"<td class='#{classes.join(" ")}'><a data-date='#{date.toLocaleString()}' href='#'>#{date.getDate()}</a></td>"
|
96
|
+
|
97
|
+
clicked: (event) ->
|
98
|
+
o=$(event.target)
|
99
|
+
o=o.children("A") if o[0].tagName=="TD"
|
100
|
+
# @date=new Date(@pager_date)
|
101
|
+
# @date.setDate(parseInt(o.html()))
|
102
|
+
@date=new Date(Date.parse(o.data("date")))
|
103
|
+
@field.val(@date.toLocaleDateString())
|
104
|
+
@element.find(".selected").removeClass "selected"
|
105
|
+
o.parent().addClass("selected")
|
106
|
+
@element.find(".selectedtext").html @currentDateString()
|
107
|
+
if @options.onchange
|
108
|
+
@options.onchange(@field.val())
|
109
|
+
false
|
110
|
+
|
111
|
+
currentDateString: ->
|
112
|
+
"<b>#{@DAYS[@date.getDay()]}</b><br />#{@MONTHS[@date.getMonth()].label} #{@date.getDate()}, #{@date.getFullYear()}"
|
113
|
+
|
114
|
+
redraw: () ->
|
115
|
+
html = """<table class="minicalendar" cellspacing="0">
|
116
|
+
<thead>
|
117
|
+
<tr><th class="back"><a href="#">←</a></th>
|
118
|
+
<th colspan="5" class="month_label">#{@label()}</th>
|
119
|
+
<th class="forward"><a href="#">→</a></th></tr>
|
120
|
+
<tr class="day_header">#{@dayRows()}</tr>
|
121
|
+
</thead>
|
122
|
+
<tbody>#{@buildDateCells()}</tbody>
|
123
|
+
<tfoot>
|
124
|
+
<tr><td colspan="7" class="selectedtext">#{@currentDateString()}</td></tr>
|
125
|
+
</tfoot>
|
126
|
+
</table>"""
|
127
|
+
@element.html html
|
128
|
+
@element.find("th.back").click => @back()
|
129
|
+
@element.find("th.forward").click => @forward()
|
130
|
+
@element.find("tbody").click (event) => @clicked(event)
|
131
|
+
|
132
|
+
dh = (date) ->
|
133
|
+
_.extend(date, DateHelper)
|
134
|
+
date
|
135
|
+
|
136
|
+
class DateHelper
|
137
|
+
@forward_a_month: (count = 1) ->
|
138
|
+
month=@getMonth()+count
|
139
|
+
d = new Date(@getFullYear(), month, 1)
|
140
|
+
@setTime(d)
|
141
|
+
@back_a_month: (count = 1) ->
|
142
|
+
month=@getMonth()-count
|
143
|
+
d = new Date(@getFullYear(), month, 1)
|
144
|
+
@setTime(d)
|
145
|
+
@same_as: (date) ->
|
146
|
+
@getFullYear() == date.getFullYear() &&
|
147
|
+
@getMonth() == date.getMonth() &&
|
148
|
+
@getDate() == date.getDate()
|
149
|
+
@go_tomorrow = ->
|
150
|
+
@setTime new Date(@valueOf()+1000*60*60*24)
|
151
|
+
@go_yesterday = ->
|
152
|
+
@setTime new Date(@valueOf()-1000*60*60*24)
|
153
|
+
|
154
|
+
`this.Cal = Calendar`
|
@@ -0,0 +1,228 @@
|
|
1
|
+
(function() {
|
2
|
+
var $, DateHelper, dh;
|
3
|
+
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
4
|
+
$ = jQuery;
|
5
|
+
this.Calendar = (function() {
|
6
|
+
function Calendar(id, field, options) {
|
7
|
+
this.id = id;
|
8
|
+
this.field = field;
|
9
|
+
this.options = options != null ? options : {};
|
10
|
+
this.field = $("#" + this.field);
|
11
|
+
if (this.id != null) {
|
12
|
+
this.element = $("#" + this.id);
|
13
|
+
} else {
|
14
|
+
this.element = $("<div>").insertAfter(this.field);
|
15
|
+
}
|
16
|
+
this.show();
|
17
|
+
this.getDateFromField();
|
18
|
+
this.pager_date = new Date(this.date);
|
19
|
+
this.redraw();
|
20
|
+
}
|
21
|
+
Calendar.attach = function(field, options) {
|
22
|
+
return new Calendar(null, field, options);
|
23
|
+
};
|
24
|
+
Calendar.prototype.getDateFromField = function() {
|
25
|
+
var day, month, year, _ref;
|
26
|
+
this.date = new Date;
|
27
|
+
if (this.field.val() === "") {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
_ref = this.parseIncomingDate(), year = _ref[0], month = _ref[1], day = _ref[2];
|
31
|
+
return this.date = new Date(year, month - 1, day);
|
32
|
+
};
|
33
|
+
Calendar.prototype.parseIncomingDate = function() {
|
34
|
+
var date;
|
35
|
+
date = this.field.val().split(" ")[0];
|
36
|
+
return date.split("-").map(function(x) {
|
37
|
+
return parseInt(x);
|
38
|
+
});
|
39
|
+
};
|
40
|
+
Calendar.prototype.show = function() {
|
41
|
+
return this.element.show();
|
42
|
+
};
|
43
|
+
Calendar.prototype.hide = function() {
|
44
|
+
return this.element.hide();
|
45
|
+
};
|
46
|
+
Calendar.prototype.label = function() {
|
47
|
+
return this.MONTHS[this.pager_date.getMonth()].label + " " + this.pager_date.getFullYear();
|
48
|
+
};
|
49
|
+
Calendar.prototype.MONTHS = [
|
50
|
+
{
|
51
|
+
label: 'January',
|
52
|
+
days: 31
|
53
|
+
}, {
|
54
|
+
label: 'February',
|
55
|
+
days: 28
|
56
|
+
}, {
|
57
|
+
label: 'March',
|
58
|
+
days: 31
|
59
|
+
}, {
|
60
|
+
label: 'April',
|
61
|
+
days: 30
|
62
|
+
}, {
|
63
|
+
label: 'May',
|
64
|
+
days: 31
|
65
|
+
}, {
|
66
|
+
label: 'June',
|
67
|
+
days: 30
|
68
|
+
}, {
|
69
|
+
label: 'July',
|
70
|
+
days: 31
|
71
|
+
}, {
|
72
|
+
label: 'August',
|
73
|
+
days: 31
|
74
|
+
}, {
|
75
|
+
label: 'September',
|
76
|
+
days: 30
|
77
|
+
}, {
|
78
|
+
label: 'October',
|
79
|
+
days: 31
|
80
|
+
}, {
|
81
|
+
label: 'November',
|
82
|
+
days: 30
|
83
|
+
}, {
|
84
|
+
label: 'December',
|
85
|
+
days: 31
|
86
|
+
}
|
87
|
+
];
|
88
|
+
Calendar.prototype.DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
89
|
+
Calendar.prototype.dayRows = function() {
|
90
|
+
var day;
|
91
|
+
return ((function() {
|
92
|
+
var _i, _len, _ref, _results;
|
93
|
+
_ref = this.DAYS;
|
94
|
+
_results = [];
|
95
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
96
|
+
day = _ref[_i];
|
97
|
+
_results.push("<th>" + day.slice(0, 1) + "</th>");
|
98
|
+
}
|
99
|
+
return _results;
|
100
|
+
}).call(this)).join("");
|
101
|
+
};
|
102
|
+
Calendar.prototype.forward = function() {
|
103
|
+
dh(this.pager_date).forward_a_month();
|
104
|
+
this.redraw();
|
105
|
+
return false;
|
106
|
+
};
|
107
|
+
Calendar.prototype.back = function() {
|
108
|
+
dh(this.pager_date).back_a_month();
|
109
|
+
this.redraw();
|
110
|
+
return false;
|
111
|
+
};
|
112
|
+
Calendar.prototype.days_in_month = function(date) {
|
113
|
+
var length, month, year, _ref;
|
114
|
+
_ref = [date.getMonth(), date.getFullYear()], month = _ref[0], year = _ref[1];
|
115
|
+
length = this.MONTHS[month].days;
|
116
|
+
return (month == 1 && (year % 4 == 0) && (year % 100 != 0)) ? 29 : length;;
|
117
|
+
};
|
118
|
+
Calendar.prototype.buildDateCells = function() {
|
119
|
+
var date, day, first_day, html, i, month, _i, _len, _ref;
|
120
|
+
date = dh(new Date(this.pager_date));
|
121
|
+
date.setDate(1);
|
122
|
+
month = this.pager_date.getMonth();
|
123
|
+
first_day = date.getDay();
|
124
|
+
for (i = 1; 1 <= first_day ? i <= first_day : i >= first_day; 1 <= first_day ? i++ : i--) {
|
125
|
+
date.go_yesterday();
|
126
|
+
}
|
127
|
+
html = "";
|
128
|
+
i = 0;
|
129
|
+
while (i < this.days_in_month(date) + first_day - 1) {
|
130
|
+
html += "<tr>";
|
131
|
+
_ref = this.DAYS;
|
132
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
133
|
+
day = _ref[_i];
|
134
|
+
html += this.buildDayCell(date, month);
|
135
|
+
date.go_tomorrow();
|
136
|
+
i += 1;
|
137
|
+
}
|
138
|
+
html += "</tr>";
|
139
|
+
}
|
140
|
+
return html;
|
141
|
+
};
|
142
|
+
Calendar.prototype.buildDayCell = function(date, month) {
|
143
|
+
var classes;
|
144
|
+
classes = [];
|
145
|
+
classes.push("day");
|
146
|
+
if (date.getMonth() !== month) {
|
147
|
+
classes.push("othermonth");
|
148
|
+
}
|
149
|
+
if (date.same_as(new Date())) {
|
150
|
+
classes.push("today");
|
151
|
+
}
|
152
|
+
if (date.same_as(this.date)) {
|
153
|
+
classes.push("selected");
|
154
|
+
}
|
155
|
+
return "<td class='" + (classes.join(" ")) + "'><a data-date='" + (date.toLocaleString()) + "' href='#'>" + (date.getDate()) + "</a></td>";
|
156
|
+
};
|
157
|
+
Calendar.prototype.clicked = function(event) {
|
158
|
+
var o;
|
159
|
+
o = $(event.target);
|
160
|
+
if (o[0].tagName === "TD") {
|
161
|
+
o = o.children("A");
|
162
|
+
}
|
163
|
+
this.date = new Date(Date.parse(o.data("date")));
|
164
|
+
this.field.val(this.date.toLocaleDateString());
|
165
|
+
this.element.find(".selected").removeClass("selected");
|
166
|
+
o.parent().addClass("selected");
|
167
|
+
this.element.find(".selectedtext").html(this.currentDateString());
|
168
|
+
if (this.options.onchange) {
|
169
|
+
this.options.onchange(this.field.val());
|
170
|
+
}
|
171
|
+
return false;
|
172
|
+
};
|
173
|
+
Calendar.prototype.currentDateString = function() {
|
174
|
+
return "<b>" + this.DAYS[this.date.getDay()] + "</b><br />" + this.MONTHS[this.date.getMonth()].label + " " + (this.date.getDate()) + ", " + (this.date.getFullYear());
|
175
|
+
};
|
176
|
+
Calendar.prototype.redraw = function() {
|
177
|
+
var html;
|
178
|
+
html = "<table class=\"minicalendar\" cellspacing=\"0\">\n<thead> \n <tr><th class=\"back\"><a href=\"#\">←</a></th>\n <th colspan=\"5\" class=\"month_label\">" + (this.label()) + "</th>\n <th class=\"forward\"><a href=\"#\">→</a></th></tr>\n <tr class=\"day_header\">" + (this.dayRows()) + "</tr>\n </thead>\n <tbody>" + (this.buildDateCells()) + "</tbody>\n <tfoot>\n <tr><td colspan=\"7\" class=\"selectedtext\">" + (this.currentDateString()) + "</td></tr>\n </tfoot>\n </table>";
|
179
|
+
this.element.html(html);
|
180
|
+
this.element.find("th.back").click(__bind(function() {
|
181
|
+
return this.back();
|
182
|
+
}, this));
|
183
|
+
this.element.find("th.forward").click(__bind(function() {
|
184
|
+
return this.forward();
|
185
|
+
}, this));
|
186
|
+
return this.element.find("tbody").click(__bind(function(event) {
|
187
|
+
return this.clicked(event);
|
188
|
+
}, this));
|
189
|
+
};
|
190
|
+
return Calendar;
|
191
|
+
})();
|
192
|
+
dh = function(date) {
|
193
|
+
_.extend(date, DateHelper);
|
194
|
+
return date;
|
195
|
+
};
|
196
|
+
DateHelper = (function() {
|
197
|
+
function DateHelper() {}
|
198
|
+
DateHelper.forward_a_month = function(count) {
|
199
|
+
var d, month;
|
200
|
+
if (count == null) {
|
201
|
+
count = 1;
|
202
|
+
}
|
203
|
+
month = this.getMonth() + count;
|
204
|
+
d = new Date(this.getFullYear(), month, 1);
|
205
|
+
return this.setTime(d);
|
206
|
+
};
|
207
|
+
DateHelper.back_a_month = function(count) {
|
208
|
+
var d, month;
|
209
|
+
if (count == null) {
|
210
|
+
count = 1;
|
211
|
+
}
|
212
|
+
month = this.getMonth() - count;
|
213
|
+
d = new Date(this.getFullYear(), month, 1);
|
214
|
+
return this.setTime(d);
|
215
|
+
};
|
216
|
+
DateHelper.same_as = function(date) {
|
217
|
+
return this.getFullYear() === date.getFullYear() && this.getMonth() === date.getMonth() && this.getDate() === date.getDate();
|
218
|
+
};
|
219
|
+
DateHelper.go_tomorrow = function() {
|
220
|
+
return this.setTime(new Date(this.valueOf() + 1000 * 60 * 60 * 24));
|
221
|
+
};
|
222
|
+
DateHelper.go_yesterday = function() {
|
223
|
+
return this.setTime(new Date(this.valueOf() - 1000 * 60 * 60 * 24));
|
224
|
+
};
|
225
|
+
return DateHelper;
|
226
|
+
})();
|
227
|
+
this.Cal = Calendar;
|
228
|
+
}).call(this);
|
@@ -0,0 +1,54 @@
|
|
1
|
+
table.minicalendar
|
2
|
+
{
|
3
|
+
border-collapse:collapse;
|
4
|
+
border:2px solid #aaa;
|
5
|
+
}
|
6
|
+
|
7
|
+
table.minicalendar tr td
|
8
|
+
{
|
9
|
+
padding:3px;
|
10
|
+
background:white;
|
11
|
+
}
|
12
|
+
|
13
|
+
table.minicalendar tr th
|
14
|
+
{
|
15
|
+
text-align:center;
|
16
|
+
}
|
17
|
+
|
18
|
+
table.minicalendar tr td.today
|
19
|
+
{
|
20
|
+
background:#CDD9EB;
|
21
|
+
}
|
22
|
+
|
23
|
+
table.minicalendar tr td.othermonth
|
24
|
+
{
|
25
|
+
background:#eee;
|
26
|
+
}
|
27
|
+
|
28
|
+
table.minicalendar tr td.othermonth a { color:#999;}
|
29
|
+
|
30
|
+
table.minicalendar td.day
|
31
|
+
{
|
32
|
+
text-align:center;
|
33
|
+
font-size:0.8em;
|
34
|
+
cursor:pointer;
|
35
|
+
}
|
36
|
+
|
37
|
+
table.minicalendar td.selected
|
38
|
+
{
|
39
|
+
background:#000 !important;
|
40
|
+
}
|
41
|
+
|
42
|
+
table.minicalendar td.day a { text-decoration:none; }
|
43
|
+
table.minicalendar td.selected a { color:white; color:gold; }
|
44
|
+
|
45
|
+
table.minicalendar tfoot tr td
|
46
|
+
{
|
47
|
+
text-align:center;
|
48
|
+
font-size:0.8em;
|
49
|
+
padding:5px 0;
|
50
|
+
}
|
51
|
+
table.minicalendar tfoot tr td b
|
52
|
+
{
|
53
|
+
color:#111;
|
54
|
+
}
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: input_calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Goebel
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-07 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simple and clean JS calendar to enter dates on forms
|
23
|
+
email:
|
24
|
+
- me@joshgoebel.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- example.png
|
38
|
+
- input_calendar.gemspec
|
39
|
+
- lib/input_calendar.rb
|
40
|
+
- lib/input_calendar/tasks/copy_files.rake
|
41
|
+
- lib/input_calendar/version.rb
|
42
|
+
- src/calendar.coffee
|
43
|
+
- vendor/assets/javascripts/input_calendar.js
|
44
|
+
- vendor/assets/stylesheets/input_calendar.css
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/yyyc514/input_calendar
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: input_calendar
|
75
|
+
rubygems_version: 1.6.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Simple and clean JS calendar to enter dates on forms
|
79
|
+
test_files: []
|
80
|
+
|