Module: ActionView::Helpers::PrototypeHelper

Defined in:
lib/jquery/jquery.rb

Defined Under Namespace

Classes: JavaScriptGenerator

Constant Summary collapse

USE_PROTECTION =
const_defined?(:DISABLE_JQUERY_FORGERY_PROTECTION) ? !DISABLE_JQUERY_FORGERY_PROTECTION : true
JQUERY_VAR =
'jQuery'
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)

Instance Method Summary collapse

Instance Method Details

#periodically_call_remote(options = {}) ⇒ Object



58
59
60
61
62
# File 'lib/jquery/jquery.rb', line 58

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

#remote_function(options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jquery/jquery.rb', line 64

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