rails_responds_to_parent 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2006 Sean Treadway
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
# Module containing the methods useful for child IFRAME to parent window communication
|
24
|
+
module RailsRespondsToParent
|
25
|
+
|
26
|
+
# Executes the response body as JavaScript in the context of the parent window.
|
27
|
+
# Use this method of you are posting a form to a hidden IFRAME or if you would like
|
28
|
+
# to use IFRAME base RPC.
|
29
|
+
def responds_to_parent(&block)
|
30
|
+
yield
|
31
|
+
|
32
|
+
if performed?
|
33
|
+
# We're returning HTML instead of JS or XML now
|
34
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
35
|
+
|
36
|
+
# Either pull out a redirect or the request body
|
37
|
+
script = if location = response.headers['Location']
|
38
|
+
#TODO: erase_redirect_results is missing in rails 3.0 has to be implemented
|
39
|
+
# erase redirect
|
40
|
+
"document.location.href = #{location.to_s.inspect}"
|
41
|
+
else
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
|
45
|
+
# Escape quotes, linebreaks and slashes, maintaining previously escaped slashes
|
46
|
+
# Suggestions for improvement?
|
47
|
+
script = (script || '').
|
48
|
+
gsub('\\', '\\\\\\').
|
49
|
+
gsub(/\r\n|\r|\n/, '\\n').
|
50
|
+
gsub(/['"]/, '\\\\\&').
|
51
|
+
gsub('</script>','</scr"+"ipt>')
|
52
|
+
|
53
|
+
if(Rails::VERSION::MAJOR == 3)
|
54
|
+
# Clear out the previous render to prevent double render
|
55
|
+
response.request.env['action_controller.instance'].instance_variable_set(:@_response_body, nil)
|
56
|
+
else
|
57
|
+
erase_results
|
58
|
+
end
|
59
|
+
|
60
|
+
# Eval in parent scope and replace document location of this frame
|
61
|
+
# so back button doesn't replay action on targeted forms
|
62
|
+
# loc = document.location to be set after parent is updated for IE
|
63
|
+
# with(window.parent) - pull in variables from parent window
|
64
|
+
# setTimeout - scope the execution in the windows parent for safari
|
65
|
+
# window.eval - legal eval for Opera
|
66
|
+
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
67
|
+
var loc = document.location;
|
68
|
+
with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };
|
69
|
+
</script></body></html>".html_safe
|
70
|
+
end
|
71
|
+
end
|
72
|
+
alias respond_to_parent responds_to_parent
|
73
|
+
end
|
74
|
+
|
75
|
+
ActionController::Base.send :include, RailsRespondsToParent
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_responds_to_parent'
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_responds_to_parent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Roberts
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-07 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Responds to parent plugin for Rails 2 and 3
|
23
|
+
email: chrisroberts.code@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/rails_responds_to_parent/rails_responds_to_parent.rb
|
32
|
+
- lib/rails_responds_to_parent/version.rb
|
33
|
+
- lib/rails_responds_to_parent.rb
|
34
|
+
- rails/init.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/chrisroberts/rails_responds_to_parent
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.6.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Responds to parent plugin for Rails 2 and 3
|
69
|
+
test_files: []
|
70
|
+
|