This page last changed on Jan 24, 2012 by jed.wheeler@involver.com.

share

Renders a Facebook share dialog on your platform of choice.

Params

name type description
message string Pre-filled user message text (To be deprecated July 12th, 2011, see http://developers.facebook.com/blog/post/510/)
user_message_prompt string Call to Action
attachment associative array Share body data, including image or SWF media (For details on how to construct this variable, see http://developers.facebook.com/docs/guides/attachments/)
action_links array Array of text/href pairs
target_id int ID of Facebook Page or User whose wall will receive the post (optional)
actor_id int ID of Facebook Page. Allows admin to publish on Page's behalf (optional, cannot be used with target_id)
auto_publish boolean Indicates whether to automatically publish to the user's stream without displaying a Feed form to the user.
success function Callback on success of share post. Passes post_id to function
error function Callback on error or cancel of share post

Security Issues

Facebook does not currently support secure urls for images embedded within shares. Because the SML editable_image tag dynamically serves the image in http or https, depending on the user's current browsing mode, images inserted into a facebook share from an editable image directly will break in https mode. In order to prevent this, you can encode the editable as a variable and then use the replace filter to replace any calls for https: with a call for http:, as per the example below:

Examples

Render a share dialog with an image:

{% capture share_image %}{% editable_image name:"your editable_image logo" src_only:true %}{% endcapture %}

<script type="text/javascript">
function share() {
  sml.ui.Facebook.share({
    user_message_prompt: "What is on your mind?",
    attachment: {
      name: 'Share Name',
      caption: 'Share Caption',
      href: '{{ application_url }}',
      description: 'Share Description',
      media: [{
        type: 'image',
        src: '{{share_image | replace:"https:", "http:"}}',
        href: '{{ application_url }}'
      }]
    },
    action_links: [{
      text: 'Visit My Page',
      href: '{{ application_url }}'
    }],
    success: function(post_id) {
      sml.log("Success!");
    },
    error: function() {
      sml.log("Error! ");
    }
  });
}
</script>

<a href="#_" onclick="share(); return false;">Share Me</a>

Render a share dialog with a YouTube video :

<script type="text/javascript">
function share(options) {
  sml.ui.Facebook.share({
    message: 'I like sharing!',
    user_message_prompt: "What is on your mind?",
    attachment: {
      name: 'Share Name',
      caption: options.caption,
      href: '{{ application_url }}',
      description: 'Share Description',
      media: [{
        type: 'flash',
        swfsrc: options.swfsrc,
        imgsrc: options.imgsrc,
        href: 'http://www.facebook.com/Involver'
      }]
    },
    action_links: [{
      text: 'Visit My Page',
      href: '{{ application_url }}'
    }],
    success: function(post_id) {
      sml.log("Success!");
    },
    error: function() {
      sml.log("Error! ");
    }
  });
}
</script>

{% you_tube_feed %}
    {% for you_tube_item in you_tube_feed.you_tube_items limit: 1 %}
        <a href="#_" onclick="share({caption:'{{you_tube_item.title}}', swfsrc: '{{you_tube_item.embed_url}}', imgsrc:'{{you_tube_item.preview_image_url}}'}); return false;">Share Me</a>
    {% endfor %}
{% endyou_tube_feed %}
Document generated by Confluence on Feb 12, 2013 09:09