]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | define("dojo/_base/unload", ["./kernel", "./connect"], function(dojo, connect) { |
2 | // module: | |
3 | // dojo/unload | |
4 | // summary: | |
5 | // This module contains the document and window unload detection API. | |
6 | ||
7 | var win = window; | |
8 | ||
9 | /*===== | |
10 | dojo.windowUnloaded = function(){ | |
11 | // summary: | |
12 | // signal fired by impending window destruction. You may use | |
13 | // dojo.addOnWindowUnload() to register a listener for this | |
14 | // event. NOTE: if you wish to dojo.connect() to this method | |
15 | // to perform page/application cleanup, be aware that this | |
16 | // event WILL NOT fire if no handler has been registered with | |
17 | // dojo.addOnWindowUnload. This behavior started in Dojo 1.3. | |
18 | // Previous versions always triggered dojo.windowUnloaded. See | |
19 | // dojo.addOnWindowUnload for more info. | |
20 | }; | |
21 | =====*/ | |
22 | ||
23 | dojo.addOnWindowUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){ | |
24 | // summary: | |
25 | // registers a function to be triggered when window.onunload | |
26 | // fires. | |
27 | // description: | |
28 | // The first time that addOnWindowUnload is called Dojo | |
29 | // will register a page listener to trigger your unload | |
30 | // handler with. Note that registering these handlers may | |
31 | // destory "fastback" page caching in browsers that support | |
32 | // it. Be careful trying to modify the DOM or access | |
33 | // JavaScript properties during this phase of page unloading: | |
34 | // they may not always be available. Consider | |
35 | // dojo.addOnUnload() if you need to modify the DOM or do | |
36 | // heavy JavaScript work since it fires at the eqivalent of | |
37 | // the page's "onbeforeunload" event. | |
38 | // example: | |
39 | // | dojo.addOnWindowUnload(functionPointer) | |
40 | // | dojo.addOnWindowUnload(object, "functionName"); | |
41 | // | dojo.addOnWindowUnload(object, function(){ /* ... */}); | |
42 | ||
43 | if (!dojo.windowUnloaded) { | |
44 | connect.connect(win, "unload", (dojo.windowUnloaded= function(){})); | |
45 | } | |
46 | connect.connect(win, "unload", obj, functionName); | |
47 | }; | |
48 | ||
49 | dojo.addOnUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){ | |
50 | // summary: | |
51 | // registers a function to be triggered when the page unloads. | |
52 | // description: | |
53 | // The first time that addOnUnload is called Dojo will | |
54 | // register a page listener to trigger your unload handler | |
55 | // with. | |
56 | // | |
57 | // In a browser enviroment, the functions will be triggered | |
58 | // during the window.onbeforeunload event. Be careful of doing | |
59 | // too much work in an unload handler. onbeforeunload can be | |
60 | // triggered if a link to download a file is clicked, or if | |
61 | // the link is a javascript: link. In these cases, the | |
62 | // onbeforeunload event fires, but the document is not | |
63 | // actually destroyed. So be careful about doing destructive | |
64 | // operations in a dojo.addOnUnload callback. | |
65 | // | |
66 | // Further note that calling dojo.addOnUnload will prevent | |
67 | // browsers from using a "fast back" cache to make page | |
68 | // loading via back button instantaneous. | |
69 | // example: | |
70 | // | dojo.addOnUnload(functionPointer) | |
71 | // | dojo.addOnUnload(object, "functionName") | |
72 | // | dojo.addOnUnload(object, function(){ /* ... */}); | |
73 | ||
74 | connect.connect(win, "beforeunload", obj, functionName); | |
75 | }; | |
76 | ||
77 | return { | |
78 | addOnWindowUnload: dojo.addOnWindowUnload, | |
79 | addOnUnload: dojo.addOnUnload | |
80 | }; | |
81 | }); |