#1981 JS Window Events

SlimerDude Mon 30 Jul 2012

Am I right in thinking some fwt::Window events are not invoked in JS? The following :

using fwt
class Wotever {
  private static const Log log := Log.get("Wotever")
  Void main() {
    window := Window(null)

    window.onActive.add {
      log.warn("onActive")
    }
    window.onFocus.add {
      log.warn("onFocus")
    }
    window.onOpen.add {
      log.warn("onOpen")
    }

    window.open
  }
}

in Java prints:

onActive
onFocus
onOpen

...but nothing in JS?

andy Mon 30 Jul 2012

onOpen probably makes sense - I can add that - already should work for Dialog. Not sure about the other two tho - or if browsers even report those hooks.

SlimerDude Mon 30 Jul 2012

onOpen probably makes sense

That'd be great. I'm looking for a consistent (in Java / JS) way to kick off code when I open the main window.

SlimerDude Wed 9 Sep 2015

Dunno if this has been lost sight of, but it'd still be useful if the onOpen event was fired in Javascript.

SlimerDude Mon 21 Sep 2015

Here's a quick patch that fires the Window.onOpen event in JS:

diff -r 034bc9c81a32 src/fwt/js/WindowPeer.js
--- a/src/fwt/js/WindowPeer.js	Mon Sep 21 15:23:52 2015 -0400
+++ b/src/fwt/js/WindowPeer.js	Tue Sep 22 00:23:59 2015 +0100
@@ -44,6 +44,11 @@
 
   // attach resize listener
   window.addEventListener("resize", function() { self.relayout(); }, false);
+
+  var event      = fan.fwt.Event.make();
+  event.m_id     = fan.fwt.EventId.m_open;
+  event.m_widget = self;
+  self.onOpen().fire(event);
 }
 
 fan.fwt.WindowPeer.prototype.close = function(self, result)

without the patch, my code usually looks like:

...
window.open	

if (Env.cur.runtime == "js")
    window.onOpen.fire(Event() { it.id = EventId.open; it.widget = window } )
...

andy Tue 22 Sep 2015

Login or Signup to reply.