[Mapbender-commits] r2706 - branches/testbaudson_dev/lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 23 09:27:56 EDT 2008


Author: christoph
Date: 2008-07-23 09:27:56 -0400 (Wed, 23 Jul 2008)
New Revision: 2706

Modified:
   branches/testbaudson_dev/lib/event.js
Log:
changed structure

Modified: branches/testbaudson_dev/lib/event.js
===================================================================
--- branches/testbaudson_dev/lib/event.js	2008-07-23 11:35:25 UTC (rev 2705)
+++ branches/testbaudson_dev/lib/event.js	2008-07-23 13:27:56 UTC (rev 2706)
@@ -17,51 +17,60 @@
  * 
  */
 var MapbenderEvent = function () {
+	this.init();
+};
+
+MapbenderEvent.prototype = {
+	init : function () {
+		this.functionArray = [];
+		this.propertiesObj = {};
+		this.log = false;
+	},
 	
-	// public methods
 	/**
 	 * A function that needs to be executed, when the event occurs, has to be 
 	 * registered via this function.
 	 */
-	this.register = function(aFunction) {
+	register : function(aFunction) {
 
 		var mpbnFunction = new MapbenderFunction(aFunction);
-		functionArray.push(mpbnFunction);
-	};
+		this.functionArray.push(mpbnFunction);
+		console.log(this.functionArray);
+	},
 
 	/**
 	 * Exclude a previously registered function from the event
 	 */
-	this.unregister = function(aFunction) {
-		for (var i = 0, len = functionArray.length; i < len; i++) {
-			if (functionArray[i].getFunction() === aFunction) {
+	unregister : function(aFunction) {
+		for (var i = 0, len = this.functionArray.length; i < len; i++) {
+			if (this.functionArray[i].getFunction() === aFunction) {
 				for (var j = i + 1; j < len; j++) {
-					functionArray[j-1] = functionArray[j];
+					this.functionArray[j-1] = this.functionArray[j];
 				}
-				delete functionArray[len - 1];
+				delete this.functionArray[len - 1];
 				len = len - 1;
 			}
 		}
-		functionArray.length = len;
-	};
+		this.functionArray.length = len;
+	},
 
 	/**
 	 * Checks if a function is already registered with this event
 	 */
-	this.isRegistered = function (aFunction) {
-		for (var i = 0, len = functionArray.length; i < len; i++) {
-			if (functionArray[i].getFunction() === aFunction) {
+	isRegistered : function (aFunction) {
+		for (var i = 0, len = this.functionArray.length; i < len; i++) {
+			if (this.functionArray[i].getFunction() === aFunction) {
 				return true;
 			}
 		}
 		return false;
-	};
+	},
 	
 	/**
 	 * This function triggers the event
 	 */
-	this.trigger = function(properties, booleanOperator) {
-		if (!(functionArray.length > 0)) {
+	trigger : function(properties, booleanOperator) {
+		if (!(this.functionArray.length > 0)) {
 			return true;
 		}
 		//
@@ -106,42 +115,34 @@
 				break;
 		}
 
-		if (log) {
-			var e = new Mb_notice("functions (after sort): " + functionArray.join(","));
+		if (this.log) {
+			var e = new Mb_notice("functions (after sort): " + this.functionArray.join(","));
 		}
 
-		for (var i = 0; i < functionArray.length; i++) {
+		for (var i = 0; i < this.functionArray.length; i++) {
 			// executes the function at position i
 			// and determines the return value based on the (optional) boolean operator
 			switch (booleanOperator) {
 				case "AND":
-					result = result && functionArray[i].execute(properties);
+					result = result && this.functionArray[i].execute(properties);
 					break;
 				case "OR":
-					result = result || functionArray[i].execute(properties);
+					result = result || this.functionArray[i].execute(properties);
 					break;
 				default:
-					result = functionArray[i].execute(properties);
+					result = this.functionArray[i].execute(properties);
 					break;
 			}
 		}
 		return result;
-	};	
+	},	
 	
-	this.getProperties = function () {
-		return propertiesObj;
-	};
-
-	// private
-	/**
-	 * these functions will be executed once the event is triggered
-	 */
-	var functionArray = [];
-	
-	var propertiesObj;
-	var log = false;
+	getProperties : function () {
+		return this.propertiesObj;
+	}
 };
 
+
 /**
  * A MapbenderFunction is a function with a priority.
  */
@@ -183,6 +184,7 @@
 			str += "return " + aFunction;
 			str += "}";
 			str += "(" + argumentValues.join(", ") + "));";
+			console.log(str);
 			var returnValue = eval(str);
 			return returnValue;
 		}	



More information about the Mapbender_commits mailing list