Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit ebbf7830ec039b71a13f4e7e4c3d5aaa70e8fcc0 1 parent 8bb6b57
aaronchi authored
2  javascripts/jrails.js
View
@@ -1,3 +1,3 @@
(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({Appear:function(speed,callback){return this.fadeIn(speed,callback);},BlindDown:function(speed,callback){this.show({method:'blind',direction:'vertical'},speed,callback);return this;},BlindUp:function(speed,callback){this.hide({method:'blind',direction:'vertical'},speed,callback);return this;},BlindRight:function(speed,callback){this.show({method:'blind',direction:'horizontal'},speed,callback);return this;},BlindLeft:function(speed,callback){this.hide({method:'blind',direction:'horizontal'},speed,callback);return this;},DropOut:function(speed,callback){this.hide({method:'drop',direction:'down'},speed,callback);return this;},DropIn:function(speed,callback){this.show({method:'drop',direction:'up'},speed,callback);return this;},Fade:function(speed,callback){return this.fadeOut(speed,callback);},Fold:function(speed,callback){this.hide({method:'fold'},speed,callback);return this;},FoldOut:function(speed,callback){this.show({method:'fold'},speed,callback);return this;},Grow:function(speed,callback){this.show({method:'scale'},speed,callback);return this;},Highlight:function(speed,callback){this.show({method:'highlight'},speed,callback);return this;},Puff:function(speed,callback){this.hide({method:'puff'},speed,callback);return this;},Pulsate:function(speed,callback){this.show({method:'pulsate'},speed,callback);return this;},Shake:function(speed,callback){this.show({method:'shake'},speed,callback);return this;},Shrink:function(speed,callback){this.hide({method:'scale'},speed,callback);return this;},Squish:function(speed,callback){this.hide({method:'scale',origin:['top','left']},speed,callback);return this;},SlideUp:function(speed,callback){this.hide({method:'slide',direction:'up'},speed,callback);return this;},SlideDown:function(speed,callback){this.show({method:'slide',direction:'up'},speed,callback);return this;},SwitchOff:function(speed,callback){this.hide({method:'clip'},speed,callback);return this;},SwitchOn:function(speed,callback){this.show({method:'clip'},speed,callback);return this;}});})(jQuery);(function($){$.fn.extend({pause:function(milli,type){milli=milli||1000;type=type||"fx";return this.queue(type,function(){var self=this;setTimeout(function(){$(self).dequeue();},milli);});},clearQueue:function(type){return this.each(function(){type=type||"fx";if(this.queue&&this.queue[type]){this.queue[type].length=0;}});},unpause:$.fn.clearQueue});})(jQuery);
+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){return this.effect(o);},Appear:function(speed,callback){return this.fadeIn(speed,callback);},BlindDown:function(speed,callback){this.show({method:'blind',direction:'vertical'},speed,callback);return this;},BlindUp:function(speed,callback){this.hide({method:'blind',direction:'vertical'},speed,callback);return this;},BlindRight:function(speed,callback){this.show({method:'blind',direction:'horizontal'},speed,callback);return this;},BlindLeft:function(speed,callback){this.hide({method:'blind',direction:'horizontal'},speed,callback);return this;},DropOut:function(speed,callback){this.hide({method:'drop',direction:'down'},speed,callback);return this;},DropIn:function(speed,callback){this.show({method:'drop',direction:'up'},speed,callback);return this;},Fade:function(speed,callback){return this.fadeOut(speed,callback);},Fold:function(speed,callback){this.hide({method:'fold'},speed,callback);return this;},FoldOut:function(speed,callback){this.show({method:'fold'},speed,callback);return this;},Grow:function(speed,callback){this.show({method:'scale'},speed,callback);return this;},Highlight:function(speed,callback){this.show({method:'highlight'},speed,callback);return this;},Puff:function(speed,callback){this.hide({method:'puff'},speed,callback);return this;},Pulsate:function(speed,callback){this.show({method:'pulsate'},speed,callback);return this;},Shake:function(speed,callback){this.show({method:'shake'},speed,callback);return this;},Shrink:function(speed,callback){this.hide({method:'scale'},speed,callback);return this;},Squish:function(speed,callback){this.hide({method:'scale',origin:['top','left']},speed,callback);return this;},SlideUp:function(speed,callback){this.hide({method:'slide',direction:'up'},speed,callback);return this;},SlideDown:function(speed,callback){this.show({method:'slide',direction:'up'},speed,callback);return this;},SwitchOff:function(speed,callback){this.hide({method:'clip'},speed,callback);return this;},SwitchOn:function(speed,callback){this.show({method:'clip'},speed,callback);return this;}});})(jQuery);(function($){$.fn.extend({pause:function(milli,type){milli=milli||1000;type=type||"fx";return this.queue(type,function(){var self=this;setTimeout(function(){$(self).dequeue();},milli);});},clearQueue:function(type){return this.each(function(){type=type||"fx";if(this.queue&&this.queue[type]){this.queue[type].length=0;}});},unpause:$.fn.clearQueue});})(jQuery);
3  javascripts/sources/jrails.js
View
@@ -71,6 +71,9 @@
(function($) {
$.fn.extend({
+ visualEffect : function(o) {
+ return this.effect(o);
+ },
Appear : function(speed, callback) {
return this.fadeIn(speed, callback);
},
51 lib/jrails.rb
View
@@ -33,15 +33,11 @@ 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)
@@ -49,23 +45,23 @@ def replace_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
Please sign in to comment.
Something went wrong with that request. Please try again.