-
-
Save labs-scnm/7235903 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
| (function(){ | |
| var $ = jQuery; | |
| var TRANSFORM_TYPES = ['PUT', 'POST', 'DELETE']; | |
| $.activeTransforms = 0; | |
| $(document).ajaxSend(function(e, xhr, settings) { | |
| if (TRANSFORM_TYPES.indexOf.call(settings.type) < 0) return; | |
| return $.activeTransforms += 1; | |
| }); | |
| $(document).ajaxComplete(function(e, xhr, settings) { | |
| if (TRANSFORM_TYPES.indexOf.call(settings.type) < 0) return; | |
| return $.activeTransforms -= 1; | |
| }); | |
| window.onbeforeunload || (window.onbeforeunload = function() { | |
| if ($.activeTransforms) { | |
| return 'There are some pending network requests which\nmeans closing the page may lose unsaved data.'; | |
| } | |
| }); | |
| }).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment