SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Paste event catch only a url

    Hi,
    I'm setting up a link preview like fb
    you know you can write a message paste
    an url and see the preview.
    The point is catching a url in a string
    so my first thought was for a regex way
    but may be it's too tricky
    http://stackoverflow.com/questions/5...-url-in-a-text
    peep into this other thread looking for a way to get the pasted string
    http://stackoverflow.com/questions/2...he-paste-event
    I ended up with this solution
    PHP Code:
    $('#message_link').bind({
           
    paste: function() {
                var 
    bPLength = $.trim($('#message_link').val()).length;
                
    setTimeout(function() {
                    var 
    strInput = $.trim($('#message_link').val());
                    var 
    aPLength strInput.length;
                    
    log(bPLength);
                    
    log(aPLength);
                    
    log(strInput.substr(bPLength,aPLength));
                   
    //var xhr = YD.http.linkPreview($.trim($('#message_link').val()));
                
    }, 0);
           }
        }); 
    and it seems to work but I'd like to know your opinion.

    Bye

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tidier
    PHP Code:
    $('#message_link').bind({
           
    paste: function() {
                var 
    $self = $(this);
                var 
    bPLength $self.val().length;
                
    setTimeout(function() {
                    var 
    strInput $self.val();
                    var 
    aPLength strInput.length;
                    var 
    pastedLink = $.trim(strInput.substr(bPLength,aPLength));
                    
    log(pastedLink);
                    var 
    xhr YD.http.linkPreview(pastedLink);
                }, 
    0);
           }
        }); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •