Add blueprint style and install jRails plugin

This commit is contained in:
Wen-Tien Chang 2009-05-15 14:02:28 +08:00
parent 0f5ae0d34d
commit 68622bb23c
17 changed files with 821 additions and 13 deletions

View File

@ -5,7 +5,7 @@
<p> <p>
<%= f.label :name, "Name" %> <%= f.label :name, "Name" %>
<%= f.text_field :name %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p> <p>

View File

@ -1,17 +1,32 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pages: <%= controller.action_name %></title> <title>R4</title>
<%= stylesheet_link_tag 'scaffold' %> <link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %>
<%= stylesheet_link_tag "blueprint/screen", "forms", "main", :media => "screen, projection" %>
<%= stylesheet_link_tag "blueprint/print", :media => "print" %>
<!--[if IE]>
<%= stylesheet_link_tag "blueprint/ie", :media => "screen, projection" %>
<![endif]-->
<%= yield :page_specific_css %>
</head> </head>
<body> <body>
<div class="container">
<div id ="nav" class="span-24">
<%= link_to 'Pages', admin_pages_path %> |
<%= link_to 'Snippet', admin_snippets_path %> |
<%= link_to 'Layout', admin_layouts_path %>
</div>
<p style="color: green"><%= flash[:notice] %></p> <%= yield %>
</div>
<%= yield %>
<%= javascript_include_tag "jquery",
"jquery-ui",
"jrails",
"application", :cache => 'all' %>
<%= yield :page_specific_javascript %>
</body> </body>
</html> </html>

1
public/javascripts/jquery-ui.js vendored Normal file

File diff suppressed because one or more lines are too long

19
public/javascripts/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
(function($){$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*"})(jQuery);(function($){$.fn.reset=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset()}})};$.fn.enable=function(){return this.each(function(){this.disabled=false})};$.fn.disable=function(){return this.each(function(){this.disabled=true})}})(jQuery);(function($){$.extend({fieldEvent:function(el,obs){var field=el[0]||el,e="change";if(field.type=="radio"||field.type=="checkbox"){e="click"}else{if(obs&&field.type=="text"||field.type=="textarea"){e="keyup"}}return e}});$.fn.extend({delayedObserver:function(delay,callback){var el=$(this);if(typeof window.delayedObserverStack=="undefined"){window.delayedObserverStack=[]}if(typeof window.delayedObserverCallback=="undefined"){window.delayedObserverCallback=function(stackPos){observed=window.delayedObserverStack[stackPos];if(observed.timer){clearTimeout(observed.timer)}observed.timer=setTimeout(function(){observed.timer=null;observed.callback(observed.obj,observed.obj.formVal())},observed.delay*1000);observed.oldVal=observed.obj.formVal()}}window.delayedObserverStack.push({obj:el,timer:null,delay:delay,oldVal:el.formVal(),callback:callback});var stackPos=window.delayedObserverStack.length-1;if(el[0].tagName=="FORM"){$(":input",el).each(function(){var field=$(this);field.bind($.fieldEvent(field,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})})}else{el.bind($.fieldEvent(el,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})}},formVal:function(){var el=this[0];if(el.tagName=="FORM"){return this.serialize()}if(el.type=="checkbox"||self.type=="radio"){return this.filter("input:checked").val()||""}else{return this.val()}}})})(jQuery);(function($){$.fn.extend({visualEffect:function(o){e=o.replace(/\_(.)/g,function(m,l){return l.toUpperCase()});return eval("$(this)."+e+"()")},appear:function(speed,callback){return this.fadeIn(speed,callback)},blindDown:function(speed,callback){return this.show("blind",{direction:"vertical"},speed,callback)},blindUp:function(speed,callback){return this.hide("blind",{direction:"vertical"},speed,callback)},blindRight:function(speed,callback){return this.show("blind",{direction:"horizontal"},speed,callback)},blindLeft:function(speed,callback){this.hide("blind",{direction:"horizontal"},speed,callback);return this},dropOut:function(speed,callback){return this.hide("drop",{direction:"down"},speed,callback)},dropIn:function(speed,callback){return this.show("drop",{direction:"up"},speed,callback)},fade:function(speed,callback){return this.fadeOut(speed,callback)},fadeToggle:function(speed,callback){return this.animate({opacity:"toggle"},speed,callback)},fold:function(speed,callback){return this.hide("fold",{},speed,callback)},foldOut:function(speed,callback){return this.show("fold",{},speed,callback)},grow:function(speed,callback){return this.show("scale",{},speed,callback)},highlight:function(speed,callback){return this.show("highlight",{},speed,callback)},puff:function(speed,callback){return this.hide("puff",{},speed,callback)},pulsate:function(speed,callback){return this.show("pulsate",{},speed,callback)},shake:function(speed,callback){return this.show("shake",{},speed,callback)},shrink:function(speed,callback){return this.hide("scale",{},speed,callback)},squish:function(speed,callback){return this.hide("scale",{origin:["top","left"]},speed,callback)},slideUp:function(speed,callback){return this.hide("slide",{direction:"up"},speed,callback)},slideDown:function(speed,callback){return this.show("slide",{direction:"up"},speed,callback)},switchOff:function(speed,callback){return this.hide("clip",{},speed,callback)},switchOn:function(speed,callback){return this.show("clip",{},speed,callback)}})})(jQuery);

View File

@ -0,0 +1,49 @@
/* --------------------------------------------------------------
forms.css
* Sets up some default styling for forms
* Gives you classes to enhance your forms
Usage:
* For text fields, use class .title or .text
-------------------------------------------------------------- */
label { font-weight: bold; }
fieldset { padding:1.4em; margin: 0 0 1.5em 0; border: 1px solid #ccc; }
legend { font-weight: bold; font-size:1.2em; }
/* Form fields
-------------------------------------------------------------- */
input.text, input.title,
textarea, select {
margin:0.5em 0;
border:1px solid #bbb;
}
input.text:focus, input.title:focus,
textarea:focus, select:focus {
border:1px solid #666;
}
input.text,
input.title { width: 300px; padding:5px; }
input.title { font-size:1.5em; }
textarea { width: 390px; height: 250px; padding:5px; }
/* Success, notice and error boxes
-------------------------------------------------------------- */
.error,
.notice,
.success { padding: .8em; margin-bottom: 1em; border: 2px solid #ddd; }
.error { background: #FBE3E4; color: #8a1f11; border-color: #FBC2C4; }
.notice { background: #FFF6BF; color: #514721; border-color: #FFD324; }
.success { background: #E6EFC2; color: #264409; border-color: #C6D880; }
.error a { color: #8a1f11; }
.notice a { color: #514721; }
.success a { color: #264409; }

View File

@ -0,0 +1,10 @@
#nav {
background-color: #333;
padding: 5px;
color: #fff;
}
#nav a {
color: #fff;
text-decoration: none;
}

35
vendor/plugins/jrails/CHANGELOG vendored Normal file
View File

@ -0,0 +1,35 @@
SVN
* better approximate scriptaculous effect names
* add support for page[:element_id].visual_effect(:effect) as well as page.visual_effect(:effect, :element_id)
* added a reset form function to jrails.js (stolen from jquery form)
* can now use jquery selectors in all functions
* added javascript_function helper to render inline rjs helpers
* better support for sortable_element
* updated to jquery-ui 1.5.1
0.4.0 (16 June 2008)
* updated to jquery-ui 1.5 & merged js into single file
* Added jQuery.noConflict support
* support for value/val
* additional support for update/delete methods
* support for success/failure hash
* setRequestHeader now gets called globally
* Better support for droppables, sortables
* Add support for prototype AJAX callbacks
* better support for AJAX form calls
0.3.0 (22 Feb 2008)
* updated to jquery-fx 1.0b and jquery-ui 1.5b
* Add text/javascript request header to fix format.js
* Added Tasks (thanks ggarside)
* Improve visual_effects methods
* Fixed some RJS calls
* Fixed observer code for ie
0.2.0 (26 Nov 2007)
* Vastly Improved FX
* Improved Form Observers
* Fixed Rails <= 1.2.6 Compatibility
0.1.0 (15 Nov 2007)
* Initial release

21
vendor/plugins/jrails/README vendored Normal file
View File

@ -0,0 +1,21 @@
= jRails
jRails is a drop-in jQuery replacement for the Rails Prototype/script.aculo.us helpers.
== Resources
Install
* .script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails
Project Site
* http://code.google.com/p/ennerchi/
Web Site
* http://www.ennerchi.com/projects/jrails
Group Site
* http://groups.google.com/group/jrails

6
vendor/plugins/jrails/init.rb vendored Normal file
View File

@ -0,0 +1,6 @@
# uncomment to use jQuery.noConflict()
#ActionView::Helpers::PrototypeHelper::JQUERY_VAR = 'jQuery'
ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = ['jquery','jquery-ui','jrails']
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
require 'jrails'

9
vendor/plugins/jrails/install.rb vendored Normal file
View File

@ -0,0 +1,9 @@
# Install hook code here
puts "Copying files..."
dir = "javascripts"
["jquery-ui.js", "jquery.js", "jrails.js"].each do |js_file|
dest_file = File.join(RAILS_ROOT, "public", dir, js_file)
src_file = File.join(File.dirname(__FILE__) , dir, js_file)
FileUtils.cp_r(src_file, dest_file)
end
puts "Files copied - Installation complete!"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
(function($){$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*"})(jQuery);(function($){$.fn.reset=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset()}})};$.fn.enable=function(){return this.each(function(){this.disabled=false})};$.fn.disable=function(){return this.each(function(){this.disabled=true})}})(jQuery);(function($){$.extend({fieldEvent:function(el,obs){var field=el[0]||el,e="change";if(field.type=="radio"||field.type=="checkbox"){e="click"}else{if(obs&&field.type=="text"||field.type=="textarea"){e="keyup"}}return e}});$.fn.extend({delayedObserver:function(delay,callback){var el=$(this);if(typeof window.delayedObserverStack=="undefined"){window.delayedObserverStack=[]}if(typeof window.delayedObserverCallback=="undefined"){window.delayedObserverCallback=function(stackPos){observed=window.delayedObserverStack[stackPos];if(observed.timer){clearTimeout(observed.timer)}observed.timer=setTimeout(function(){observed.timer=null;observed.callback(observed.obj,observed.obj.formVal())},observed.delay*1000);observed.oldVal=observed.obj.formVal()}}window.delayedObserverStack.push({obj:el,timer:null,delay:delay,oldVal:el.formVal(),callback:callback});var stackPos=window.delayedObserverStack.length-1;if(el[0].tagName=="FORM"){$(":input",el).each(function(){var field=$(this);field.bind($.fieldEvent(field,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})})}else{el.bind($.fieldEvent(el,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})}},formVal:function(){var el=this[0];if(el.tagName=="FORM"){return this.serialize()}if(el.type=="checkbox"||self.type=="radio"){return this.filter("input:checked").val()||""}else{return this.val()}}})})(jQuery);(function($){$.fn.extend({visualEffect:function(o){e=o.replace(/\_(.)/g,function(m,l){return l.toUpperCase()});return eval("$(this)."+e+"()")},appear:function(speed,callback){return this.fadeIn(speed,callback)},blindDown:function(speed,callback){return this.show("blind",{direction:"vertical"},speed,callback)},blindUp:function(speed,callback){return this.hide("blind",{direction:"vertical"},speed,callback)},blindRight:function(speed,callback){return this.show("blind",{direction:"horizontal"},speed,callback)},blindLeft:function(speed,callback){this.hide("blind",{direction:"horizontal"},speed,callback);return this},dropOut:function(speed,callback){return this.hide("drop",{direction:"down"},speed,callback)},dropIn:function(speed,callback){return this.show("drop",{direction:"up"},speed,callback)},fade:function(speed,callback){return this.fadeOut(speed,callback)},fadeToggle:function(speed,callback){return this.animate({opacity:"toggle"},speed,callback)},fold:function(speed,callback){return this.hide("fold",{},speed,callback)},foldOut:function(speed,callback){return this.show("fold",{},speed,callback)},grow:function(speed,callback){return this.show("scale",{},speed,callback)},highlight:function(speed,callback){return this.show("highlight",{},speed,callback)},puff:function(speed,callback){return this.hide("puff",{},speed,callback)},pulsate:function(speed,callback){return this.show("pulsate",{},speed,callback)},shake:function(speed,callback){return this.show("shake",{},speed,callback)},shrink:function(speed,callback){return this.hide("scale",{},speed,callback)},squish:function(speed,callback){return this.hide("scale",{origin:["top","left"]},speed,callback)},slideUp:function(speed,callback){return this.hide("slide",{direction:"up"},speed,callback)},slideDown:function(speed,callback){return this.show("slide",{direction:"up"},speed,callback)},switchOff:function(speed,callback){return this.hide("clip",{},speed,callback)},switchOn:function(speed,callback){return this.show("clip",{},speed,callback)}})})(jQuery);

View File

@ -0,0 +1,192 @@
/*
*
* jRails ajax extras
* version 0.1
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*";
})(jQuery);
/*
*
* jRails form extras
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
// reset a form
$.fn.reset = function() {
return this.each(function() {
// guard against an input with the name of 'reset'
// note that IE reports the reset function as an 'object'
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
this.reset();
});
};
// enable a form element
$.fn.enable = function() {
return this.each(function() {
this.disabled = false;
});
};
// disable a form element
$.fn.disable = function() {
return this.each(function() {
this.disabled = true;
});
};
})(jQuery);
/*
*
* jRails form observer plugin
* version 0.2
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.extend({ // Translate field to event
fieldEvent: function(el, obs) {
var field = el[0] || el, e = 'change';
if (field.type == 'radio' || field.type == 'checkbox') e = 'click';
else if (obs && field.type == 'text' || field.type == 'textarea') e = 'keyup';
return e;
}
});
$.fn.extend({ // Delayed observer for fields and forms
delayedObserver: function(delay, callback){
var el = $(this);
if (typeof window.delayedObserverStack == 'undefined') window.delayedObserverStack = [];
if (typeof window.delayedObserverCallback == 'undefined') {
window.delayedObserverCallback = function(stackPos) {
var observed = window.delayedObserverStack[stackPos];
if (observed.timer) clearTimeout(observed.timer);
observed.timer = setTimeout(function(){
observed.timer = null;
observed.callback(observed.obj, observed.obj.formVal());
}, observed.delay * 1000);
observed.oldVal = observed.obj.formVal();
};
}
window.delayedObserverStack.push({
obj: el, timer: null, delay: delay,
oldVal: el.formVal(), callback: callback
});
var stackPos = window.delayedObserverStack.length-1;
if (el[0].tagName == 'FORM') {
$(':input', el).each(function(){
var field = $(this);
field.bind($.fieldEvent(field, delay), function(){
var observed = window.delayedObserverStack[stackPos];
if (observed.obj.formVal() == observed.oldVal) return;
else window.delayedObserverCallback(stackPos);
});
});
} else {
el.bind($.fieldEvent(el, delay), function(){
var observed = window.delayedObserverStack[stackPos];
if (observed.obj.formVal() == observed.oldVal) return;
else window.delayedObserverCallback(stackPos);
});
};
},
formVal: function() { // Gets form values
var el = this[0];
if(el.tagName == 'FORM') return this.serialize();
if(el.type == 'checkbox' || el.type == 'radio') return this.filter('input:checked').val() || '';
else return this.val();
}
});
})(jQuery);
/*
*
* jRails visual effects stubs
* version 0.2
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.fn.extend({
visualEffect : function(o) {
e = o.replace(/\_(.)/g, function(m, l){return l.toUpperCase()});
return eval('$(this).'+e+'()');
},
appear : function(speed, callback) {
return this.fadeIn(speed, callback);
},
blindDown : function(speed, callback) {
return this.show('blind', { direction: 'vertical' }, speed, callback);
},
blindUp : function(speed, callback) {
return this.hide('blind', { direction: 'vertical' }, speed, callback);
},
blindRight : function(speed, callback) {
return this.show('blind', { direction: 'horizontal' }, speed, callback);
},
blindLeft : function(speed, callback) {
this.hide('blind', { direction: 'horizontal' }, speed, callback);
return this;
},
dropOut : function(speed, callback) {
return this.hide('drop', {direction: 'down' }, speed, callback);
},
dropIn : function(speed, callback) {
return this.show('drop', { direction: 'up' }, speed, callback);
},
fade : function(speed, callback) {
return this.fadeOut(speed, callback);
},
fadeToggle : function(speed, callback) {
return this.animate({opacity: 'toggle'}, speed, callback);
},
fold : function(speed, callback) {
return this.hide('fold', {}, speed, callback);
},
foldOut : function(speed, callback) {
return this.show('fold', {}, speed, callback);
},
grow : function(speed, callback) {
return this.show('scale', {}, speed, callback);
},
highlight : function(speed, callback) {
return this.show('highlight', {}, speed, callback);
},
puff : function(speed, callback) {
return this.hide('puff', {}, speed, callback);
},
pulsate : function(speed, callback) {
return this.show('pulsate', {}, speed, callback);
},
shake : function(speed, callback) {
return this.show('shake', {}, speed, callback);
},
shrink : function(speed, callback) {
return this.hide('scale', {}, speed, callback);
},
squish : function(speed, callback) {
return this.hide('scale', { origin: ['top', 'left'] }, speed, callback);
},
slideUp : function(speed, callback) {
return this.hide('slide', { direction: 'up'}, speed, callback);
},
slideDown : function(speed, callback) {
return this.show('slide', { direction: 'up'}, speed, callback);
},
switchOff : function(speed, callback) {
return this.hide('clip', {}, speed, callback);
},
switchOn : function(speed, callback) {
return this.show('clip', {}, speed, callback);
}
});
})(jQuery);

410
vendor/plugins/jrails/lib/jrails.rb vendored Normal file
View File

@ -0,0 +1,410 @@
module ActionView
module Helpers
module JavaScriptHelper
# This function can be used to render rjs inline
#
# <%= javascript_function do |page|
# page.replace_html :list, :partial => 'list', :object => @list
# end %>
#
def javascript_function(*args, &block)
html_options = args.extract_options!
function = args[0] || ''
html_options.symbolize_keys!
function = update_page(&block) if block_given?
javascript_tag(function)
end
def jquery_id(id)
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
end
def jquery_ids(ids)
Array(ids).map{|id| jquery_id(id)}.join(',')
end
end
module PrototypeHelper
unless const_defined? :JQUERY_VAR
JQUERY_VAR = '$'
end
unless const_defined? :JQCALLBACKS
JQCALLBACKS = Set.new([ :beforeSend, :complete, :error, :success ] + (100..599).to_a)
AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
:asynchronous, :method, :insertion, :position,
:form, :with, :update, :script ]).merge(JQCALLBACKS)
end
def periodically_call_remote(options = {})
frequency = options[:frequency] || 10 # every ten seconds by default
code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
javascript_tag(code)
end
def remote_function(options)
javascript_options = options_for_ajax(options)
update = ''
if options[:update] && options[:update].is_a?(Hash)
update = []
update << "success:'#{options[:update][:success]}'" if options[:update][:success]
update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
update = '{' + update.join(',') + '}'
elsif options[:update]
update << "'#{options[:update]}'"
end
function = "#{JQUERY_VAR}.ajax(#{javascript_options})"
function = "#{options[:before]}; #{function}" if options[:before]
function = "#{function}; #{options[:after]}" if options[:after]
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
return function
end
class JavaScriptGenerator
module GeneratorMethods
def insert_html(position, id, *options_for_render)
insertion = position.to_s.downcase
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
end
def replace_html(id, *options_for_render)
insert_html(:html, id, *options_for_render)
end
def replace(id, *options_for_render)
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
end
def remove(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").remove"
end
def show(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").show"
end
def hide(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").hide"
end
def toggle(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").toggle"
end
def jquery_id(id)
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
end
def jquery_ids(ids)
Array(ids).map{|id| jquery_id(id)}.join(',')
end
end
end
protected
def options_for_ajax(options)
js_options = build_callbacks(options)
url_options = options[:url]
url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
js_options['url'] = "'#{url_for(url_options)}'"
js_options['async'] = false if options[:type] == :synchronous
js_options['type'] = options[:method] ? method_option_to_s(options[:method]) : ( options[:form] ? "'post'" : nil )
js_options['dataType'] = options[:datatype] ? "'#{options[:datatype]}'" : (options[:update] ? nil : "'script'")
if options[:form]
js_options['data'] = "#{JQUERY_VAR}.param(#{JQUERY_VAR}(this).serializeArray())"
elsif options[:submit]
js_options['data'] = "#{JQUERY_VAR}(\"##{options[:submit]} :input\").serialize()"
elsif options[:with]
js_options['data'] = options[:with].gsub("Form.serialize(this.form)","#{JQUERY_VAR}.param(#{JQUERY_VAR}(this.form).serializeArray())")
end
js_options['type'] ||= "'post'"
if options[:method]
if method_option_to_s(options[:method]) == "'put'" || method_option_to_s(options[:method]) == "'delete'"
js_options['type'] = "'post'"
if js_options['data']
js_options['data'] << " + '&"
else
js_options['data'] = "'"
end
js_options['data'] << "_method=#{options[:method]}'"
end
end
if respond_to?('protect_against_forgery?') && protect_against_forgery?
if js_options['data']
js_options['data'] << " + '&"
else
js_options['data'] = "'"
end
js_options['data'] << "#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')"
end
js_options['data'] = "''" if js_options['type'] == "'post'" && js_options['data'].nil?
options_for_javascript(js_options.reject {|key, value| value.nil?})
end
def build_update_for_success(html_id, insertion=nil)
insertion = build_insertion(insertion)
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request);"
end
def build_update_for_error(html_id, insertion=nil)
insertion = build_insertion(insertion)
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request.responseText);"
end
def build_insertion(insertion)
insertion = insertion ? insertion.to_s.downcase : 'html'
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
insertion
end
def build_observer(klass, name, options = {})
if options[:with] && (options[:with] !~ /[\{=(.]/)
options[:with] = "'#{options[:with]}=' + value"
else
options[:with] ||= 'value' unless options[:function]
end
callback = options[:function] || remote_function(options)
javascript = "#{JQUERY_VAR}('#{jquery_id(name)}').delayedObserver("
javascript << "#{options[:frequency] || 0}, "
javascript << "function(element, value) {"
javascript << "#{callback}}"
#javascript << ", '#{options[:on]}'" if options[:on]
javascript << ")"
javascript_tag(javascript)
end
def build_callbacks(options)
callbacks = {}
options[:beforeSend] = '';
[:uninitialized,:loading,:loaded].each do |key|
options[:beforeSend] << (options[key].last == ';' ? options.delete(key) : options.delete(key) << ';') if options[key]
end
options.delete(:beforeSend) if options[:beforeSend].blank?
options[:error] = options.delete(:failure) if options[:failure]
if options[:update]
if options[:update].is_a?(Hash)
options[:update][:error] = options[:update].delete(:failure) if options[:update][:failure]
if options[:update][:success]
options[:success] = build_update_for_success(options[:update][:success], options[:position]) << (options[:success] ? options[:success] : '')
end
if options[:update][:error]
options[:error] = build_update_for_error(options[:update][:error], options[:position]) << (options[:error] ? options[:error] : '')
end
else
options[:success] = build_update_for_success(options[:update], options[:position]) << (options[:success] ? options[:success] : '')
end
end
options.each do |callback, code|
if JQCALLBACKS.include?(callback)
callbacks[callback] = "function(request){#{code}}"
end
end
callbacks
end
end
class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
def initialize(generator, id)
id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
@id = id
super(generator, "#{JQUERY_VAR}(\"#{id}\")")
end
def replace_html(*options_for_render)
call 'html', @generator.send(:render, *options_for_render)
end
def replace(*options_for_render)
call 'replaceWith', @generator.send(:render, *options_for_render)
end
def reload(options_for_replace={})
replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
end
def value()
call 'val()'
end
def value=(value)
call 'val', value
end
end
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
def initialize(generator, pattern)
super(generator, "#{JQUERY_VAR}(#{pattern.to_json})")
end
end
module ScriptaculousHelper
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
unless const_defined? :SCRIPTACULOUS_EFFECTS
SCRIPTACULOUS_EFFECTS = {
:appear => {:method => 'fadeIn'},
:blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
:blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
:blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
:blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
:bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
:bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
:drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
:drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
:fade => {:method => 'fadeOut'},
:fold_in => {:method => 'fold', :mode => 'hide'},
:fold_out => {:method => 'fold', :mode => 'show'},
:grow => {:method => 'scale', :mode => 'show'},
:shrink => {:method => 'scale', :mode => 'hide'},
:slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
:slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
:slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
:slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
:squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
:switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
:switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
:toggle_appear => {:method => 'fadeToggle'},
:toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
:toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
}
end
def visual_effect(name, element_id = false, js_options = {})
element = element_id ? element_id : "this"
if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
name = effect[:method]
mode = effect[:mode]
js_options = js_options.merge(effect[:options]) if effect[:options]
end
[:color, :direction].each do |option|
js_options[option] = "'#{js_options[option]}'" if js_options[option]
end
if js_options.has_key? :duration
speed = js_options.delete :duration
speed = (speed * 1000).to_i unless speed.nil?
else
speed = js_options.delete :speed
end
if ['fadeIn','fadeOut','fadeToggle'].include?(name)
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{name}("
javascript << "#{speed}" unless speed.nil?
javascript << ");"
else
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{mode || 'effect'}('#{name}'"
javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
javascript << ",#{speed}" unless speed.nil?
javascript << ");"
end
end
def sortable_element_js(element_id, options = {}) #:nodoc:
#convert similar attributes
options[:handle] = ".#{options[:handle]}" if options[:handle]
if options[:tag] || options[:only]
options[:items] = "> "
options[:items] << options.delete(:tag) if options[:tag]
options[:items] << ".#{options.delete(:only)}" if options[:only]
end
options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
options[:containment] = options.delete(:container) if options[:container]
options[:dropOnEmpty] = false unless options[:dropOnEmpty]
options[:helper] = "'clone'" if options[:ghosting] == true
options[:axis] = case options.delete(:constraint)
when "vertical"
"y"
when "horizontal"
"x"
when false
nil
when nil
"y"
end
options.delete(:axis) if options[:axis].nil?
options.delete(:overlap)
options.delete(:ghosting)
if options[:onUpdate] || options[:url]
options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
end
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
options[:update] = options.delete(:onUpdate) if options[:onUpdate]
[:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
options[option] = "'#{options[option]}'" if options[option]
end
options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
%(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});)
end
def draggable_element_js(element_id, options = {})
%(#{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)});)
end
def drop_receiving_element_js(element_id, options = {})
#convert similar options
options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
options[:drop] = options.delete(:onDrop) if options[:onDrop]
if options[:drop] || options[:url]
options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
end
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
[:activeClass, :hoverClass, :tolerance].each do |option|
options[option] = "'#{options[option]}'" if options[option]
end
%(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
end
end
end
end

19
vendor/plugins/jrails/tasks/jrails.rake vendored Normal file
View File

@ -0,0 +1,19 @@
namespace :jrails do
namespace :update do
desc "Copies the jQuery and jRails javascripts to public/javascripts"
task :javascripts do
puts "Copying files..."
project_dir = RAILS_ROOT + '/public/javascripts/'
scripts = Dir[File.join(File.dirname(__FILE__), '..') + '/javascripts/*.js']
FileUtils.cp(scripts, project_dir)
puts "files copied successfully."
end
end
namespace :install do
desc "Installs the jQuery and jRails javascripts to public/javascripts"
task :javascripts do
Rake::Task['jrails:update:javascripts'].invoke
end
end
end