[GeoNetwork-devel] Fix for little red reset button in IE

1. Start up GN in IE7.
2. Click on "Open Map Viewer".
3. Click on the red and white reset (on/off) button
    at the top right of the big map.
4. Scroll to the bottom of the page and observe the error message:
    "Exception 'Object doesn't support this property or method'".

It seems this was broken by the cleanup
of Intermap in revision 955.

The Intermap.rebuild() function is not
an event handler, so one shouldn't use
bindAsEventListener() on it. This time
it is just "good luck" that the code works
in Firefox.

I attach a patch.

[The reason the existing code works on
Firefox and not in IE is because
of the implementation
of bindAsEventListener() in prototype.js.

The second time rebuild() is called
(after pressing the red reset button),
it is being called by
bindAsEventListener(), and
bindAsEventListener() is passing
the value of window.event
as the parameter to rebuild().
IE has window.event;
Firefox doesn't, so the value
of "window.event" is undefined.

It is possible to see this difference
"in action".

In IE, use Script Debugger to set a
breakpoint inside the body of rebuild().
After pressing the red reset button,
the breakpoint is reached the first
time with the parameter "callback" set
to a function. The second time the
breakpoint is reached, the parameter
"callback" is set to an _event_.
Thus the subsequent call to callback()
generates an exception.

Now do the same think in Firefox
using Firebug. The second
time the breakpoint is reached,
the parameter "callback" is
_undefined_, and thus _not invoked_
as a function.

And yes, although the fix is trivial,
this took me a very long time
to figure out - but at least I
learnt quite a lot along the way.]

Index: web/intermap/scripts/im_integration.js

--- web/intermap/scripts/im_integration.js (revision 1335)
+++ web/intermap/scripts/im_integration.js (working copy)
@@ -267,7 +267,7 @@
         im_bm.setBBox_dom(req.responseXML);
         im_mm.setBBox_dom(req.responseXML);

- im_bm.rebuild(im_mm.rebuild.bindAsEventListener(im_mm));
+ im_bm.rebuild(im_mm.rebuild.bind(im_mm));

         // TODO: reset AoI also?
  }

--
Richard Walker
Software Improvements Pty Ltd
Phone: +61 2 6273 2055
Fax: +61 2 6273 2082