jquerydialogjquery-eventsconfirm

jQuery Clean Confirm Dialog Idea - but onclick does not trigger the new onclick functions when called from eventHandler


So since the jQuery confirm box looks awesome I figured we need to make it actually usefull by making it possible to use it together with all other click events and inline handlers without hassles and ugly hacks like redirecting the browser url.

So I came up with this EDIT new version jQuery confirm dialog idea to capture click events before onclick can get triggered

I figure when accessing the eventHandler of that object, it is already to late to update the inline handlers. Or is there a way?

The code:

    $(function(){
    $(".needsFancyConfirm").each(function(index, ele){
        ele=$(ele);
        ele._onclick=ele.attr("onclick");
        ele.attr("onclick", "return false;"); //preventDefault would do the same imho

        ele.bind("click.foo",function(){
            $("#dialog").dialog({
         bgiframe: true,
         height: 300,
         modal: true,
         buttons: {
              SubmitFormWithAllOldOnclickEvents: function() {
                    $(this).dialog('close');
                 ele.attr("onclick",ele._onclick);
                  ele.unbind("click", "click.foo");
                 console.info(ele.attr('onclick') + " <-- just to make sure what is written in Onclick, now we will execute it");
                  console.info($("#coolIdea")[0].onclick() + " <-- this returns false - it should return the set old onclick e.g. alert Wow u managed to execute me");
              }
         }


         });
        });
});
});

Solution

  • So i think this is basically a chicken and egg problem.

    At the moment we capture the event there is no way to change the eventhandlers since they were already read.