Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix script

  • Loading branch information...
commit e596e338cd517a2188423cb533bd52a472d123a2 1 parent f485cab
@kristianmandrup authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/facebook-social_plugins/helper/script.rb
View
18 lib/facebook-social_plugins/helper/script.rb
@@ -98,11 +98,15 @@ def fb_onlogin_react options = {}, &block
# options - status, cookie, xfbml (true|false)
# - :channel => 'channel.html'
def fb_async_init_script app_id, domain, options = {}
+ raise ArgumentError, "Not a valid Facebook App ID. It should be a 15 digit number" unless valid_facebook_id?(app_id)
+ raise ArgumentError, "No domain name specified" if domain.blank?
+ channel = options[:channel_url] || 'assets/facebook_channel' if options[:channel] || options[:channel_url]
+ channelAttrib = channel ? "channelUrl : '//#{domain}/#{channel}.html', // Channel File" : ''
%Q{
window.fbAsyncInit = function() {
FB.init({
- appId : '#{app_id}', // App ID
- channelUrl : '//#{domain}/#{options[:channel] || 'assets/facebook_channel'}.html', // Channel File
+ appId : '#{app_id}', // App ID
+ #{channelAttrib}
status : #{options[:status] || true}, // check login status
cookie : #{options[:cookie] || true}, // enable cookies to allow the server to access the session
xfbml : #{options[:xfbml] || true } // parse XFBML
@@ -113,12 +117,18 @@ def fb_async_init_script app_id, domain, options = {}
}
end
+ def valid_facebook_id? id
+ id ~= /\d{15}/
+ end
+
def fb_channel_script locale = :en_US
%Q{
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
- js = d.createElement('script'); js.id = id; js.async = true;
- js.src = "#{all_script locale}";
+ js = d.createElement('script');
+ js.id = id;
+ js.async = true;
+ js.src = '#{all_script(locale)}';
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
}
Please sign in to comment.
Something went wrong with that request. Please try again.