diff --git a/README.mkd b/README.mkd new file mode 100644 index 0000000..7718b5b --- /dev/null +++ b/README.mkd @@ -0,0 +1,36 @@ +# CalendarDateSelect + +http://code.google.com/p/calendardateselect/ + +This project is looking for a new maintainer. Please contact me if you have sufficient interest in this project to move it forward. + +## Examples + +"See a demo here":http://electronicholas.com/calendar + +## Assets in Rails 3.1 or greater (with asset pipeline *enabled*) + +The asset files will be added to the asset pipeline and available for you to use. Add these lines in `app/assets/javascripts/application.js`: + +```js +//= require calendar_date_select +``` +*Optional*: Include your locale: +```js +//= require calendar_date_select/locale/fr +``` + +And add in your `app/assets/stylesheets/application.css`: +```css +/* + *= require calendar_date_select/default + */ +``` + +## Submitting patches + +Please take care to do the following: + +* Clean up your patch (don't send a patch bomb with a hundred features in one) +* Write test cases! +* As a general rule of thumb, think of ways to make things more general purpose than specific. diff --git a/README.txt b/README.txt deleted file mode 100644 index 5ee1dbd..0000000 --- a/README.txt +++ /dev/null @@ -1,17 +0,0 @@ -= CalendarDateSelect - -http://code.google.com/p/calendardateselect/ - -* This project is looking for a new maintainer. Please contact me if you have sufficient interest in this project to move it forward. - -== Examples - -"See a demo here":http://electronicholas.com/calendar - -== Submitting patches - -Please take care to do the following: - -* Clean up your patch (don't send a patch bomb with a hundred features in one) -* Write test cases! -* As a general rule of thumb, think of ways to make things more general purpose than specific. diff --git a/VERSION b/VERSION index 4a02d2c..c807441 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.2 +1.16.3 diff --git a/calendar_date_select.gemspec b/calendar_date_select.gemspec index 49b0065..8cb469e 100644 --- a/calendar_date_select.gemspec +++ b/calendar_date_select.gemspec @@ -81,6 +81,7 @@ Gem::Specification.new do |s| "spec/calendar_date_select/includes_helper_spec.rb", "spec/spec_helper.rb" ] + s.add_dependency 'prototype-rails' if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION diff --git a/public/images/calendar_date_select/calendar.gif b/lib/assets/images/calendar_date_select/calendar.gif similarity index 100% rename from public/images/calendar_date_select/calendar.gif rename to lib/assets/images/calendar_date_select/calendar.gif diff --git a/public/javascripts/calendar_date_select/calendar_date_select.js b/lib/assets/javascripts/calendar_date_select.js similarity index 97% rename from public/javascripts/calendar_date_select/calendar_date_select.js rename to lib/assets/javascripts/calendar_date_select.js index f22d521..8fb60c4 100644 --- a/public/javascripts/calendar_date_select/calendar_date_select.js +++ b/lib/assets/javascripts/calendar_date_select.js @@ -29,6 +29,7 @@ Date.padded2 = function(hour) { var padded2 = parseInt(hour, 10); if (hour < 10) Date.prototype.getPaddedMinutes = function() { return Date.padded2(this.getMinutes()); } Date.prototype.getAMPMHour = function() { var hour = this.getHours(); return (hour == 0) ? 12 : (hour > 12 ? hour - 12 : hour ) } Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "AM" : "PM"; } +Date.prototype.getHourForDropdown = function() { return this.getAMPMHour()+ " " + this.getAMPM(); } Date.prototype.stripTime = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate());}; Date.prototype.daysDistance = function(compare_date) { return Math.round((compare_date - this) / Date.one_day); }; Date.prototype.toFormattedString = function(include_time){ @@ -209,7 +210,7 @@ CalendarDateSelect.prototype = { var t = new Date(); this.hour_select = new SelectBox(buttons_div, - blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getAMPMHour()+ " " + t.getAMPM(),x])} )), + blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getHourForDropdown(),x])} )), { calendar_date_select: this, onchange: function() { this.calendar_date_select.updateSelectedDate( { hour: this.value });}, @@ -380,8 +381,16 @@ CalendarDateSelect.prototype = { this.selection_made = true; } - if (!isNaN(parts.get("hour"))) this.selected_date.setHours(parts.get("hour")); - if (!isNaN(parts.get("minute"))) this.selected_date.setMinutes( Math.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) ); + if (!isNaN(parts.get("hour"))){ + this.selected_date.setHours(parts.get("hour")); + this.selection_made = true; + } + + if (!isNaN(parts.get("minute"))){ + this.selected_date.setMinutes( Math.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) ); + this.selection_made = true; + } + if (parts.get("hour") === "" || parts.get("minute") === "") this.setUseTime(false); else if (!isNaN(parts.get("hour")) || !isNaN(parts.get("minute"))) @@ -456,4 +465,4 @@ CalendarDateSelect.prototype = { if (e.keyCode==Event.KEY_ESC) this.close(); }, callback: function(name, param) { if (this.options.get(name)) { this.options.get(name).bind(this.target_element)(param); } } -} \ No newline at end of file +} diff --git a/public/javascripts/calendar_date_select/format_american.js b/lib/assets/javascripts/calendar_date_select/format_american.js similarity index 100% rename from public/javascripts/calendar_date_select/format_american.js rename to lib/assets/javascripts/calendar_date_select/format_american.js diff --git a/public/javascripts/calendar_date_select/format_danish.js b/lib/assets/javascripts/calendar_date_select/format_danish.js similarity index 100% rename from public/javascripts/calendar_date_select/format_danish.js rename to lib/assets/javascripts/calendar_date_select/format_danish.js diff --git a/public/javascripts/calendar_date_select/format_db.js b/lib/assets/javascripts/calendar_date_select/format_db.js similarity index 100% rename from public/javascripts/calendar_date_select/format_db.js rename to lib/assets/javascripts/calendar_date_select/format_db.js diff --git a/public/javascripts/calendar_date_select/format_euro_24hr.js b/lib/assets/javascripts/calendar_date_select/format_euro_24hr.js similarity index 100% rename from public/javascripts/calendar_date_select/format_euro_24hr.js rename to lib/assets/javascripts/calendar_date_select/format_euro_24hr.js diff --git a/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js b/lib/assets/javascripts/calendar_date_select/format_euro_24hr_ymd.js similarity index 100% rename from public/javascripts/calendar_date_select/format_euro_24hr_ymd.js rename to lib/assets/javascripts/calendar_date_select/format_euro_24hr_ymd.js diff --git a/public/javascripts/calendar_date_select/format_finnish.js b/lib/assets/javascripts/calendar_date_select/format_finnish.js similarity index 100% rename from public/javascripts/calendar_date_select/format_finnish.js rename to lib/assets/javascripts/calendar_date_select/format_finnish.js diff --git a/public/javascripts/calendar_date_select/format_hyphen_ampm.js b/lib/assets/javascripts/calendar_date_select/format_hyphen_ampm.js similarity index 100% rename from public/javascripts/calendar_date_select/format_hyphen_ampm.js rename to lib/assets/javascripts/calendar_date_select/format_hyphen_ampm.js diff --git a/public/javascripts/calendar_date_select/format_iso_date.js b/lib/assets/javascripts/calendar_date_select/format_iso_date.js similarity index 100% rename from public/javascripts/calendar_date_select/format_iso_date.js rename to lib/assets/javascripts/calendar_date_select/format_iso_date.js diff --git a/public/javascripts/calendar_date_select/format_italian.js b/lib/assets/javascripts/calendar_date_select/format_italian.js similarity index 100% rename from public/javascripts/calendar_date_select/format_italian.js rename to lib/assets/javascripts/calendar_date_select/format_italian.js diff --git a/public/javascripts/calendar_date_select/locale/ar.js b/lib/assets/javascripts/calendar_date_select/locale/ar.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/ar.js rename to lib/assets/javascripts/calendar_date_select/locale/ar.js diff --git a/public/javascripts/calendar_date_select/locale/cs.js b/lib/assets/javascripts/calendar_date_select/locale/cs.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/cs.js rename to lib/assets/javascripts/calendar_date_select/locale/cs.js diff --git a/public/javascripts/calendar_date_select/locale/da.js b/lib/assets/javascripts/calendar_date_select/locale/da.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/da.js rename to lib/assets/javascripts/calendar_date_select/locale/da.js diff --git a/public/javascripts/calendar_date_select/locale/de.js b/lib/assets/javascripts/calendar_date_select/locale/de.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/de.js rename to lib/assets/javascripts/calendar_date_select/locale/de.js diff --git a/public/javascripts/calendar_date_select/locale/es.js b/lib/assets/javascripts/calendar_date_select/locale/es.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/es.js rename to lib/assets/javascripts/calendar_date_select/locale/es.js diff --git a/public/javascripts/calendar_date_select/locale/fi.js b/lib/assets/javascripts/calendar_date_select/locale/fi.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/fi.js rename to lib/assets/javascripts/calendar_date_select/locale/fi.js diff --git a/public/javascripts/calendar_date_select/locale/fr.js b/lib/assets/javascripts/calendar_date_select/locale/fr.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/fr.js rename to lib/assets/javascripts/calendar_date_select/locale/fr.js diff --git a/public/javascripts/calendar_date_select/locale/it.js b/lib/assets/javascripts/calendar_date_select/locale/it.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/it.js rename to lib/assets/javascripts/calendar_date_select/locale/it.js diff --git a/public/javascripts/calendar_date_select/locale/ja.js b/lib/assets/javascripts/calendar_date_select/locale/ja.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/ja.js rename to lib/assets/javascripts/calendar_date_select/locale/ja.js diff --git a/public/javascripts/calendar_date_select/locale/nl.js b/lib/assets/javascripts/calendar_date_select/locale/nl.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/nl.js rename to lib/assets/javascripts/calendar_date_select/locale/nl.js diff --git a/public/javascripts/calendar_date_select/locale/pl.js b/lib/assets/javascripts/calendar_date_select/locale/pl.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/pl.js rename to lib/assets/javascripts/calendar_date_select/locale/pl.js diff --git a/public/javascripts/calendar_date_select/locale/pt.js b/lib/assets/javascripts/calendar_date_select/locale/pt.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/pt.js rename to lib/assets/javascripts/calendar_date_select/locale/pt.js diff --git a/public/javascripts/calendar_date_select/locale/ru.js b/lib/assets/javascripts/calendar_date_select/locale/ru.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/ru.js rename to lib/assets/javascripts/calendar_date_select/locale/ru.js diff --git a/public/javascripts/calendar_date_select/locale/sl.js b/lib/assets/javascripts/calendar_date_select/locale/sl.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/sl.js rename to lib/assets/javascripts/calendar_date_select/locale/sl.js diff --git a/public/javascripts/calendar_date_select/locale/sv.js b/lib/assets/javascripts/calendar_date_select/locale/sv.js similarity index 100% rename from public/javascripts/calendar_date_select/locale/sv.js rename to lib/assets/javascripts/calendar_date_select/locale/sv.js diff --git a/public/stylesheets/calendar_date_select/blue.css b/lib/assets/stylesheets/calendar_date_select/blue.css similarity index 100% rename from public/stylesheets/calendar_date_select/blue.css rename to lib/assets/stylesheets/calendar_date_select/blue.css diff --git a/public/stylesheets/calendar_date_select/default.css b/lib/assets/stylesheets/calendar_date_select/default.css similarity index 100% rename from public/stylesheets/calendar_date_select/default.css rename to lib/assets/stylesheets/calendar_date_select/default.css diff --git a/public/stylesheets/calendar_date_select/green.css b/lib/assets/stylesheets/calendar_date_select/green.css similarity index 100% rename from public/stylesheets/calendar_date_select/green.css rename to lib/assets/stylesheets/calendar_date_select/green.css diff --git a/public/stylesheets/calendar_date_select/plain.css b/lib/assets/stylesheets/calendar_date_select/plain.css similarity index 100% rename from public/stylesheets/calendar_date_select/plain.css rename to lib/assets/stylesheets/calendar_date_select/plain.css diff --git a/public/stylesheets/calendar_date_select/red.css b/lib/assets/stylesheets/calendar_date_select/red.css similarity index 100% rename from public/stylesheets/calendar_date_select/red.css rename to lib/assets/stylesheets/calendar_date_select/red.css diff --git a/public/stylesheets/calendar_date_select/silver.css b/lib/assets/stylesheets/calendar_date_select/silver.css similarity index 100% rename from public/stylesheets/calendar_date_select/silver.css rename to lib/assets/stylesheets/calendar_date_select/silver.css diff --git a/lib/calendar_date_select.rb b/lib/calendar_date_select.rb index d0336db..f5e64ae 100644 --- a/lib/calendar_date_select.rb +++ b/lib/calendar_date_select.rb @@ -8,20 +8,25 @@ module CalendarDateSelect Files = [ - '/public', - '/public/javascripts/calendar_date_select', - '/public/stylesheets/calendar_date_select', - '/public/images/calendar_date_select', - '/public/javascripts/calendar_date_select/locale' + '/lib/assets', + '/lib/assets/javascripts/calendar_date_select', + '/lib/assets/stylesheets/calendar_date_select', + '/lib/assets/images/calendar_date_select', + '/lib/assets/javascripts/calendar_date_select/locale' ] + module Rails + class Engine < ::Rails::Engine + end + end + class Railtie < ::Rails::Railtie initializer 'calendardateselect.initialize', :after => :action_view do ActionView::Helpers::FormHelper.send(:include, CalendarDateSelect::FormHelpers) ActionView::Base.send(:include, CalendarDateSelect::FormHelpers) ActionView::Base.send(:include, CalendarDateSelect::IncludesHelper) - + ActionView::Helpers::InstanceTag.class_eval do class << self; alias new_with_backwards_compatibility new; end #TODO: singleton_class.class_eval end diff --git a/lib/calendar_date_select/calendar_date_select.rb b/lib/calendar_date_select/calendar_date_select.rb index 36b5b68..907c4ae 100644 --- a/lib/calendar_date_select/calendar_date_select.rb +++ b/lib/calendar_date_select/calendar_date_select.rb @@ -1,5 +1,5 @@ module CalendarDateSelect - VERSION = '1.16.2' + VERSION = '1.16.3' FORMATS = { :natural => { diff --git a/lib/calendar_date_select/form_helpers.rb b/lib/calendar_date_select/form_helpers.rb index 4b6f995..24a5f1e 100644 --- a/lib/calendar_date_select/form_helpers.rb +++ b/lib/calendar_date_select/form_helpers.rb @@ -102,6 +102,7 @@ def calendar_date_select_tag( name, value = nil, options = {}) javascript_options.delete(:format) options[:id] ||= name + options.merge!(:onclick => "new CalendarDateSelect( $(this), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );") tag = javascript_options[:hidden] || javascript_options[:embedded] ? hidden_field_tag(name, value, options) : text_field_tag(name, value, options) @@ -143,9 +144,14 @@ def calendar_date_select(object, method, options={}) end end - tag = ActionView::Helpers::InstanceTag.new_with_backwards_compatibility(object, method, self, options.delete(:object)) + + options.delete(:object) + options.merge!(:type => (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text") + options.merge!(:onclick => "new CalendarDateSelect( $(this), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );") + tag = ActionView::Helpers::Tags::TextField.new(object, method, self, options).render + calendar_date_select_output( - tag.to_input_field_tag( (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text", options), + tag, image, options, javascript_options @@ -203,15 +209,16 @@ def calendar_date_select_process_options(options) def calendar_date_select_output(input, image, options = {}, javascript_options = {}) out = input + if javascript_options[:embedded] uniq_id = "cds_placeholder_#{(rand*100000).to_i}" # we need to be able to locate the target input element, so lets stick an invisible span tag here we can easily locate out << content_tag(:span, nil, :style => "display: none; position: absolute;", :id => uniq_id) - out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{options_for_javascript(javascript_options)} ); ") + out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} ); ") else out << " " out << image_tag(image, - :onclick => "new CalendarDateSelect( $(this).previous(), #{options_for_javascript(javascript_options)} );", + :onclick => "new CalendarDateSelect( $(this).previous(), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );", :style => 'border:0px; cursor:pointer;', :class=>'calendar_date_select_popup_icon') end diff --git a/lib/calendar_date_select/version.rb b/lib/calendar_date_select/version.rb new file mode 100644 index 0000000..fb3a94a --- /dev/null +++ b/lib/calendar_date_select/version.rb @@ -0,0 +1,5 @@ +module CalendarDateSelect + module Rails + VERSION = "1.2.0" + end +end