[Mapbender-commits] r5953 - trunk/mapbender/lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Apr 15 10:08:09 EDT 2010


Author: christoph
Date: 2010-04-15 10:08:09 -0400 (Thu, 15 Apr 2010)
New Revision: 5953

Modified:
   trunk/mapbender/lib/basic.js
Log:
added new use case "call api function" with 0...n parameters:

$dom.mapbender("functionName"[, arg1, arg2, ...])

the chain is NOT broken!

Modified: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js	2010-04-15 14:06:19 UTC (rev 5952)
+++ trunk/mapbender/lib/basic.js	2010-04-15 14:08:09 UTC (rev 5953)
@@ -62,7 +62,7 @@
 
 $.fn.mapbender = function () {
 	var id = this.attr("id");
-	
+
 	// Return the whole API object
 	if (arguments.length === 0) {
 		return Mapbender.modules[id];
@@ -85,6 +85,10 @@
 			new Mb_exception("Module " + id + " is not present!");
 			return null;
 		}
+		if (typeof module[arguments[0]] === "function") {
+			module[arguments[0]]();
+			return this;
+		}
 		return module[arguments[0]];
 	}
 	// Set an attribute
@@ -95,6 +99,15 @@
 			new Mb_exception("Module " + id + " is not present!");
 			return null;
 		}
+		if (typeof module[arguments[0]] === "function") {
+			if (typeof arguments[1] === "object") {
+				module[arguments[0]].apply(arguments[1]);
+			}
+			else {
+				module[arguments[0]].call(arguments[1]);
+			}
+			return this;
+		}
 		module[arguments[0]] = arguments[1];
 		return this;
 	}
@@ -112,6 +125,21 @@
 			return closure.call(module);
 		});
 	}
+	else if (arguments.length > 2 && typeof arguments[0] === "string") {
+		var module = this.data("api");
+
+		if (typeof module === "undefined") {
+			new Mb_exception("Module " + id + " is not present!");
+			return null;
+		}
+		var closure = module[arguments[0]];
+		if (typeof closure === "function") {
+			var args = Array.prototype.slice.call(arguments);
+			args.shift();
+			closure.apply(module, args);
+		}
+		return this;		
+	}
 };
 
 /**



More information about the Mapbender_commits mailing list