[Mapbender-commits] r1898 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Dec 6 08:47:55 EST 2007
Author: christoph
Date: 2007-12-06 08:47:55 -0500 (Thu, 06 Dec 2007)
New Revision: 1898
Added:
trunk/mapbender/http/javascripts/event.js
Log:
included event.js
Added: trunk/mapbender/http/javascripts/event.js
===================================================================
--- trunk/mapbender/http/javascripts/event.js (rev 0)
+++ trunk/mapbender/http/javascripts/event.js 2007-12-06 13:47:55 UTC (rev 1898)
@@ -0,0 +1,108 @@
+/**
+ * An event. What happens, when the event occurs, depends on which functions have been
+ * registered with the event.
+ */
+var MapbenderEvent = function () {
+
+ // public
+ /**
+ * A function that needs to be executed, when the event occurs, has to be
+ * registered via this function.
+ */
+ this.register = function(aFunction, aPriority) {
+ var e = new Mb_notice("MapbenderEvent: registering " + aFunction);
+
+ if (typeof(aFunction) == "function") {
+ var mpbnFunction = new MapbenderFunction(aFunction, aPriority);
+ functionArray.push(mpbnFunction);
+
+ // unfortunately, there is no way of using static variables in JS...
+ sortFunction = mpbnFunction.getSortFunction();
+ }
+ };
+
+ /**
+ * This function triggers the event
+ */
+ this.trigger = function(properties) {
+ var e = new Mb_notice("MapbenderEvent: triggering " + this);
+ propertiesObj = properties;
+ functionArray.sort(sortFunction);
+ for (var i = 0; i < functionArray.length; i++) {
+ // executes the function at position i
+ functionArray[i].execute(propertiesObj);
+ }
+ };
+
+ this.getProperties = function () {
+ return propertiesObj;
+ }
+
+ // private
+ /**
+ * these functions will be executed once the event is triggered
+ */
+ var functionArray = [];
+
+ /**
+ * the functionArray will be sorted using this function
+ */
+ var sortFunction;
+
+ var propertiesObj;
+
+ // constructor
+};
+
+/**
+ * A MapbenderFunction is a function with a priority.
+ */
+var MapbenderFunction = function (aFunction, aPriority) {
+
+ // public
+ /**
+ * Returns the function itself
+ */
+ this.getFunction = function () {
+ return func;
+ };
+
+ /**
+ * Returns the functions priority
+ */
+ this.getPriority = function () {
+ return priority;
+ };
+
+ /**
+ * Executes the function
+ */
+ this.execute = function (argumentObj) {
+ var e = new Mb_notice("MapbenderFunction: executing " + this);
+ return func(argumentObj);
+ }
+ /**
+ * Returns a sort function for Mapbender functions. Sorted by priority.
+ */
+ this.getSortFunction = function () {
+ var mapbenderFunctionSort = function (functionA, functionB) {
+ return functionA.getPriority() - functionB.getPriority();
+ };
+ return mapbenderFunctionSort;
+ };
+
+ // private
+ var func = aFunction;
+
+ // constructor
+ /**
+ * priority is a number, lower number means higher priority.
+ * Maybe use 0-9, then 5 could be a default.
+ */
+ if (typeof(aPriority) != "number") {
+ var priority = 5;
+ }
+ else {
+ var priority = aPriority;
+ }
+};
\ No newline at end of file
More information about the Mapbender_commits
mailing list