]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - js/share.js
Fix URL to share on Twitter
[Github/YOURLS.git] / js / share.js
1 $(document).ready(function(){\r
2         $('#tweet_body').focus();\r
3 \r
4         $('#tweet_body').keypress(function(){\r
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.\r
6         });\r
7         \r
8         $('#copylink').click(function(){\r
9                 $(this).select();\r
10         });     \r
11         \r
12         init_clipboard();\r
13 })\r
14 \r
15 function update_share() {\r
16         var text = encodeURI( $('#tweet_body').val() );\r
17         var url = encodeURI( $('#copylink').val() );\r
18         var tw = 'http://twitter.com/intent/tweet?status='+text;\r
19         var ff = 'http://friendfeed.com/share/bookmarklet/frame#title='+text ;\r
20         var fb = 'http://www.facebook.com/share.php?u='+url ;\r
21         $('#share_tw').attr('href', tw);\r
22         $('#share_ff').attr('href', ff);\r
23         $('#share_fb').attr('href', fb);\r
24         \r
25         var charcount = parseInt(140 - $('#tweet_body').val().length);\r
26         $('#charcount')\r
27                 .toggleClass("negative", charcount < 0)\r
28                 .text( charcount );\r
29 }\r
30 \r
31 function share(dest) {\r
32         var url = $('#share_'+dest).attr('href');\r
33         switch (dest) {\r
34         case 'ff':\r
35                 //$('body').append('<script type="text/javascript" src="http://friendfeed.com/share/bookmarklet/javascript"></script>');\r
36                 window.open(url, 'ff','toolbar=no,width=500,height=350');\r
37                 break;\r
38         case 'fb':\r
39                 //var url = $('#share_fb').attr('href');\r
40                 window.open( url, 'fb','toolbar=no,width=1000,height=550');\r
41                 break;\r
42         case 'tw':\r
43                 //var url = $('#share_tw').attr('href');\r
44                 window.open(url, 'tw','toolbar=no,width=800,height=550');\r
45                 break;\r
46         }\r
47         return false;\r
48 }\r
49 \r
50 var clip;\r
51 function init_clipboard() {\r
52         // Check we have the proper copy element\r
53         if( !$('#copylink').length )\r
54                 return;\r
55                 \r
56         // Create a new clipboard client\r
57         clip = new ZeroClipboard.Client();\r
58         \r
59         // Glue the clipboard client to the last td in each row\r
60         clip.glue( 'copylink' );\r
61 \r
62         // Grab the text from the parent row of the icon\r
63         var txt = $('#copylink').val();\r
64         clip.setText(txt);\r
65 \r
66         // Add a complete event to let the user know the text was copied\r
67         clip.addEventListener('complete', function(client, text) {\r
68                 html_pulse( '#copybox h2', 'Copied!' );\r
69         });\r
70         \r
71         // Custom animation on hover\r
72         $('#copylink').css({'backgroundPosition':'130% 50%'});\r
73         clip.addEventListener('onMouseOver', function(client, text) {\r
74                 $('#copylink').select().animate({'backgroundPosition':'100% 50%'}, 300);\r
75         });\r
76         clip.addEventListener('onMouseOut', function(client, text) {\r
77                 $('#copylink').blur().animate({'backgroundPosition':'130% 50%'}, 300);\r
78         });\r
79         \r
80         // Force flash clip size (IE fix)\r
81         $('#'+clip.movieId).css('height', '35px');\r
82 };                     \r
83 \r