Permalink
Browse files

better support for rjs

git-svn-id: https://ennerchi.googlecode.com/svn/trunk/plugins/jrails@19 1bc9508b-f83e-0410-b78e-05f979d4f8d9
  • Loading branch information...
1 parent 8bb6b57 commit ebbf7830ec039b71a13f4e7e4c3d5aaa70e8fcc0 aaronchi committed Dec 14, 2007
Showing with 38 additions and 18 deletions.
  1. +1 −1 javascripts/jrails.js
  2. +3 −0 javascripts/sources/jrails.js
  3. +34 −17 lib/jrails.rb
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -71,6 +71,9 @@
(function($) {
$.fn.extend({
+ visualEffect : function(o) {
+ return this.effect(o);
+ },
Appear : function(speed, callback) {
return this.fadeIn(speed, callback);
},
View
@@ -33,39 +33,35 @@ def remote_function(options)
class JavaScriptGenerator
module GeneratorMethods
- def select(pattern)
- record "$('#{pattern}')"
- end
-
def insert_html(position, id, *options_for_render)
insertion = position.to_s.downcase
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
- call "$('##{id}').#{insertion}", render(*options_for_render)
+ call "$(\"##{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 "$('##{id}').replaceWith", render(*options_for_render)
+ call "$(\"##{id}\").replaceWith", render(*options_for_render)
end
def remove(*ids)
- call "$('##{ids.join(',#')}').remove"
+ call "$(\"##{ids.join(',#')}\").remove"
end
def show(*ids)
- call "$('##{ids.join(',#')}').show"
+ call "$(\"##{ids.join(',#')}\").show"
end
def hide(*ids)
- call "$('##{ids.join(',#')}').hide"
+ call "$(\"##{ids.join(',#')}\").hide"
end
def toggle(*ids)
- call "$('##{ids.join(',#')}').toggle"
+ call "$(\"##{ids.join(',#')}\").toggle"
end
end
@@ -85,7 +81,7 @@ def options_for_ajax(options)
if options[:form]
js_options['data'] = "$.param($(this).serializeArray())"
elsif options[:submit]
- js_options['data'] = "$('##{options[:submit]}').serializeArray()"
+ js_options['data'] = "$(\"##{options[:submit]}\").serializeArray()"
elsif options[:with]
js_options['data'] = options[:with].gsub('Form.serialize(this.form)','$.param($(this.form).serializeArray())')
end
@@ -107,7 +103,7 @@ def build_update(options)
insertion = options[:position].to_s.downcase if options[:position]
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
- "$('##{options[:update]}').#{insertion}(request.responseText);"
+ "$(\"##{options[:update]}\").#{insertion}(request.responseText);"
end
def build_observer(klass, name, options = {})
@@ -118,7 +114,7 @@ def build_observer(klass, name, options = {})
end
callback = options[:function] || remote_function(options)
- javascript = "$('##{name}').delayedObserver("
+ javascript = "$(\"##{name}\").delayedObserver("
javascript << "#{options[:frequency] || 0}, "
javascript << "function(element, value) {"
javascript << "#{callback}}"
@@ -142,6 +138,27 @@ def build_callbacks(options)
end
+ class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
+ def initialize(generator, id)
+ @id = id
+ super(generator, "$(\"##{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
+ end
+
+ class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
+ def initialize(generator, pattern)
+ super(generator, "$(#{pattern.to_json})")
+ end
+ end
+
module ScriptaculousHelper
unless const_defined? :TOGGLE_EFFECTS
@@ -196,7 +213,7 @@ def visual_effect(name, element_id = false, js_options = {})
#if TOGGLE_EFFECTS.include? name.to_sym
# "Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{options_for_javascript(js_options)});"
- javascript = "$('##{element_id}').effect('#{name.to_s.downcase}'"
+ javascript = "$(\"##{element_id}\").effect(\"#{name.to_s.downcase}\""
javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
javascript << ",#{speed}" unless speed.nil?
javascript << ")"
@@ -222,11 +239,11 @@ def sortable_element_js(element_id, options = {})
options.delete_if { |key, value| [:only, :tag, :overlap, :hoverclass].include?(key) }
- "$('##{element_id}').sortable(#{options_for_javascript(options) unless options.empty? });"
+ "$(\"##{element_id}\").sortable(#{options_for_javascript(options) unless options.empty? });"
end
def draggable_element_js(element_id, options = {})
- "$('##{element_id}').draggable(#{options_for_javascript(options) unless options.empty? });"
+ "$(\"##{element_id}\").draggable(#{options_for_javascript(options) unless options.empty? });"
end
def drop_receiving_element_js(element_id, options = {})
@@ -243,7 +260,7 @@ def drop_receiving_element_js(element_id, options = {})
options.delete_if { |key, value| [:hoverclass].include?(key) }
- "$('##{element_id}').droppable(#{options_for_javascript(options) unless options.empty? });"
+ "$(\"##{element_id}\").droppable(#{options_for_javascript(options) unless options.empty? });"
end
end

0 comments on commit ebbf783

Please sign in to comment.