Loading...

Viewing Fixee

Language: Javascript (View Plain Text) (Show diff)

February 9, 2010 11:41 pm

  1. //Find each link or input with a hard coded onclick method
  2. jQuery.each(jQuery("a[onclick], input[onclick]"), function(){
  3. //create an "onclickmethod" attribute and assign it the FUNCTION DEFINITION of the onclick method (in order to cache it for later use)
  4. jQuery.data(jQuery(this)[0], "onclickmethod", jQuery(this).attr("onclick").toString());
  5. //remove the onclick function bind
  6. jQuery(this).removeAttr("onclick");
  7. });
  8. jQuery("a, input").live("click", function(e){
  9. window.doAskConfirm = false;
  10.  
  11. //grab the cached function definition for the originally bound onclick method
  12. var methodString = jQuery.data(jQuery(this)[0],"onclickmethod");
  13. //if the element had an onclickmethod attr, continue on in order to execute it
  14. if(!!methodString){
  15. //remove the " onclick" leaving just an annonymous function definition
  16. var reg = / onclick/;
  17. methodString = methodString.replace(reg, '');
  18. //create a function named clickMethod holding the anonymous function created above
  19. clickMethod = eval("(" + methodString + ")");
  20. //execute the clickMethod function (call the original click event)
  21. clickMethod(e);
  22. }
  23. });