Permalink
Browse files

refactored common attribute values and added FB logout event handlers

  • Loading branch information...
1 parent c7ad0bb commit 83b0f5feb78c373aa33bdf8ee76f57e4575c4b73 @kristianmandrup committed Apr 3, 2012
View
@@ -114,6 +114,9 @@ Open graph <meta> tag helpers
* fb_analytics(app_id) # Facebook analytics meta tag
* fb_activity(namespace, action) # Open Graph action to perform
+* fb_logout(script) # setup FB event handler to trigger on FB logout
+* fb_logout_and_redirect_to(path) # setup FB event handler to trigger on FB logout and redirect
+
== Social plugins
Currently the following Social plugins are included in this gem
@@ -5,7 +5,7 @@
module FacebookSocialPlugins
def self.plugins
- ['activity_feed', 'add_to_timeline', 'comments', 'facepile', 'like_box', 'like_button',
+ ['activity_feed', 'add_to_timeline', 'comments', 'facepile', 'like_box', 'like_button',
'live_stream', 'login_button', 'recommendations_box', 'registration', 'send_button', 'subscribe_button']
end
@@ -26,8 +26,8 @@ def plugin_class
def attributes
super.merge(
:site => :string, :action => :array, :app_id => :string, :width => :integer, :height => :integer,
- :header => :boolean, :colorscheme => ['light', 'dark'], :font => ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'],
- :border_color => :string, :recommendations => :boolean, :filter => :string, :linktarget => ['_top', '_parent'],
+ :header => :boolean, :colorscheme => colorschemes, :font => fonts,
+ :border_color => :string, :recommendations => :boolean, :filter => :string, :linktarget => linktargets,
:ref => :string, :max_age => :integer, :width => :integer
)
end
@@ -11,4 +11,3 @@ def render
end
end
end
-
@@ -12,7 +12,7 @@ def plugin_class
# attributes always availabe for a button?
def attributes
- super.merge(:font => ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'], :colorscheme => ['light', 'dark'])
+ super.merge(:font => fonts, :colorscheme => colorschemes)
end
end
end
@@ -30,7 +30,7 @@ def plugin_class
# max_rows - max rows to display, 1-10 normally
def attributes
super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
- :max_rows => :integer, :size => ['small', 'large'], :width => :integer
+ :max_rows => :integer, :size => sizes, :width => :integer
)
end
end
@@ -24,7 +24,7 @@ def plugin_class
# fb_source - the stream type ('home', 'profile', 'search', 'ticker', 'tickerdialog' or 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.
def attributes
super.merge(
- :href => :string, :send => :boolean, :layout => ['standard', 'button_count', 'box_count'],
+ :href => :string, :send => :boolean, :layout => layouts,
:show_faces => :boolean, :action => ['like', 'recommend'], :ref => :string,
:fb_ref => :string, :fb_source => :special, :width => :integer
)
@@ -34,7 +34,7 @@ def plugin_class
# Otherwise the valid values are 1-180, which specifies the number of days.
def attributes
super.merge(:site => :string, :action => :string, :app_id => :string, :height => :integer,
- :header => :string, :linktarget => ['_top', '_parent'], :ref => :string,
+ :header => :string, :linktarget => linktargets, :ref => :string,
:max_age => :integer, :width => :integer)
end
end
@@ -27,10 +27,14 @@ def plugin_class
# target Optional. The target of the form submission: _top (default), _parent, or _self.
def attributes
super.merge(:client_id => :string, :redirect_uri => :string, :fields => :string,
- :fb_only => :boolean, :fb_register => :boolean, :border_color => :string, :target => ['_top', '_parent', '_self']
+ :fb_only => :boolean, :fb_register => :boolean, :border_color => :string, :target => targets
)
end
+ def targets
+ ['_top', '_parent', '_self']
+ end
+
# Named Fields
# Specify these in the order you want them to appear in the form. The name field must always be the first field.
@@ -29,6 +29,26 @@ def validate!
protected
+ def layouts
+ ['standard', 'button_count', 'box_count']
+ end
+
+ def sizes
+ ['small', 'large']
+ end
+
+ def fonts
+ ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana']
+ end
+
+ def colorschemes
+ ['light', 'dark']
+ end
+
+ def linktargets
+ ['_top', '_parent']
+ end
+
def find_att_key key
return key if attributes[key]
key = key.to_s.dasherize.to_sym
@@ -18,7 +18,7 @@ def plugin_class
# font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
# width - the width of the plugin.
def attributes
- super.merge(:href => :string, :layout => ['standard', 'button_count', 'box_count'],
+ super.merge(:href => :string, :layout => layouts,
:show_faces => :boolean, :width => :integer)
end
end
@@ -44,6 +44,14 @@ def fb_login_button options = {}
FacebookSocialPlugins::LoginButton.new(options).render
end
+ def fb_logout &block
+ content_tag :script, %Q{FB.Event.subscribe("auth.logout", function() { #{yield} });}
+ end
+
+ def fb_logout_and_redirect_to path
+ content_tag :script, %Q{FB.Event.subscribe("auth.logout", function() {window.location = #{path} });}
+ end
+
def fb_recommendations_box options = {}
FacebookSocialPlugins::RecommendationsBox.new(options).render
end

0 comments on commit 83b0f5f

Please sign in to comment.