﻿function trimAll(a) { return a.replace(/\s/g, "") } function attachEventListener(a, b, c, d) { if (window.addEventListener) { a.addEventListener(b, c, d) } else { a.attachEvent("on" + b, c) } } function interceptKeyPress(a) { if (!a) { if (window.event) a = window.event; else return } var b = a.keyCode ? a.keyCode : a.which ? a.which : void 0; if (a.charCode == null || a.charCode == 0) { if (b == 116) { userMovingWithinSite() } } } function interceptKeyDown(a) { if (!a) { if (window.event) a = window.event; else return } keyCode = a.keyCode; if (keyCode == 116) { userMovingWithinSite() } if (keyCode == 17) { ctrlKeyIsDown = true } if (ctrlKeyIsDown && keyCode == 82) { userMovingWithinSite() } } function interceptKeyUp(a) { if (!a) { if (window.event) a = window.event; else return } keyCode = a.keyCode; if (keyCode == 17) { ctrlKeyIsDown = false } } function userMovingWithinSite() { movingWithinSite = true } var movingWithinSite = false; var codeToExecute = function () { }; var ctrlKeyIsDown = false; (function (a) { a.fn.onUserExit = function (b) { var c = { execute: "", internalURLs: "" }; var b = a.extend(c, b); if (b.execute == "") { alert("The onUserExit jQuery Plugin has been misconfigured.  Please add the function you wish to execute.") } if (b.internalURLs == "") { alert("The onUserExit jQuery Plugin has been misconfigured.  Please add internal URLs so it know when the user is navigating internally.") } codeToExecute = b.execute; a("a").each(function () { var c = a(this); var d = false; var e = trimAll(b.internalURLs).split("|"); for (i = 0; i < e.length; i++) { if (c.attr("href") == null || c.attr("href") == "undefined") continue; if (c.attr("href").indexOf(e[i]) !== -1) { d = true } if (c.attr("href").indexOf("http://") == -1) { d = true } } if (d == true) { c.bind("click", function () { userMovingWithinSite() }) } }); a("form").each(function () { var b = a(this); currentonSubmit = b.attr("onSubmit"); if (currentonSubmit === undefined) { currentonSubmit = "" } b.attr("onSubmit", currentonSubmit + " userMovingWithinSite();") }); attachEventListener(document, "keydown", interceptKeyDown, true); attachEventListener(document, "keyup", interceptKeyUp, true); attachEventListener(document, "keypress", interceptKeyPress, true) }; a(window).bind("beforeunload unload", function () { if (movingWithinSite == false) codeToExecute() }) })(jQuery)
