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