Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created September 10, 2010 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefrichter/573569 to your computer and use it in GitHub Desktop.
Save josefrichter/573569 to your computer and use it in GitHub Desktop.
module Facebooker2
module Rails
module Helpers
module Javascript
def fb_html_safe(str)
if str.respond_to?(:html_safe)
str.html_safe
else
str
end
end
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
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '#{app_id}',
status : #{status}, // check login status
cookie : #{cookie}, // enable cookies to allow the server to access the session
xfbml : #{xfbml} // parse XFBML
});
#{extra_js}
};
(function() {
var s = document.createElement('div');
s.setAttribute('id','fb-root');
document.documentElement.getElementsByTagName("body")[0].appendChild(s);
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
s.appendChild(e);
}());
</script>
JAVASCRIPT
js = js.html_safe if js.respond_to? :html_safe; js
block_given? ? concat(js) : js
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment