[OpenLayers-Dev] [OpenLayers-Trac] [OpenLayers] #880: Event
object conflict
Paul Spencer
pspencer at dmsolutions.ca
Sat Aug 4 12:33:04 EDT 2007
Chris, this seems like a reasonable approach. An enhancement would
be to add methods from OpenLayers.Event to window.Event if it exists,
but only if the method doesn't already exist.
I've used something like this:
function extendObj(destination, source) {
for (property in source) {
if (typeof destination[property] == 'undefined') {
destination[property] = source[property];
}
}
}
then the code could be:
if (window.Event) {
extendObj(window.Event, OpenLayers.Event);
} else {
var Event = OpenLayers.Event;
}
This would be safe enough to ensure that the methods are available on
window.Event regardless of the toolkit being used (it might not only
be prototype that causes this problem)
Cheers
Paul
On 4-Aug-07, at 8:48 AM, Christopher Schmidt wrote:
> Paul --
>
> Can you glance at this and offer feedback? I think this answers your
> questions, and perhaps adequately resolves them until 3.0?
>
> -- Chris
>
> On Sat, Aug 04, 2007 at 12:45:29PM -0000, OpenLayers wrote:
>> #880: Event object conflict
>> Comment (by crschmidt):
>>
>> The reason for originally having Event in the main namespace is
>> that we
>> had encouraged people (through 2.0, I think) to use Event.stop in
>> their
>> client code. We now only use OpenLayers.Event internally, but we
>> wanted to
>> ensure that users who had used 'Event.stop' would not have their
>> applications break.
>>
>> Looking at the prototype code, it seems like Prototype will
>> extend any
>> Event object it finds. This means that we should, I think, be
>> able to
>> change:
>>
>> if (window.Event) {
>> OpenLayers.Util.extend(window.Event, OpenLayers.Event);
>> } else {
>> var Event = OpenLayers.Event;
>> }
>>
>> to just:
>>
>> if (!window.Event) {
>> var Event = OpenLayers.Event;
>> }
>>
>> That way, users who are not using Prototype and are using
>> Event.stop will
>> get their stop still.
>>
>> Then, in 3.0, we remove it.
>
>
>
> --
> Christopher Schmidt
> MetaCarta
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
+-----------------------------------------------------------------+
|Paul Spencer pspencer at dmsolutions.ca |
+-----------------------------------------------------------------+
|Chief Technology Officer |
|DM Solutions Group Inc http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+
More information about the Dev
mailing list