From cc2c634f732803aee80ba67632c5fe5efaa66b51 Mon Sep 17 00:00:00 2001 From: ozhozh Date: Thu, 1 Jul 2010 18:51:55 +0000 Subject: [PATCH] JS tweaks git-svn-id: http://yourls.googlecode.com/svn/trunk@446 12232710-3e20-11de-b438-597f59cd7555 --- js/insert.js | 2 ++ js/share.js | 35 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/js/insert.js b/js/insert.js index 10b991b..fda0c09 100644 --- a/js/insert.js +++ b/js/insert.js @@ -44,12 +44,14 @@ function add() { function toggle_share_fill_boxes( url, shorturl, title ) { $('#copylink').val( shorturl ); + $('#titlelink').val( title ); $('#origlink').attr( 'href', url ).html( url ); $('#statlink').attr( 'href', shorturl+'+' ).html( shorturl+'+' ); var tweet = ( title ? title + ' ' + shorturl : shorturl ); $('#tweet_body').val( tweet ).keypress(); $('#shareboxes').slideDown(); init_clipboard(); + $('#tweet_body').keypress(); } // Display the edition interface diff --git a/js/share.js b/js/share.js index 1d400ed..4744d08 100644 --- a/js/share.js +++ b/js/share.js @@ -1,22 +1,10 @@ $(document).ready(function(){ $('#tweet_body').focus(); - $('#tweet_body').keyup(function(event){ - var text = encodeURI( $('#tweet_body').val() ); - var url = encodeURI( $('#copylink').val() ); - var tw = 'http://twitter.com/home?status='+text; - var ff = 'http://friendfeed.com/share/bookmarklet/frame#title='+text ; - var fb = 'http://www.facebook.com/share.php?u='+url ; - $('#share_tw').attr('href', tw); - $('#share_ff').attr('href', ff); - $('#share_fb').attr('href', fb); - - var charcount = parseInt(140 - $('#tweet_body').val().length); - $('#charcount') - .toggleClass("negative", charcount < 0) - .text( charcount ); + $('#tweet_body').keypress(function(){ + setTimeout( function(){update_share()}, 50 ); // we're delaying, otherwise keypress() always triggers too fast before current key press actually inserts a letter?!! Go figure. }); - + $('#copylink').click(function(){ $(this).select(); }); @@ -24,6 +12,23 @@ $(document).ready(function(){ init_clipboard(); }) +function update_share() { + var text = encodeURI( $('#tweet_body').val() ); + console.log( text ); + var url = encodeURI( $('#copylink').val() ); + var tw = 'http://twitter.com/home?status='+text; + var ff = 'http://friendfeed.com/share/bookmarklet/frame#title='+text ; + var fb = 'http://www.facebook.com/share.php?u='+url ; + $('#share_tw').attr('href', tw); + $('#share_ff').attr('href', ff); + $('#share_fb').attr('href', fb); + + var charcount = parseInt(140 - $('#tweet_body').val().length); + $('#charcount') + .toggleClass("negative", charcount < 0) + .text( charcount ); +} + function share(dest) { var url = $('#share_'+dest).attr('href'); switch (dest) { -- 2.45.0