]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - js/share.js
change zeroclipboard to clipboardjs
[Github/YOURLS.git] / js / share.js
1 $(document).ready(function(){
2         $('#tweet_body').focus();
3
4         $('#tweet_body').keypress(function(){
5                 setTimeout( function(){update_share()}, 50 ); // we're delaying, otherwise keypress() always triggers too fast before current key press actually inserts a letter?!! Go figure.
6         });
7 })
8
9 function update_share() {
10         var text = encodeURIComponent( $('#tweet_body').val() );
11         var url = encodeURIComponent( $('#copylink').val() );
12         var tw = 'http://twitter.com/intent/tweet?status='+text;
13         var fb = 'http://www.facebook.com/share.php?u='+url ;
14         $('#share_tw').attr('href', tw);
15         $('#share_fb').attr('href', fb);
16         
17         var charcount = parseInt(140 - $('#tweet_body').val().length);
18         $('#charcount')
19                 .toggleClass("negative", charcount < 0)
20                 .text( charcount );
21 }
22
23 function share(dest) {
24         var url = $('#share_'+dest).attr('href');
25         switch (dest) {
26         case 'fb':
27                 //var url = $('#share_fb').attr('href');
28                 window.open( url, 'fb','toolbar=no,width=1000,height=550');
29                 break;
30         case 'tw':
31                 //var url = $('#share_tw').attr('href');
32                 window.open(url, 'tw','toolbar=no,width=800,height=550');
33                 break;
34         }
35         return false;
36 }
37
38 function init_clipboard() {
39
40     var clipboard = new Clipboard('#copylink', {
41         text: function (trigger) {
42             return $(trigger).select();
43         }
44     });
45
46     clipboard.on('success', function (e) {
47         html_pulse('#copybox h2, #copybox h3', 'Copied!');
48     });
49 };