Permalink
Browse files

Added MooTools javascript support with generator

Updated README
  • Loading branch information...
tazsingh committed Apr 15, 2011
1 parent be02d4a commit 131d6dee147f4d515daa77d4acc7fa77f369bfcc
View
@@ -42,14 +42,14 @@ To generate the necessary static files AND the example below:
script/generate event_calendar --help
--static-only: Only generate the stylesheet and javascript
- --use-jquery: Generate jquery javascript
+ --use-jquery: Generate jQuery javascript
+ --use-mootools: Generate MooTools javascript
--use-all-day: Include an 'all_day' field on events, and display appropriately
You can change the default event model name (Event) and controller/view name (Calendar) by passing in two name arguments:
script/generate event_calendar EventModel ControllerName
-
==Generated Files
Make sure to include the stylesheet and javascript in your layout/view.
@@ -160,6 +160,7 @@ Some helper methods are created, but you could put this in the view. The key is
end
Notice you can pass in a block to the calendar method. In this example I'm passing a link to the event details, and displaying the event's name.
+If you are using the MooTools javascript, a Tip will be created with the content of the link's title attribute for displaying additional information.
====app/views/calendar/index.html.erb
@@ -255,6 +256,10 @@ You can override any of these by passing your options to the calendar method. In
* The event <b>select color</b> is set in the event_calendar.js file.
+===ORM Support
+
+Mongoid is supported out of the box with no additional lines of code in the model. Use the has_event_calendar method as you do with ActiveRecord.
+
==il8n
To localize month and day names, add the following to your localization file(s) in config/locales:
@@ -3,7 +3,8 @@
class EventCalendarGenerator < Rails::Generator::Base
default_options :static_only => false,
:use_jquery => false,
- :use_all_day => false
+ :use_all_day => false,
+ :use_mootools => false
attr_reader :class_name, :view_name
@@ -19,8 +20,8 @@ def manifest
# static files
m.file "stylesheet.css", "public/stylesheets/event_calendar.css"
- script = options[:use_jquery] ? 'jq_javascript.js' : 'javascript.js'
- m.file script, "public/javascripts/event_calendar.js"
+ script = options[:use_jquery] ? 'jq_javascript.js' : (options[:use_mootools] ? 'mt_javascript.js' : 'javascript.js')
+ m.file script, "public/javascripts/event_calendar.js"
# MVC and other supporting files
unless options[:static_only]
@@ -42,8 +43,10 @@ def add_options!(opt)
opt.separator 'Options:'
opt.on("--static-only",
"Only generate the static files. (stylesheet, javascript, and images)") { |v| options[:static_only] = v }
- opt.on("--use-jquery",
- "Use jquery template file when generating the javascript.") { |v| options[:use_jquery] = v }
+ { 'jquery' => 'jQuery', 'mootools' => 'MooTools' }.each do |k,v|
+ opt.on("--use-#{k}",
+ "Use #{v} template file when generating the javascript.") { |val| options[:"use_#{v}"] = val }
+ end
opt.on("--use-all-day",
"Include an 'all_day' field on events, and display appropriately.") { |v| options[:use_all_day] = v }
end
@@ -0,0 +1,45 @@
+window.addEvent('load', function() {
+ var highlight_color = "#2EAC6A";
+
+ new Tips('.ec-event a');
+
+ $$(".ec-event-bg").each(function(el) {
+ el.addEvent('mouseover', function(e) {
+ event_id = el.getProperty('data-event-id');
+ $$(".ec-event-"+event_id).each(function(ele) {
+ ele.setStyle('background-color',highlight_color);
+ });
+ });
+ el.addEvent('mouseout', function(e) {
+ event_color = el.getProperty('data-color');
+ event_id = el.getProperty('data-event-id');
+ $$(".ec-event-"+event_id).each(function(ele) {
+ ele.setStyle('background-color',event_color);
+ });
+ });
+ });
+
+ $$(".ec-event-no-bg").each(function(el) {
+ el.addEvent('mouseover', function(e) {
+ el.setStyle({ 'color': '#FFF' });
+ el.getChildren('a').each(function(link) {
+ link.setStyle('color','#FFF');
+ });
+ el.getChildren('.ec-bullet').each(function(bullet) {
+ bullet.setStyle('background-color','#FFF');
+ });
+ el.setStyle('background-color',highlight_color);
+ });
+ el.addEvent('mouseout', function(e) {
+ event_color = el.getProperty('data-color');
+ el.setStyle({'color': event_color});
+ el.getChildren('a').each(function(link) {
+ link.setStyle('color',event_color);
+ });
+ el.getChildren('.ec-bullet').each(function(bullet) {
+ bullet.setStyle('background-color',event_color);
+ });
+ el.setStyle('background-color','transparent');
+ })
+ });
+});
@@ -9,7 +9,9 @@ class EventCalendarGenerator < Rails::Generators::Base
argument :controller_name, :optional => true, :default => 'calendar'
class_option :static_only, :type => :boolean, :default => false, :desc => "Only generate stylesheets and scripts"
- class_option :use_jquery, :type => :boolean, :default => false, :desc => "Use JQuery for scripting"
+ { 'jquery' => 'jQuery', 'mootools' => 'MooTools' }.each do |k,v|
+ class_option :"use_#{k}", :type => :boolean, :default => false, :desc => "Use #{v} for scripting"
+ end
class_option :use_all_day, :type => :boolean, :default => false, :desc => "Add an additional 'all_day' attribute"
class_option :use_color, :type => :boolean, :default => false, :desc => "Add an additional 'color' attribute"
@@ -18,8 +20,11 @@ def do_it
say "Adding a color column", :yellow if options[:use_color]
if options[:use_jquery]
- say "Using JQuery for scripting", :yellow
+ say "Using jQuery for scripting", :yellow
copy_file 'jq_javascript.js', "public/javascripts/event_calendar.js"
+ elsif options[:use_mootools]
+ say "Using MooTools for scripting", :yellow
+ copy_file "mt_javascript.js", "public/javascripts/event_calendar.js"
else
say "Using Prototype for scripting", :yellow
copy_file 'javascript.js', "public/javascripts/event_calendar.js"
@@ -0,0 +1,45 @@
+window.addEvent('load', function() {
+ var highlight_color = "#2EAC6A";
+
+ new Tips('.ec-event a');
+
+ $$(".ec-event-bg").each(function(el) {
+ el.addEvent('mouseover', function(e) {
+ event_id = el.getProperty('data-event-id');
+ $$(".ec-event-"+event_id).each(function(ele) {
+ ele.setStyle('background-color',highlight_color);
+ });
+ });
+ el.addEvent('mouseout', function(e) {
+ event_color = el.getProperty('data-color');
+ event_id = el.getProperty('data-event-id');
+ $$(".ec-event-"+event_id).each(function(ele) {
+ ele.setStyle('background-color',event_color);
+ });
+ });
+ });
+
+ $$(".ec-event-no-bg").each(function(el) {
+ el.addEvent('mouseover', function(e) {
+ el.setStyle({ 'color': '#FFF' });
+ el.getChildren('a').each(function(link) {
+ link.setStyle('color','#FFF');
+ });
+ el.getChildren('.ec-bullet').each(function(bullet) {
+ bullet.setStyle('background-color','#FFF');
+ });
+ el.setStyle('background-color',highlight_color);
+ });
+ el.addEvent('mouseout', function(e) {
+ event_color = el.getProperty('data-color');
+ el.setStyle({'color': event_color});
+ el.getChildren('a').each(function(link) {
+ link.setStyle('color',event_color);
+ });
+ el.getChildren('.ec-bullet').each(function(bullet) {
+ bullet.setStyle('background-color',event_color);
+ });
+ el.setStyle('background-color','transparent');
+ })
+ });
+});

0 comments on commit 131d6de

Please sign in to comment.