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