Insert the fb-root dynamically
This commit is contained in:
parent
6b721aaca9
commit
52491b2446
@ -1,6 +1,6 @@
|
||||
spec = Gem::Specification.new do |s|
|
||||
s.name = 'facebooker2'
|
||||
s.version = '0.0.3'
|
||||
s.version = '0.0.4'
|
||||
s.summary = "Facebook Connect integration library for ruby and rails"
|
||||
s.description = "Facebook Connect integration library for ruby and rails"
|
||||
s.files = Dir['lib/**/*.rb']
|
||||
|
@ -26,6 +26,12 @@ module Facebooker2
|
||||
content_tag("fb:login-button",text,options.merge(:onlogin=>js))
|
||||
end
|
||||
|
||||
def fb_login(options = {},&proc)
|
||||
js = capture(&proc)
|
||||
text = options.delete(:text)
|
||||
concat(content_tag("fb:login-button",text,options.merge(:onlogin=>js)))
|
||||
end
|
||||
|
||||
#
|
||||
# Logs the user out of facebook and redirects to the given URL
|
||||
# args are passed to the call to link_to_function
|
||||
|
@ -2,13 +2,13 @@ module Facebooker2
|
||||
module Rails
|
||||
module Helpers
|
||||
module Javascript
|
||||
def fb_connect_async_js(app_id=Facebooker2.app_id,options={})
|
||||
def fb_connect_async_js(app_id=Facebooker2.app_id,options={},&proc)
|
||||
opts = Hash.new(true).merge!(options)
|
||||
cookie = opts[:cookie]
|
||||
status = opts[:status]
|
||||
xfbml = opts[:xfbml]
|
||||
extra_js = capture(&proc) if block_given?
|
||||
js = <<-JAVASCRIPT
|
||||
<div id="fb-root"></div>
|
||||
<script>
|
||||
window.fbAsyncInit = function() {
|
||||
FB.init({
|
||||
@ -17,16 +17,21 @@ module Facebooker2
|
||||
cookie : #{cookie}, // enable cookies to allow the server to access the session
|
||||
xfbml : #{xfbml} // parse XFBML
|
||||
});
|
||||
#{extra_js}
|
||||
};
|
||||
|
||||
(function() {
|
||||
ar s = document.createElement('div');
|
||||
s.setAttribute('id','fb-root');
|
||||
document.documentElement.getElementsByTagName("HEAD")[0].appendChild(s);
|
||||
var e = document.createElement('script');
|
||||
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
|
||||
e.async = true;
|
||||
document.getElementById('fb-root').appendChild(e);
|
||||
s.appendChild(e);
|
||||
}());
|
||||
</script>
|
||||
JAVASCRIPT
|
||||
block_given? ? concat(js) : js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user