1
0
Переглянути джерело

Fixes #52 - Closes helios popup after parent unload event

Ryan Simmons 9 роки тому
батько
коміт
9f203394b0
2 змінених файлів з 72 додано та 2 видалено
  1. 60 2
      src/Helios-Core.js
  2. 12 0
      src/Helios-Core.st

+ 60 - 2
src/Helios-Core.js

@@ -5376,6 +5376,7 @@ return $8;
 } else {
 $7;
 };
+self._handleLossOfEnvironmentWithParent_(parent);
 $9=$recv($recv(parentSmalltalkGlobals)._at_("Environment"))._new();
 return $9;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -5384,10 +5385,10 @@ return $9;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "defaultEnvironment\x0a\x09\x22If helios is loaded from within a frame, answer the parent window environment\x22\x0a\x09\x0a\x09| parent parentSmalltalkGlobals |\x0a\x09\x0a\x09parent := window opener ifNil: [ window parent ].\x0a\x09parent ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09[ parentSmalltalkGlobals := ((parent at: 'requirejs') value: 'amber/boot') at: 'globals' ]\x0a\x09on: Error do: [ parentSmalltalkGlobals := (parent at: 'requirejs') value: 'amber_vm/globals' ].\x0a\x09parentSmalltalkGlobals ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09^ (parentSmalltalkGlobals at: 'Environment') new",
+source: "defaultEnvironment\x0a\x09\x22If helios is loaded from within a frame, answer the parent window environment\x22\x0a\x09\x0a\x09| parent parentSmalltalkGlobals |\x0a\x09\x0a\x09parent := window opener ifNil: [ window parent ].\x0a\x09parent ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09[ parentSmalltalkGlobals := ((parent at: 'requirejs') value: 'amber/boot') at: 'globals' ]\x0a\x09on: Error do: [ parentSmalltalkGlobals := (parent at: 'requirejs') value: 'amber_vm/globals' ].\x0a\x09parentSmalltalkGlobals ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09self handleLossOfEnvironmentWithParent: parent.\x0a\x09\x0a\x09^ (parentSmalltalkGlobals at: 'Environment') new",
 referencedClasses: ["Environment", "Error"],
 //>>excludeEnd("ide");
-messageSends: ["ifNil:", "opener", "parent", "new", "on:do:", "at:", "value:"]
+messageSends: ["ifNil:", "opener", "parent", "new", "on:do:", "at:", "value:", "handleLossOfEnvironmentWithParent:"]
 }),
 $globals.HLManager);
 
@@ -5441,6 +5442,39 @@ messageSends: []
 }),
 $globals.HLManager);
 
+$core.addMethod(
+$core.method({
+selector: "handleLossOfEnvironmentWithParent:",
+protocol: 'actions',
+fn: function (parent){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(parent)._onunload_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+self._removeBeforeUnloadMessage();
+return $recv(window)._close();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"handleLossOfEnvironmentWithParent:",{parent:parent},$globals.HLManager)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["parent"],
+source: "handleLossOfEnvironmentWithParent: parent\x0a\x09parent onunload: [ \x0a\x09\x09self removeBeforeUnloadMessage.\x0a\x09\x09window close ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["onunload:", "removeBeforeUnloadMessage", "close"]
+}),
+$globals.HLManager);
+
 $core.addMethod(
 $core.method({
 selector: "history",
@@ -5750,6 +5784,30 @@ messageSends: ["removeActiveTab", "tabsWidget"]
 }),
 $globals.HLManager);
 
+$core.addMethod(
+$core.method({
+selector: "removeBeforeUnloadMessage",
+protocol: 'actions',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+window.onbeforeunload = null;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"removeBeforeUnloadMessage",{},$globals.HLManager)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "removeBeforeUnloadMessage\x0a\x09<window.onbeforeunload = null>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.HLManager);
+
 $core.addMethod(
 $core.method({
 selector: "removeTabForWidget:",

+ 12 - 0
src/Helios-Core.st

@@ -1277,6 +1277,12 @@ confirm: aString ifTrue: aBlock ifFalse: anotherBlock
 		show
 !
 
+handleLossOfEnvironmentWithParent: parent
+	parent onunload: [ 
+		self removeBeforeUnloadMessage.
+		window close ]
+!
+
 inform: aString
 	HLInformationWidget new
 		informationString: aString;
@@ -1287,6 +1293,10 @@ removeActiveTab
 	self tabsWidget removeActiveTab
 !
 
+removeBeforeUnloadMessage
+	<window.onbeforeunload = null>
+!
+
 removeTabForWidget: aWidget
 	self tabsWidget removeTabForWidget: aWidget
 !
@@ -1320,6 +1330,8 @@ defaultEnvironment
 	on: Error do: [ parentSmalltalkGlobals := (parent at: 'requirejs') value: 'amber_vm/globals' ].
 	parentSmalltalkGlobals ifNil: [ ^ Environment new ].
 	
+	self handleLossOfEnvironmentWithParent: parent.
+	
 	^ (parentSmalltalkGlobals at: 'Environment') new
 ! !