Skip to content

Commit

Permalink
amd related cleanup: localize references to dojo "global", and use on…
Browse files Browse the repository at this point in the history
…() rather than dojo/connect, refs #12672 !strict.

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@28614 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
wkeese committed May 20, 2012
1 parent f63bb33 commit 37f9223
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions _base/unload.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
define(["./kernel", "./connect"], function(dojo, connect) {
// module:
// dojo/unload
define(["./kernel", "./lang", "../on"], function(dojo, lang, on){

// module:
// dojo/unload
// summary:
// This module contains the document and window unload detection API.

var win = window;

/*=====
dojo.windowUnloaded = function(){
// summary:
// This module contains the document and window unload detection API.
// 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.
};
=====*/

var win = window;

/*=====
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
// dojo.addOnWindowUnload. This behavior started in Dojo 1.3.
// Previous versions always triggered dojo.windowUnloaded. See
// dojo.addOnWindowUnload for more info.
};
=====*/
var unload = { // module export

dojo.addOnWindowUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){
addOnWindowUnload: function(/*Object?|Function?*/ obj, /*String|Function?*/ functionName){
// summary:
// registers a function to be triggered when window.onunload
// fires.
// 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
// destory "fastback" page caching in browsers that support
// 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
// dojo.addOnUnload() if you need to modify the DOM or do
// heavy JavaScript work since it fires at the eqivalent of
// 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:
// | dojo.addOnWindowUnload(functionPointer)
// | dojo.addOnWindowUnload(object, "functionName");
// | dojo.addOnWindowUnload(object, function(){ /* ... */});
// | unload.addOnWindowUnload(functionPointer)
// | unload.addOnWindowUnload(object, "functionName");
// | unload.addOnWindowUnload(object, function(){ /* ... */});

if (!dojo.windowUnloaded) {
connect.connect(win, "unload", (dojo.windowUnloaded= function(){}));
on(win, "unload", (dojo.windowUnloaded = function(){}));
}
connect.connect(win, "unload", obj, functionName);
};
on(win, "unload", lang.hitch(obj, functionName));
},

dojo.addOnUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){
addOnUnload: function(/*Object?|Function?*/ obj, /*String|Function?*/ functionName){
// summary:
// registers a function to be triggered when the page unloads.
// description:
// The first time that addOnUnload is called Dojo will
// register a page listener to trigger your unload handler
// with.
//
// In a browser enviroment, the functions will be triggered
// 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
Expand All @@ -71,11 +75,13 @@ define(["./kernel", "./connect"], function(dojo, connect) {
// | dojo.addOnUnload(object, "functionName")
// | dojo.addOnUnload(object, function(){ /* ... */});

connect.connect(win, "beforeunload", obj, functionName);
};
on(win, "beforeunload", lang.hitch(obj, functionName));
}
};

dojo.addOnWindowUnload = unload.addOnWindowUnload;
dojo.addOnUnload = unload.addOnUnload;

return unload;

return {
addOnWindowUnload: dojo.addOnWindowUnload,
addOnUnload: dojo.addOnUnload
};
});

0 comments on commit 37f9223

Please sign in to comment.