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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 6 09:44:59 EST 2010


Author: christoph
Date: 2010-01-06 09:44:56 -0500 (Wed, 06 Jan 2010)
New Revision: 5290

Modified:
   trunk/mapbender/lib/basic.js
   trunk/mapbender/lib/core.js
Log:


Modified: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js	2010-01-06 09:30:28 UTC (rev 5289)
+++ trunk/mapbender/lib/basic.js	2010-01-06 14:44:56 UTC (rev 5290)
@@ -1,3 +1,63 @@
+//
+// custom jQuery selectors
+//
+$.expr[":"].maps = function (obj) {
+	return ($(obj).data('isMap') === true);
+};
+
+$.expr[":"].modules = function (obj) {
+	return (typeof $(obj).mapbender() !== "undefined");
+};
+
+//
+// mapbender jQuery plugin
+//
+$.fn.mapbender = function () {
+	var id = this.attr("id");
+	
+	// Return the whole API object
+	if (arguments.length === 0) {
+		return Mapbender.modules[id];
+	}
+	// Add API functionality (parameter is API object)
+	else if (arguments.length === 1 && typeof arguments[0] === "object") {
+		var obj = arguments[0];
+		Mapbender.modules[id] = $.extend(
+			obj,
+			Mapbender.modules[id]
+		);
+		return this.data("api", Mapbender.modules[id]);
+		
+	}
+	// Get a value from an attribute
+	else if (arguments.length === 1 && typeof arguments[0] === "string") {
+		var attr = arguments[0];	
+
+		var module = this.data("api");
+
+		if (typeof module === "undefined") {
+			new Mb_exception("Module " + id + " is not present!");
+			return null;
+		}
+		return module[attr];
+	}
+	// Use API functionality
+	else if (arguments.length === 1 && typeof arguments[0] === "function") {
+		var closure = arguments[0];	
+		
+		return this.each(function () {
+			var module = $(this).data("api");
+
+			if (typeof module === "undefined") {
+				new Mb_exception("Module " + id + " is not present!");
+				return this;
+			}
+			return closure.call(module)
+		});
+	}
+};
+
+
 var clickX;
 var clickY;
 

Modified: trunk/mapbender/lib/core.js
===================================================================
--- trunk/mapbender/lib/core.js	2010-01-06 09:30:28 UTC (rev 5289)
+++ trunk/mapbender/lib/core.js	2010-01-06 14:44:56 UTC (rev 5290)
@@ -179,7 +179,7 @@
 }
 
 /**
- * @deprecated, use Mapbender.modules[module_id]
+ * @deprecated, use $("#module_id:maps")
  */
 var mb_mapObj = [];
 



More information about the Mapbender_commits mailing list