1

for the moment the script does like this:

  1. click on the link edit the link by making the input visible
  2. click next/before the link edit the link by making the input visible

i want when you click one time on the link not to edit but to open the page in new window, and when you click double to edit.

here's the script:

jsfiddle - CODE

Abude
  • 2,112
  • 7
  • 35
  • 58

2 Answers2

3

http://jsfiddle.net/jaspermogg/pFyNY/1/ - you can double click the div to edit, or single click the link to open. That what you wanted?

$('.a0').dblclick(function(e){
    e.preventDefault();
    $(this).parent().find('input').val($(this).find('a').text()).show().focus();
    $(this).hide();
})

$('#url0, #url1').each(
    function(index, element){
        $(element).blur(function(){
            $(this).hide().prev().show().find('a').html(this.value);
    })
    }    
);

And here's a jsFiddle that changes the href of the a to the value you edited it to, just in case that's what you're trying to do next :-) http://jsfiddle.net/jaspermogg/pFyNY/2/

Here's the jsFiddle that does what you want - http://jsfiddle.net/jaspermogg/pFyNY/5/

JS -

$('.a0 a').click(function(){

    var href = $(this).attr('href');

    // Redirect only after 500 milliseconds (CHANGE THE 500 IN THE CODE TO DETERMINE HOW LONG THE USER GETS TO DBLCLICK)
    if (!$(this).data('timer')) {
       $(this).data('timer', setTimeout(function () {
          window.location = href;
       }, 500));
    }
    return false; // Prevent default action (redirecting)
});

$('.a0').dblclick(function(){
    clearTimeout($(this).find('a').data('timer'));
    $(this).find('a').data('timer', null);

    $(this).parent().find('input').val($(this).find('a').text()).show().focus();
    $(this).hide();
})

$('#url0, #url1').each(
    function(index, element){
        $(element).blur(function(){
            $(this).hide().prev().show().find('a').html(this.value);
    })
    }    
);

Inspired by Jquery create Double Click event on A Href

Community
  • 1
  • 1
Jasper Mogg
  • 924
  • 2
  • 8
  • 23
0

Use target="_blank" property to open link in new page.

<a target="_blank" href="dsad.cas">dsad.cas</a>

And use .dblclick function of jquery to edit the link

$('.a0').dblclick(function(e){
    e.preventDefault();
    $(this).parent().find('input').val($(this).find('a').text()).show().focus();
    $(this).hide();
})

$('#url0, #url1').each(
    function(index, element){
        $(element).blur(function(){
            $(this).hide().prev().show().find('a').html(this.value);
    })
    }    
);
​

Here is the Demo

Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101
  • nope :) , it's not what i want to do, i want one click on the div area and double click on the link to make the edit, also one click on the link to go to the page – Abude Jun 22 '12 at 16:47