Skip to content

Commit

Permalink
final version of v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Holek committed Feb 16, 2011
1 parent e460ae7 commit ccb071b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
21 changes: 16 additions & 5 deletions README.md
Expand Up @@ -4,7 +4,7 @@ This gem will add an easy-to-use Facebook Share button feature to your Rails pro

Any public method will return just JavaScript code and nothing else.

## How To Install
## How to install

This gem relies on jQuery, be sure to have it installed in your project. It does not depend on jquery-rails gem, because some projects use jQuery without it.

Expand Down Expand Up @@ -35,16 +35,27 @@ You can ommit *app_id* parameter, if you already have a Facebook Application ini
Be sure you have <div id="fb-root"></div> in your application layout before you load the Facebook Connect JS

Default facebook Share options can be changed with the above code snippet
* *appid* - your Facebook application ID that will connect your site to Facebook.
* *status*. *cookie* and *xfbml* - as described at [FB.init JS SDK](http://developers.facebook.com/docs/reference/javascript/fb.init/)

* *appid* - your Facebook application ID that will connect your site to Facebook
* *status*. *cookie* and *xfbml* - as described at [FB.init JS SDK](http://developers.facebook.com/docs/reference/javascript/fb.init/)
* *locale* - Facebook locale code representations, ie. en_US, de_DE, pl_PL, etc. The full list of Facebook supported languages is available in http://www.facebook.com/translations/FacebookLocales.xml or at [Facebook Developer Wiki](http://fbdevwiki.com/wiki/Locales)

* *selector* - a selector to target Facebook share binding, ".fb_share" by default
* any other parameter will be passed to Facebook's **[FB.ui](http://developers.facebook.com/docs/reference/javascript/fb.ui/)** function, so you can use whichever parameters you need, except for *method*, which defaults always to *publish.stream*

## Usage

The simplest usage (given you specified your project's Facebook Application ID) is as follows:

<%= link_to 'Share on Facebook', '#', :class => "fb_share" %>
<%= facebook_share_once %>

That will produce a link "Share on Facebook" with a class of "fb_share" and a corresponding JavaScript script tags initializing Facebook app and sharing method bind to click on that link. By default gem passes ".fb_share" selector to jQuery.

## Todo

* add tests

## Note on Patches/Pull Requests
## Note on patches/pull requests

* Fork the project.
* Create a feature branch
Expand Down
8 changes: 4 additions & 4 deletions lib/facebook_share.rb
Expand Up @@ -10,7 +10,7 @@ def default_facebook_share_options
{
:app_id => "0",
:selector => ".fb_share",
:url => request.url,
:link => request.url,
:locale => "en_US",
:display => "popup"
}.merge(FacebookShare.default_facebook_share_options || {})
Expand All @@ -23,7 +23,7 @@ def facebook_share_once(options = {})
def facebook_share(options = {})
options = default_facebook_share_options.merge(options)
script = <<-JS
$("#{selector}").unbind("click.facebook_share").bind("click.facebook_share",function () {
$("#{options[:selector]}").unbind("click.facebook_share").bind("click.facebook_share",function () {
FB.ui({method: \'stream.publish\'#{build_params(options)}});
return false;
});
Expand Down Expand Up @@ -61,7 +61,7 @@ def build_params(options, for_init = false)
options.each do |key, value|
# if it's for init script, include only status, cookie and xfbml
# if it's for stream.publish, include all except for initial
param_check = ( for_init ) ? INIT_PARAMS.include?(key) : !(REMOVE_PARAMS.include?(key))
param_check = ( for_init ) ? FacebookShare::INIT_PARAMS.include?(key.to_s) : !(FacebookShare::REMOVE_PARAMS.include?(key.to_s))

if value && param_check
value_sanitized = value.gsub(/"/, '\"')
Expand All @@ -75,4 +75,4 @@ def html_safe_string(str)
@use_html_safe ||= "".respond_to?(:html_safe)
@use_html_safe ? str.html_safe : str
end
end
end

0 comments on commit ccb071b

Please sign in to comment.