1
YUI.add('util-share', function (Y, NAME) {
4
Y.namespace("U1.util");
8
var Share = function(link, photo) {
18
if (this.url && this.url.length) {
21
throw new Error("must set a url type before get");
25
setUrl: function(type) {
28
this.url = this._facebookUrl(this.link, this.photo);
31
this.url = this._twitterUrl(this.link);
41
* Opens a window to share the link
43
open: function(w, h, name) {
44
name = name || "U1Share";
45
var url = this.getUrl(),
46
conf = this.getConfString(w, h),
48
u1Window = Y.config.win.open(url, name, conf);
52
* Generated a conf string from width and height
53
@method generateConfString
54
@param {Number} w the window width (defaults to 420)
55
@param {Number} h the window height (defaults to 480)
57
getConfString: function(w, h) {
60
var win = Y.config.win,
61
left_ = parseInt((win.screen.width/2)-(w/2), 10),
62
top_ = parseInt((win.screen.height/2)-(h/2), 10);
63
return "width="+w+",height="+h+",left="+left_+",top="+top_+",status=yes";
66
_facebookUrl: function(link, photo) {
67
var url = "http://www.facebook.com/dialog/feed?",
68
id = "166704313352575",
70
redirect = "https://one.ubuntu.com/window-close/";
72
if (link && link.length) {
74
url += ["app_id=" + id,
75
"link="+ window.encodeURI(link),
76
"redirect_uri="+ window.encodeURI(redirect),
80
if (photo && photo.length) {
81
url += "&picture="+ window.encodeURI(photo);
87
throw new Error("_createFacebookUrl requires link to share");
91
_twitterUrl: function(link) {
92
var url = "https://twitter.com/share?";
94
if (link && link.length) {
97
"url="+ window.encodeURI(link),
98
"text="+ window.encodeURI("Sharing a link from UbuntuOne."),
106
throw new Error("createTwitterUrl requires link to share");
112
Y.U1.util.Share = Share;
115
}, '@VERSION@', {"requires": ["base", "node"]});