1 // TODO: Open share links in a small window |
1 // TODO: Open share links in a small window |
2 |
2 |
3 IriSP.Widgets.Social = function(player, config) { |
3 IriSP.Widgets.Social = function(player, config) { |
4 IriSP.Widgets.Widget.call(this, player, config); |
4 IriSP.Widgets.Widget.call(this, player, config); |
|
5 ZeroClipboard.setMoviePath( IriSP.getLib('zeroClipboardSwf') ); |
5 } |
6 } |
6 |
7 |
7 IriSP.Widgets.Social.prototype = new IriSP.Widgets.Widget(); |
8 IriSP.Widgets.Social.prototype = new IriSP.Widgets.Widget(); |
8 |
9 |
9 IriSP.Widgets.Social.prototype.defaults = { |
10 IriSP.Widgets.Social.prototype.defaults = { |
10 text: "", |
11 text: "", |
11 url: "", |
12 url: "", |
|
13 show_url: true, |
12 show_twitter: true, |
14 show_twitter: true, |
13 show_fb: true, |
15 show_fb: true, |
14 show_gplus: true, |
16 show_gplus: true, |
15 show_mail: true |
17 show_mail: true |
16 } |
18 } |
17 |
19 |
18 IriSP.Widgets.Social.prototype.template = |
20 IriSP.Widgets.Social.prototype.template = |
19 '<span class="Ldt-Social">{{#show_fb}}<a href="#" target="_blank" class="Ldt-Social-Fb Ldt-TraceMe" title="{{l10n.share_on}} Facebook"></a>{{/show_fb}}' |
21 '<span class="Ldt-Social">{{#show_url}}<div class="Ldt-Social-Url-Container"><a href="#" target="_blank" class="Ldt-Social-Square Ldt-Social-Url Ldt-TraceMe" title="{{l10n.share_link}}">' |
|
22 + '</a><div class="Ldt-Social-UrlPop"><input class="Ldt-Social-Input"/><div class="Ldt-Social-CopyBtn">{{l10n.copy}}</div></div></div>{{/show_url}}' |
|
23 + '{{#show_fb}}<a href="#" target="_blank" class="Ldt-Social-Fb Ldt-TraceMe" title="{{l10n.share_on}} Facebook"></a>{{/show_fb}}' |
20 + '{{#show_twitter}}<a href="#" target="_blank" class="Ldt-Social-Twitter Ldt-TraceMe" title="{{l10n.share_on}} Twitter"></a>{{/show_twitter}}' |
24 + '{{#show_twitter}}<a href="#" target="_blank" class="Ldt-Social-Twitter Ldt-TraceMe" title="{{l10n.share_on}} Twitter"></a>{{/show_twitter}}' |
21 + '{{#show_gplus}}<a href="#" target="_blank" class="Ldt-Social-Gplus Ldt-TraceMe" title="{{l10n.share_on}} Google+"></a>{{/show_gplus}}' |
25 + '{{#show_gplus}}<a href="#" target="_blank" class="Ldt-Social-Gplus Ldt-TraceMe" title="{{l10n.share_on}} Google+"></a>{{/show_gplus}}' |
22 + '{{#show_mail}}<a href="#" target="_blank" class="Ldt-Social-Mail Ldt-TraceMe" title="{{l10n.share_mail}}"></a>{{/show_mail}}</span>'; |
26 + '{{#show_mail}}<a href="#" target="_blank" class="Ldt-Social-Mail Ldt-TraceMe" title="{{l10n.share_mail}}"></a>{{/show_mail}}</span>'; |
23 |
27 |
24 IriSP.Widgets.Social.prototype.messages = { |
28 IriSP.Widgets.Social.prototype.messages = { |
25 "fr": { |
29 "fr": { |
26 share_on: "Partager sur", |
30 share_on: "Partager sur", |
27 share_mail: "Envoyer par courriel" |
31 share_mail: "Envoyer par courriel", |
|
32 share_link: "Partager le lien hypertexte", |
|
33 copy: "Copier" |
28 }, |
34 }, |
29 "en" : { |
35 "en" : { |
30 share_on: "Share on", |
36 share_on: "Share on", |
31 share_mail: "Share by e-mail" |
37 share_mail: "Share by e-mail", |
|
38 share_link: "Share hypertext link", |
|
39 copy: "Copy" |
32 } |
40 } |
33 } |
41 } |
34 |
42 |
35 IriSP.Widgets.Social.prototype.draw = function() { |
43 IriSP.Widgets.Social.prototype.draw = function() { |
36 this.renderTemplate(); |
44 this.renderTemplate(); |
|
45 this.clipId = IriSP._.uniqueId("Ldt-Social-CopyBtn-"); |
|
46 this.$.find(".Ldt-Social-CopyBtn").attr("id", this.clipId); |
|
47 var _this = this; |
|
48 this.$.find(".Ldt-Social-Url").click(function() { |
|
49 _this.toggleCopy(); |
|
50 return false; |
|
51 }); |
|
52 this.$.find(".Ldt-Social-Input").focus(function() { |
|
53 this.select(); |
|
54 }); |
37 this.updateUrls(this.url, this.text); |
55 this.updateUrls(this.url, this.text); |
38 } |
56 } |
39 |
57 |
|
58 IriSP.Widgets.Social.prototype.toggleCopy = function() { |
|
59 var _pop = this.$.find(".Ldt-Social-UrlPop"); |
|
60 _pop.toggle(); |
|
61 if (_pop.is(":visible")) { |
|
62 if (typeof this.clip == "undefined") { |
|
63 this.clip = new ZeroClipboard.Client(); |
|
64 this.clip.setHandCursor( true ); |
|
65 this.clip.glue(this.clipId); |
|
66 var _this = this; |
|
67 this.clip.addEventListener( 'onMouseUp', function() { |
|
68 _pop.hide(); |
|
69 _this.clip.hide(); |
|
70 }); |
|
71 } |
|
72 this.clip.show(); |
|
73 this.clip.setText( this.url ); |
|
74 this.$.find(".Ldt-Social-Input").val(this.url).focus(); |
|
75 } else { |
|
76 this.clip.hide(); |
|
77 } |
|
78 } |
|
79 |
40 IriSP.Widgets.Social.prototype.updateUrls = function(_url, _text) { |
80 IriSP.Widgets.Social.prototype.updateUrls = function(_url, _text) { |
|
81 this.url = _url; |
|
82 this.text = _text; |
41 this.$.find(".Ldt-Social-Fb").attr("href", "http://www.facebook.com/share.php?" + IriSP.jQuery.param({ u: _url, t: _text })); |
83 this.$.find(".Ldt-Social-Fb").attr("href", "http://www.facebook.com/share.php?" + IriSP.jQuery.param({ u: _url, t: _text })); |
42 this.$.find(".Ldt-Social-Twitter").attr("href", "https://twitter.com/intent/tweet?" + IriSP.jQuery.param({ url: _url, text: _text })); |
84 this.$.find(".Ldt-Social-Twitter").attr("href", "https://twitter.com/intent/tweet?" + IriSP.jQuery.param({ url: _url, text: _text })); |
43 this.$.find(".Ldt-Social-Gplus").attr("href", "https://plusone.google.com/_/+1/confirm?" + IriSP.jQuery.param({ url: _url, title: _text })); |
85 this.$.find(".Ldt-Social-Gplus").attr("href", "https://plusone.google.com/_/+1/confirm?" + IriSP.jQuery.param({ url: _url, title: _text })); |
44 this.$.find(".Ldt-Social-Mail").attr("href", "mailto:?" + IriSP.jQuery.param({ subject: _text, body: _text + ": " + _url })); |
86 this.$.find(".Ldt-Social-Mail").attr("href", "mailto:?" + IriSP.jQuery.param({ subject: _text, body: _text + ": " + _url })); |
45 } |
87 } |