1c1dd91e |
1 | /**\r |
2 | * jQuery.FormNavigate.js\r |
3 | * jQuery Form onChange Navigate Confirmation plugin\r |
4 | * Browser Compatibility : IE 6.0, 7.0, 8.0; Firefox 2.0+; Safari 3+; Opera 9+; Chrome 1+;\r |
5 | *\r |
6 | * Copyright (c) 2009 Law Ding Yong\r |
7 | * \r |
8 | * Licensed under the MIT license:\r |
9 | * http://www.opensource.org/licenses/mit-license.php\r |
10 | *\r |
11 | * See the file license.txt for copying permission.\r |
12 | */\r |
13 | \r |
14 | /**\r |
15 | * Documentation :\r |
16 | * ==================\r |
17 | *\r |
18 | * How to Use:\r |
19 | * $("YourForm").FormNavigate("YourMessage");\r |
20 | * -- "YourForm" as Your Form ID $("#form") or any method to grab your form\r |
21 | * -- "YourMessage" as Your onBeforeUnload Prompt Message Here\r |
22 | *\r |
23 | * This plugin handles onchange of input type of text, textarea, password, radio, checkbox, select and file to toggle on and off of window.onbeforeunload event.\r |
24 | * Users are able to configure the custom onBeforeUnload message.\r |
25 | */\r |
26 | var global_formNavigate = true; // Js Global Variable for onChange Flag\r |
27 | (function($){\r |
28 | $.fn.FormNavigate = function(message) {\r |
29 | window.onbeforeunload = confirmExit; \r |
30 | function confirmExit( event ) { \r |
31 | if (global_formNavigate == true) { event.cancelBubble = true; } else { return message; }\r |
32 | }\r |
33 | $(":input[type=text], :input[type='textarea'], :input[type='password'], :input[type='radio'], :input[type='checkbox'], :input[type='file'], select", this).change(function(){\r |
34 | global_formNavigate = false;\r |
35 | });\r |
36 | //to handle back button\r |
37 | $(":input[type='textarea']", this).keyup(function(){ \r |
38 | global_formNavigate = false; \r |
39 | }); \r |
40 | $(":submit", this).click(function(){\r |
41 | global_formNavigate = true;\r |
42 | });\r |
43 | $(".token-input-list-facebook").bind( "DOMNodeRemoved DOMNodeInserted", function(){ \r |
44 | global_formNavigate = false; \r |
45 | });\r |
46 | }\r |
47 | })(jQuery);\r |