Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
* onchange event handler
Browse files Browse the repository at this point in the history
* detects to see if prototype is loaded.  If not, shows error message
* ability to hide "buttons"

git-svn-id: https://calendardateselect.googlecode.com/svn/trunk@76 4972a71b-da31-0410-b7dd-373b726a5e75
  • Loading branch information
timcharper committed Jul 11, 2007
1 parent b651fe8 commit f71dc04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/calendar_date_select.rb
Expand Up @@ -24,10 +24,10 @@ def calendar_date_select_tag( name, value = nil, options = {})

def calendar_date_select_process_options(options)
calendar_options = {}
calendar_options[:time] = options.delete(:time) ? true : false
calendar_options[:embedded] = options.delete(:embedded) ? true : false
for key in [:time, :embedded, :buttons]
calendar_options[key] = options.delete(key) if options.has_key?(key)
end
calendar_options[:year_range] = options.delete(:year_range) || 10

options[:format] ||= "%B %d, %Y" + (calendar_options[:time] ? " %I:%M %p" : '')

calendar_options
Expand Down
28 changes: 21 additions & 7 deletions public/javascripts/calendar_date_select.js
@@ -1,5 +1,8 @@
// CalendarDateSelect version 1.5.1 - a small prototype based date picker
// CalendarDateSelect version 1.5.2 - a small prototype based date picker
// Questions, comments, bugs? - email the Author - Tim Harper <"timseeharper@gmail.seeom".gsub("see", "c")>
if (typeof Prototype == 'undefined')
alert("CalendarDateSelect Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes calendar_date_select.js (e.g. <%= calendar_date_select_includes %>).");

Element.addMethods({
purgeChildren: function(element) { $A(element.childNodes).each(function(e){$(e).remove();}); },
build: function(element, type, options, style) {
Expand Down Expand Up @@ -45,10 +48,12 @@ CalendarDateSelect.prototype = {
this.options = $H({
embedded: false,
time: false,
buttons: true,
year_range: 10,
calendar_div: nil,
close_on_click: nil,
minute_interval: 5
minute_interval: 5,
onchange: nil
}).merge(options || {});

this.target_element = $(target_element); // make sure it's an element, not a string
Expand Down Expand Up @@ -90,8 +95,11 @@ CalendarDateSelect.prototype = {

this.initFrame();
if(!this.options["embedded"]) setTimeout(function(){
if (( parseInt(this.calendar_div.style.top) + this.calendar_div.getDimensions().height ) > (window.f_scrollTop() + window.f_height()))
this.positionCalendarDiv(true);
c_h = this.calendar_div.getDimensions().height; w_t = window.f_scrollTop();
if (( parseInt(this.calendar_div.style.top) + c_h ) > (w_t + window.f_height()))
e_t = Position.cumulativeOffset(this.target_element)[1];
if ( (e_t - c_h) > w_t ) // will it stay below the top of the window
this.positionCalendarDiv(true);
}.bindAsEventListener(this), 1);
},
positionCalendarDiv: function(above) {
Expand Down Expand Up @@ -159,6 +167,7 @@ CalendarDateSelect.prototype = {
initButtonsDiv: function()
{
buttons_div = this.buttons_div;
if (!this.options["buttons"]) { Element.remove(buttons_div); return false; };

buttons_div.build("input", {
value: (this.options["time"] ? "Now" : "Today" ),
Expand Down Expand Up @@ -308,11 +317,16 @@ CalendarDateSelect.prototype = {
if (parts.hour) this.selected_date.setHours(parts.hour);
if (parts.minute) this.selected_date.setMinutes(parts.minute);

if (this.selection_made) this.target_element.value = this.dateString();
if (this.options.close_on_click) { this.close(); }

this.updateFooter();
this.setSelectedClass();

if (this.selection_made) this.updateValue();
if (this.options.close_on_click) { this.close(); }

},
updateValue: function() {
this.target_element.value = this.dateString();
if (this.target_element.onchange) this.target_element.onchange();
},
today: function() {
this.date = new Date();
Expand Down

0 comments on commit f71dc04

Please sign in to comment.