[Mapbender-dev] Mapbender module scope in JavaScript

Christoph Baudson christoph.baudson at wheregroup.com
Fri Dec 12 10:33:29 EST 2008


Hello,

currently, Mapbender pollutes the global namespace with a lot of 
variables. We have already introduced the object Mapbender, which will 
serve as our namespace.

First of all we should move all modules under this namespace, in order 
to avoid modules overwriting their variables (it has happened in the past).

I have done some experiments today,
* In map.php, where each javascript is included, I wrapped the code 
(<js>) around sth. like

Mapbender.Modules.<elementId>.init = function () {<js>}

Mapbender.Modules.<elementId> can also hold other data like id, target 
etc, which by then had to be imported from PHP. By this, we can achieve 
to convert most modules to pure JS, which will make Mapbender less 
vulnerable (no server side interaction).

We could have an array with modules that work with this modular 
approach. For others, we would simply skip the wrapping process and 
leave them in the global namespace. This improves backwards 
compatibility and allows a gradual change.

* changed the button class and allowed it to store closures in addition 
to strings


I came across the following problems:

* most modules (buttons) use a hard wired mouse event (database), that 
links to a function in the global scope. The event handlers would have 
to be set in the module itself, not the administration. Although this 
means work, it will keep the JavaScript in the source code which is a 
good thing.

- old string-type events (mb_registerInitFunctions) will no longer work. 
However, most have already been changed to the new syntax, and it should 
not be any problem.

- all hard wired mouse events will fail. We will need to use closures 
instead. This is a good thing.


I guess this is an important step for Mapbender to become a solid 
framework. I'm glad that this change seems to be possible. Please 
comment. I would like to include this in Mapbender 2.6.

Happy weekend

Christoph

-- 

_______________________________________

W h e r e G r o u p GmbH & Co. KG

Siemensstraße 8
53121 Bonn
Germany

Christoph Baudson
Anwendungsentwickler

Fon: +49 (0)228 / 90 90 38 - 15
Fax: +49 (0)228 / 90 90 38 - 11
christoph.baudson at wheregroup.com
www.wheregroup.com
Amtsgericht Bonn, HRA 6788
_______________________________________

Komplementärin:
WhereGroup Verwaltungs GmbH
vertreten durch:
Olaf Knopp, Peter Stamm
_______________________________________



More information about the Mapbender_dev mailing list