Module: JQueryOnRails::Helpers::JQueryHelper
- Defined in:
- lib/jquery_on_rails/helpers/jquery_helper.rb
Defined Under Namespace
Classes: JavaScriptGenerator
Constant Summary collapse
- CALLBACKS =
{ :beforeSend=>'request', :complete=>'request,status', :error=>'request,status,exception', :success=>'data,status,request' }
- INSERT_POSITIONS =
{ :before=>'before', :after=>'after', :top=>'prepend', :bottom=>'append' }
- AJAX_OPTIONS =
Set.new([:cache, :contentType, :data, :dataType, :dataFilter, :global, :ifModified, :jsonp, :jsonpCallback, :password, :processData, :scriptCharset, :timeout, :traditional, :type, :username, :xhr])
- CONFIRM_FUNCTION =
'confirm'.freeze
- TOGGLE_EFFECTS =
Set.new([:toggle_appear, :toggle_slide, :toggle_blind])
- RENAME_EFFECTS =
{ :appear=>'fadeIn', :fade=>'fadeOut' }
Instance Method Summary collapse
-
#remote_function(options) ⇒ Object
Returns the JavaScript needed for a remote function.
- #update_page(&block) ⇒ Object
- #update_page_tag(html_options = {}, &block) ⇒ Object
-
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Basic effects, limited to those supported by core jQuery 1.4 Additional effects are supported by jQuery UI.
Instance Method Details
#remote_function(options) ⇒ Object
Returns the JavaScript needed for a remote function. Takes the same arguments as link_to_remote.
Example:
# Generates: <select id="options" onchange="jQuery.ajax({method : 'GET',
# url : '/testing/update_options', processData:false, async:true, evalScripts:true,
# complete : function(data,status,request){$('#options').html(request.responseText)}})">
<select id="options" onchange="<%= remote_function(:update => "options",
:url => { :action => :update_options }) %>">
<option value="0">Hello</option>
<option value="1">World</option>
</select>
51 52 53 54 55 56 57 58 |
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 51 def remote_function() function = "jQuery.ajax(#{()})" function = "#{[:before]}; #{function}" if [:before] function = "#{function}; #{[:after]}" if [:after] function = "if (#{[:condition]}) { #{function}; }" if [:condition] function = "if (#{confirm_for_javascript([:confirm])}) { #{function}; }" if [:confirm] function end |
#update_page(&block) ⇒ Object
251 252 253 |
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 251 def update_page(&block) JavaScriptGenerator.new(view_context, &block).to_s.html_safe end |
#update_page_tag(html_options = {}, &block) ⇒ Object
255 256 257 |
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 255 def update_page_tag( = {}, &block) javascript_tag update_page(&block), end |
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Basic effects, limited to those supported by core jQuery 1.4 Additional effects are supported by jQuery UI.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 62 def visual_effect(name, element_id = false, = {}) element = element_id ? ActiveSupport::JSON.encode("##{element_id}") : "element" element = "jQuery(#{element})" = ( unless .empty?) case name = name.to_sym when :toggle_slide "#{element}.slideToggle(#{});" when :toggle_appear "(function(state){ return (function() { state=!state; return #{element}['fade'+(state?'In':'Out')](#{}); })(); })(#{element}.css('visiblity')!='hidden');" else "#{element}.#{RENAME_EFFECTS[name] || name.to_s.camelize(false)}(#{});" end end |