Sha256: 69716a7f1be80e1433dca41addee28c73f4f9d15c9770d56b712126e2f1ab27c

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

module ActiveScaffold
  # Module containing the methods useful for child IFRAME to parent window communication
  module RespondsToParent
    # Executes the response body as JavaScript in the context of the parent window.
    # Use this method of you are posting a form to a hidden IFRAME or if you would like
    # to use IFRAME base RPC.
    def responds_to_parent(&block)
      yield
      return unless performed?

      # Either pull out a redirect or the request body
      script =  if response.headers['Location']
                  "document.location.href = '#{self.class.helpers.escape_javascript response.headers.delete('Location').to_s}'"
                else
                  response.body || ''
                end
      response.status = 200 if (300...400).include? response.status

      # Eval in parent scope and replace document location of this frame
      # so back button doesn't replay action on targeted forms
      # loc = document.location to be set after parent is updated for IE
      # with(window.parent) - pull in variables from parent window
      # setTimeout - scope the execution in the windows parent for safari
      # window.eval - legal eval for Opera
      script = "<html><body><script type='text/javascript' charset='utf-8'>
        var loc = document.location;
        with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
      </script></body></html>"

      # We're returning HTML instead of JS or XML now
      response.headers['Content-Type'] = 'text/html; charset=UTF-8'

      # Clear out the previous render to prevent double render and then render
      if respond_to?(:erase_results, true)
        erase_results
      else
        instance_variable_set(:@_response_body, nil)
      end

      render :text => script
    end
    alias_method :respond_to_parent, :responds_to_parent
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.42 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.41.1 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.41 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.40 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.39 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.38 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.37 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.36 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.35 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.34 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.33 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.32 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.31 lib/active_scaffold/responds_to_parent.rb
active_scaffold-3.4.30 lib/active_scaffold/responds_to_parent.rb