aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/projects/social_api/share/index.html
blob: 844ac9d69393ea5d85d04d36644dce217b61e012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: Share
slug: Mozilla/Projects/Social_API/Share
translation_of: Archive/Social_API/Share
---
<p id="Share">这一篇只是初步草案,可能会被改变。分享从 [TBD: Firefox 23] 开始可用。</p>

<p>A service provider may choose to provide a Share panel that users can use to share content from the current browser tab with their friends.  The Share panel is slightly different from other Social UI in the browser.  The Share panel itself contains a list of providers that support the share functionality.  When a user shares a page, they can choose which provider they want to share with.  Each provider may have differing functionality, such as simply providing a comment box to extensive functionlality allowing for image selection and more.</p>

<p>Share is initiated by the user either through the share button in the toolbar or a context menu.  The user can select an image or text in a page to be shared, or share the page itself.  Links within a page may also be shared without visiting the link.</p>

<p>A provider implementing support for share may choose to use a URL template that is compatible with OExchange, however the browser also sends a DOM event to the page after load containing details of the share.  In some circumstances, such as sharing a link on the page, the browser will not have detailed information.  Using the DOM event allows the provider to display information about the page being shared without needing to fetch it themselves and parse the page for information.  The browser includes certain META tags, including OpenGraph tags in the event data.</p>

<h2 id="A_User_Experience_Flow_for_Share">A User Experience Flow for Share</h2>

<p>SocialAPI content works different than typical web pages.  The are presented as primary UI in the browser, and may be confined in size, live longer than a browser tab, and more.  How your user will interact with your share panel is unique and you will need to take into account how a user should experience your share panel.</p>

<p>[TODO: describe the expected flow here]</p>

<h2 id="OpenGraphData_DOM_Event">OpenGraphData DOM Event</h2>

<p>The share page can listen for the <code>OpenGraphData</code> DOM Event.</p>

<pre>addEventListener("OpenGraphData", function(e) {
  var shareData = JSON.parse(e.detail);
  $("#shared").text(shareData.url);
})
</pre>

<h4 id="Attributes">Attributes</h4>

<p>The event detail can contain the following attributes which are retreived from META tags and other tags within HEAD, such as the TITLE tag:</p>

<ul>
 <li>url: The URL to the page, link, image or video being shared</li>
 <li>medium: The media type being shared</li>
 <li>source: The media url being shared if a video is being shared</li>
 <li>sitename: The site name</li>
 <li>title: The title of the page</li>
 <li>description: The description of the page</li>
 <li>text: The selected text that the user is sharing</li>
 <li>previews: A list of images available as page previews</li>
</ul>

<h2 id="Share_URL_Template">Share URL Template</h2>

<p>While we prefer the use of the DOM event, many sites have existing endpoints that allow users to share to that site.  SocialAPI supports using a URL template to make implementation easy for sites that already have this functionality.  In your manifest, you can define your shareURL in this format:</p>

<pre>"shareURL": "https://yoursite.com/share?u=%{url}&amp;t=%{title}</pre>

<p>The %{name} values will be replaced with the following attributes if available.  Otherwise that parameter is removed from the final url used to load your share endpoint.</p>

<ul>
 <li>url: The URL to the page, link, image or video being shared</li>
 <li>medium: The media type being shared</li>
 <li>source: The media url being shared if a video is being shared</li>
 <li>sitename: The site name</li>
 <li>title: The title of the page</li>
 <li>description: The description of the page</li>
 <li>text: The selected text that the user is sharing</li>
 <li>image: A URL to an image to use as a preview, or the image shared by the user.</li>
</ul>

<h2 id="How_to_properly_size_your_share_panel">How to properly size your share panel</h2>

<p>Your share panel is presented in a door hanger from the browser toolbar.  While it can be flexible in size, there is a minimum and a maximum size that the panel will allow.  You also need to implement a couple items to help the browser identify the size you need for your panel.  There are a few ways you can define the proper size for your panel, here are some examples:</p>

<h3 id="Styling_the_BODY_element">Styling the BODY element</h3>

<p>By default the browser will look at the <code>body.style.width</code> and <code>body.style.height</code>, also taking into account the margin.  It will try to size the panel to show your full page.</p>

<pre>&lt;html&gt;
&lt;body style="width: 300px; height: 400px"&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>

<h3 id="Identifying_a_content_element">Identifying a content element</h3>

<p>The browser will also look to see if you have defined a primary content element.  If you have, then it will use the width and height styles from that element to size the panel.  You will need to make sure that your content element is properly placed.</p>

<pre>&lt;html&gt;
&lt;body contentid="content"&gt;
&lt;div id="content" style="width: 300px; height: 400px; top: 0; left: 0;"/&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>