Last active
August 29, 2015 14:00
-
-
Save stefanbackor/11211193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Speed up your webapp click response using jQuery.. | |
/* | |
Use case: Lets suppose we are using XMLHttpRequest Ajax calls for page content change - expecting html return to just redraw page container, not whole layout | |
Solution: Use mousedown instead of click if possible. Don't forget to bypass if any function key or other than left click pressed. | |
*/ | |
$(document).on("mousedown","a[href^='/']",basicAjaxEvent); | |
$(document).on("click","a[href^='/']",basicAjaxEvent); | |
function basicAjaxEvent(e){ | |
var ret = undefined; | |
var callback=doYourBasicAjaxPageContentRequestAndReturnTrueIfSuccess_function; | |
$(this).data('was-mouse-down',ret); | |
if(e.altKey==false&&e.ctrlKey==false&&e.shiftKey==false&&e.metaKey==false&&(e.which==0||e.which==1)&&typeof callback == "function"/*&&!isLameBrowser()*/) { | |
if(e.type=="mousedown"){ | |
ret = !callback($(this)); | |
$(this).data('was-mouse-down',ret); | |
return ret; | |
} | |
else if(e.type=="click"){ | |
return ($(this).data('was-mouse-down' == true) ? true : false; | |
} | |
else { | |
return false; | |
} | |
} | |
else if(e.type=="click"&&$(this).attr("href")!=undefined&&$(this).attr("href")!="") { | |
return callback($(this)); | |
} | |
else if($(this).attr("href")!=undefined&&$(this).attr("href")!="") { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment