input_calendar 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module InputCalendar
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
data/src/calendar.coffee CHANGED
@@ -99,15 +99,22 @@ class @Calendar
99
99
  classes.push("othermonth") if date.getMonth() != month
100
100
  classes.push("today") if date.same_as(new Date())
101
101
  classes.push("selected") if date.same_as(@date)
102
- "<td class='#{classes.join(" ")}'><a data-date='#{date.toDateString()}' href='#'>#{date.getDate()}</a></td>"
102
+ "<td class='#{classes.join(" ")}'><a data-date='#{@toDateString(date)}' href='#'>#{date.getDate()}</a></td>"
103
+
104
+ toDateString: (date) ->
105
+ month = date.getMonth()
106
+ day = date.getDate()
107
+ month = if month < 10 then "0#{month}" else month
108
+ day = if day < 10 then "0#{day}" else day
109
+ "#{date.getFullYear()}-#{month}-#{day}"
103
110
 
104
111
  clicked: (event) ->
105
112
  o=$(event.target)
106
113
  o=o.children("A") if o[0].tagName=="TD"
107
- # @date=new Date(@pager_date)
108
- # @date.setDate(parseInt(o.html()))
109
- @date=new Date(Date.parse(o.data("date")))
110
- @field.val(@date.toLocaleDateString())
114
+ args = o.data("date").split("-")
115
+ @date = new Date(args...)
116
+ # stuff the raw value in the value field
117
+ @field.val(o.data("date"))
111
118
  @element.find(".selected").removeClass "selected"
112
119
  o.parent().addClass("selected")
113
120
  @element.find(".selectedtext").html @generateFooter()
@@ -1,3 +1,4 @@
1
+ // Generated by CoffeeScript 1.3.3
1
2
  (function() {
2
3
  var $, DateHelper, dh;
3
4
 
@@ -10,7 +11,9 @@
10
11
  this.id = id;
11
12
  this.field = field;
12
13
  this.options = options != null ? options : {};
13
- if (!this.field.jquery) this.field = $("#" + this.field);
14
+ if (!this.field.jquery) {
15
+ this.field = $("#" + this.field);
16
+ }
14
17
  if (this.id != null) {
15
18
  this.element = $("#" + this.id);
16
19
  } else {
@@ -34,7 +37,9 @@
34
37
  };
35
38
 
36
39
  Calendar.prototype.getDateFromField = function() {
37
- if (this.field.val() === "") return;
40
+ if (this.field.val() === "") {
41
+ return;
42
+ }
38
43
  return this.date = this.parseIncomingDate();
39
44
  };
40
45
 
@@ -163,22 +168,46 @@
163
168
  var classes;
164
169
  classes = [];
165
170
  classes.push("day");
166
- if (date.getMonth() !== month) classes.push("othermonth");
167
- if (date.same_as(new Date())) classes.push("today");
168
- if (date.same_as(this.date)) classes.push("selected");
169
- return "<td class='" + (classes.join(" ")) + "'><a data-date='" + (date.toDateString()) + "' href='#'>" + (date.getDate()) + "</a></td>";
171
+ if (date.getMonth() !== month) {
172
+ classes.push("othermonth");
173
+ }
174
+ if (date.same_as(new Date())) {
175
+ classes.push("today");
176
+ }
177
+ if (date.same_as(this.date)) {
178
+ classes.push("selected");
179
+ }
180
+ return "<td class='" + (classes.join(" ")) + "'><a data-date='" + (this.toDateString(date)) + "' href='#'>" + (date.getDate()) + "</a></td>";
181
+ };
182
+
183
+ Calendar.prototype.toDateString = function(date) {
184
+ var day, month;
185
+ month = date.getMonth();
186
+ day = date.getDate();
187
+ month = month < 10 ? "0" + month : month;
188
+ day = day < 10 ? "0" + day : day;
189
+ return "" + (date.getFullYear()) + "-" + month + "-" + day;
170
190
  };
171
191
 
172
192
  Calendar.prototype.clicked = function(event) {
173
- var o;
193
+ var args, o;
174
194
  o = $(event.target);
175
- if (o[0].tagName === "TD") o = o.children("A");
176
- this.date = new Date(Date.parse(o.data("date")));
177
- this.field.val(this.date.toLocaleDateString());
195
+ if (o[0].tagName === "TD") {
196
+ o = o.children("A");
197
+ }
198
+ args = o.data("date").split("-");
199
+ this.date = (function(func, args, ctor) {
200
+ ctor.prototype = func.prototype;
201
+ var child = new ctor, result = func.apply(child, args), t = typeof result;
202
+ return t == "object" || t == "function" ? result || child : child;
203
+ })(Date, args, function(){});
204
+ this.field.val(o.data("date"));
178
205
  this.element.find(".selected").removeClass("selected");
179
206
  o.parent().addClass("selected");
180
207
  this.element.find(".selectedtext").html(this.generateFooter());
181
- if (this.options.onchange) this.options.onchange(this.field.val());
208
+ if (this.options.onchange) {
209
+ this.options.onchange(this.field.val());
210
+ }
182
211
  return false;
183
212
  };
184
213
 
@@ -198,8 +227,8 @@
198
227
  };
199
228
 
200
229
  Calendar.prototype.redraw = function() {
201
- var html;
202
- var _this = this;
230
+ var html,
231
+ _this = this;
203
232
  html = "<table class=\"" + this.options["class"] + "\" cellspacing=\"0\">\n<thead> \n <tr><th class=\"back\"><a href=\"#\">&larr;</a></th>\n <th colspan=\"5\" class=\"month_label\">" + (this.label()) + "</th>\n <th class=\"forward\"><a href=\"#\">&rarr;</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.generateFooter()) + "</td></tr>\n </tfoot>\n </table>";
204
233
  this.element.html(html);
205
234
  this.element.find("th.back").click(function() {
@@ -228,7 +257,9 @@
228
257
 
229
258
  DateHelper.forward_a_month = function(count) {
230
259
  var d, month;
231
- if (count == null) count = 1;
260
+ if (count == null) {
261
+ count = 1;
262
+ }
232
263
  month = this.getMonth() + count;
233
264
  d = new Date(this.getFullYear(), month, 1);
234
265
  return this.setTime(d);
@@ -236,7 +267,9 @@
236
267
 
237
268
  DateHelper.back_a_month = function(count) {
238
269
  var d, month;
239
- if (count == null) count = 1;
270
+ if (count == null) {
271
+ count = 1;
272
+ }
240
273
  month = this.getMonth() - count;
241
274
  d = new Date(this.getFullYear(), month, 1);
242
275
  return this.setTime(d);
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: input_calendar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Goebel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-05 00:00:00 Z
18
+ date: 2012-07-13 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Simple and clean JS calendar to enter dates on forms