]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - js/share.js
Fix end of line
[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 ff = 'http://friendfeed.com/share/bookmarklet/frame#title='+text ;
14         var fb = 'http://www.facebook.com/share.php?u='+url ;
15         $('#share_tw').attr('href', tw);
16         $('#share_ff').attr('href', ff);
17         $('#share_fb').attr('href', fb);
18         
19         var charcount = parseInt(140 - $('#tweet_body').val().length);
20         $('#charcount')
21                 .toggleClass("negative", charcount < 0)
22                 .text( charcount );
23 }
24
25 function share(dest) {
26         var url = $('#share_'+dest).attr('href');
27         switch (dest) {
28         case 'ff':
29                 //$('body').append('<script type="text/javascript" src="http://friendfeed.com/share/bookmarklet/javascript"></script>');
30                 window.open(url, 'ff','toolbar=no,width=500,height=350');
31                 break;
32         case 'fb':
33                 //var url = $('#share_fb').attr('href');
34                 window.open( url, 'fb','toolbar=no,width=1000,height=550');
35                 break;
36         case 'tw':
37                 //var url = $('#share_tw').attr('href');
38                 window.open(url, 'tw','toolbar=no,width=800,height=550');
39                 break;
40         }
41         return false;
42 }
43
44 function init_clipboard() {
45         $('#copylink').click(function(){
46                 $(this).select();
47         })
48         
49         $('#copylink').zclip({
50                 path: zclipurl,
51                 copy: $('#copylink').val(),
52                 afterCopy:function(){
53                         html_pulse( '#copybox h2, #copybox h3', 'Copied!' );
54                 }
55         });
56 };                     
57