Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t665] onclose event for editors

1. Right before closing, editors will issue a close message through comm.
2. Rest of "close" code happen (almost) next JS event loop.
  • Loading branch information...
commit 83fad2b6849086b5d2d46521175750ef6795cad5 1 parent 728de40
Bobby Richter authored
4 editors/default-editor.html
View
@@ -54,6 +54,10 @@
}
}, false);
+ _comm.listen( "close", function( e ){
+ // use this to process something right before the editor closes
+ });
+
_comm.listen( "trackeventupdated", function( e ){
for( var item in _manifest ){
var element = document.getElementById( item );
44 src/dialog/iframe-dialog.js
View
@@ -39,24 +39,32 @@ define( [
} //onCancel
this.close = function(){
- _parent.removeChild( _iframe );
- if( _modalLayer ){
- _modalLayer.destroy();
- _modalLayer = undefined;
- } //if
- _comm.unlisten( "submit", onSubmit );
- _comm.unlisten( "cancel", onCancel );
- _comm.unlisten( "close", _this.close );
- _comm.destroy();
- _open = false;
- window.removeEventListener( "beforeunload", _this.close, false);
- for( var e in _listeners ){
- if( e !== "close" ){
- _em.unlisten( e, _listeners[ e ] );
- }
- } //for
- _em.dispatch( "close" );
- _em.unlisten( "close", _listeners.close );
+ // Send a close message to the dialog first, then actually close the dialog.
+ // A setTimeout is used here to ensure that its associated function will be run
+ // almost right after the postMessage happens. This ensures that messages get to
+ // their destination before we remove the dom element (which will basically ruin
+ // everything) by placing callbacks in the browser's event loop in the correct order.
+ _this.send( "close" );
+ setTimeout(function(){

setTimeout( function(){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ _parent.removeChild( _iframe );
+ if( _modalLayer ){
+ _modalLayer.destroy();
+ _modalLayer = undefined;
+ } //if
+ _comm.unlisten( "submit", onSubmit );
+ _comm.unlisten( "cancel", onCancel );
+ _comm.unlisten( "close", _this.close );
+ _comm.destroy();
+ _open = false;
+ window.removeEventListener( "beforeunload", _this.close, false);

_this.close, false );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ for( var e in _listeners ){
+ if( e !== "close" ){
+ _em.unlisten( e, _listeners[ e ] );
+ }
+ } //for
+ _em.dispatch( "close" );
+ _em.unlisten( "close", _listeners.close );
+ }, 0);

}, 0 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}; //close
this.open = function( listeners ){
46 src/dialog/window-dialog.js
View
@@ -59,25 +59,33 @@ define( [
} //onError
this.close = function(){
- if( _modalLayer ){
- _modalLayer.destroy();
- _modalLayer = undefined;
- } //if
- _comm.unlisten( "submit", onSubmit );
- _comm.unlisten( "cancel", onCancel );
- _comm.unlisten( "close", _this.close );
- _comm.destroy();
- if( _window.close ){
- _window.close();
- } //if
- clearInterval( _statusInterval );
- window.removeEventListener( "beforeunload", _this.close, false);
- _comm = _window = undefined;
- _open = false;
- for( var e in _listeners ){
- _em.unlisten( e, _listeners[ e ] );
- } //for
- _em.dispatch( "close" );
+ // Send a close message to the dialog first, then actually close the dialog.
+ // A setTimeout is used here to ensure that its associated function will be run
+ // almost right after the postMessage happens. This ensures that messages get to
+ // their destination before we remove the dom element (which will basically ruin
+ // everything) by placing callbacks in the browser's event loop in the correct order.
+ _this.send( "close" );
+ setTimeout(function(){

setTimeout( function(){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if( _modalLayer ){
+ _modalLayer.destroy();
+ _modalLayer = undefined;
+ } //if
+ _comm.unlisten( "submit", onSubmit );
+ _comm.unlisten( "cancel", onCancel );
+ _comm.unlisten( "close", _this.close );
+ _comm.destroy();
+ if( _window.close ){
+ _window.close();
+ } //if
+ clearInterval( _statusInterval );
+ window.removeEventListener( "beforeunload", _this.close, false);

_this.close, false );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ _comm = _window = undefined;
+ _open = false;
+ for( var e in _listeners ){
+ _em.unlisten( e, _listeners[ e ] );
+ } //for
+ _em.dispatch( "close" );
+ }, 0 );
}; //close
function checkWindowStatus(){
Matthew Schranz

setTimeout( function(){

Matthew Schranz

_this.close, false );

Matthew Schranz

setTimeout( function(){

Matthew Schranz

_this.close, false );

Please sign in to comment.
Something went wrong with that request. Please try again.