[Mapbender-commits] r4066 - in trunk/mapbender/http: include javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jun 22 06:49:13 EDT 2009


Author: christoph
Date: 2009-06-22 06:49:13 -0400 (Mon, 22 Jun 2009)
New Revision: 4066

Added:
   trunk/mapbender/http/include/dyn_js_object.php
Modified:
   trunk/mapbender/http/javascripts/map.php
   trunk/mapbender/http/javascripts/mod_zoomIn1.php
Log:
Mapbender elements as jquery plugins

http://baudson.cute-ice.de/serendipity/index.php?/archives/30-Mapbender-a-set-of-jQuery-plugins.html


Added: trunk/mapbender/http/include/dyn_js_object.php
===================================================================
--- trunk/mapbender/http/include/dyn_js_object.php	                        (rev 0)
+++ trunk/mapbender/http/include/dyn_js_object.php	2009-06-22 10:49:13 UTC (rev 4066)
@@ -0,0 +1,62 @@
+<?php
+# $Id: dyn_js.php 3850 2009-04-03 09:02:12Z christoph $
+# $Header: /cvsroot/mapbender/mapbender/http/classes/class_wfs.php,v 1.15 2006/03/09 13:55:46 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+if (isset($gui_id)) {
+	$sql = "SELECT * FROM gui_element_vars WHERE fkey_e_id = $1 AND fkey_gui_id = $2 and var_type='var'";
+	$v = array($e_id, $gui_id);
+	$t = array('s', 's');
+   	$res = db_prep_query($sql, $v, $t);
+	$arrays = array();
+	$varArray = array();
+	while ($row = db_fetch_array($res)) {
+		if (mb_strpos($row["var_name"], "[")) {
+			$arrayname = mb_substr($row["var_name"], 0, mb_strpos($row["var_name"], "["));
+			
+			if (!in_array($arrayname, $arrays)) {
+				$i++;
+				$arrays[$i] = $arrayname;
+				$varArray[]= $arrayname  . ": []";
+			}
+		}
+		if (is_numeric(stripslashes($row["var_value"]))) {
+			$varArray[]= $row["var_name"].": ".stripslashes($row["var_value"]);
+		}
+		elseif (strpos(stripslashes($row["var_value"]), "[") === 0 || 
+				strpos(stripslashes($row["var_value"]), "{") === 0) {
+			$varArray[]= $row["var_name"].": ".stripslashes($row["var_value"]);
+		}
+		else {
+			$varArray[]= $row["var_name"].": '" . 
+				str_replace(
+					array('"',"'", "\r", "\n", "\0"), 
+					array('\"','\\\'','\r', '\n', '\0'), 
+					stripslashes($row["var_value"])
+				) .	"'";
+		}
+	}
+	echo "$.extend(options, {";
+	echo implode(",\n", $varArray);
+	echo "});";
+}
+else {
+	$e = new mb_exception("Application ID not set while retrieving element vars of module " . $e_id);
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/javascripts/map.php
===================================================================
--- trunk/mapbender/http/javascripts/map.php	2009-06-20 07:06:16 UTC (rev 4065)
+++ trunk/mapbender/http/javascripts/map.php	2009-06-22 10:49:13 UTC (rev 4066)
@@ -148,8 +148,16 @@
 //
 
 $modulesNotRelyingOnGlobalsArray = explode(",", MODULES_NOT_RELYING_ON_GLOBALS);
-
-echo "\nMapbender.Modules = {};\n";
+?>
+Mapbender.Modules = {};
+Mapbender.addModule = function (name, obj) {
+	if (name && !Mapbender.Modules[name]) {	
+		Mapbender.Modules[name] = obj;
+		return true;
+	}
+	return false;
+};
+<?php
 $mb_sql = "SELECT DISTINCT e_js_file, e_id, e_src, e_target, e_pos, " .
 		"e_url, e_left, e_top, e_width, e_height, e_requires FROM gui_element WHERE e_public = 1 AND " .
 		"fkey_gui_id = $1 ORDER BY e_pos";
@@ -160,14 +168,51 @@
 	if($row_js["e_js_file"] != ""){
 		$jsArray = explode(",", $row_js["e_js_file"]);
 		for ($i = 0; $i < count($jsArray); $i++) {
-			$e_id = $row_js["e_id"];
+			$e_id = isset($row_js["e_id"]) ? $row_js["e_id"] : "";
 			$e_src = $row_js["e_src"];
 			$e_require = $row_js["e_requires"];
 			$e_target = explode(",",$row_js["e_target"]);
 			$e_width = intval($row_js["e_width"]);
 			$e_height = intval($row_js["e_height"]);
+			$e_top = intval($row_js["e_top"]);
+			$e_left = intval($row_js["e_left"]);
 			$currentFile = trim($jsArray[$i]);
-			if (file_exists($currentFile)) {
+			if (!file_exists($currentFile)) {
+				$e = new mb_exception("Javascript not found: " . $currentFile);
+				echo "var e = new Mb_exception('Javascript not found: " . $currentFile . "');";
+				die;
+			}
+			if (in_array($e_id, $modulesNotRelyingOnGlobalsArray)) {
+				echo <<<JS
+
+var options = {
+	id:"$e_id",
+	target:"$e_target",
+	top:$e_top,
+	left:$e_left,
+	width:$e_width,
+	height:$e_height,
+	src:"$e_src"
+};
+
+JS;
+				include "../include/dyn_js_object.php";
+				echo <<<JS
+				
+$.fn.$e_id = function (options) {
+	return this.each(function () {
+
+JS;
+		require($currentFile);
+				echo <<<JS
+
+	});
+}
+
+$("#$e_id").$e_id(options);
+JS;
+			}
+			else {
 				echo "Mapbender.Modules." . $e_id . " = {\n";
 				echo "id:'".$row_js["e_id"]."',";
 				echo "url:'".$row_js["e_url"]."',";
@@ -175,31 +220,10 @@
 				echo "left:'".$row_js["e_left"]."',";
 				echo "width:'".$row_js["e_width"]."',";
 				echo "height:'".$row_js["e_height"]."'";
-				if (in_array($e_id, $modulesNotRelyingOnGlobalsArray)) {
-					echo ",\ninit : function () {\n";
-					require($currentFile);
-					echo "}\n";
-					echo "};\n";
-				}
-				else {
-					echo "};\n";
-					require($currentFile);
-				}
+				echo "};\n";
+				require($currentFile);
 			}
-			else {
-				$e = new mb_exception("Javascript not found: " . $currentFile);
-				echo "var e = new Mb_exception('Javascript not found: " . $currentFile . "');";
-				die;
-			}
 		}
 	}
 }
-?>
-eventBeforeInit.register(function () {
-	for (var module in Mapbender.Modules) {
-		var initFunction = Mapbender.Modules[module].init;
-		if (typeof(initFunction) == "function") {
-			Mapbender.Modules[module].init();
-		}
-	}
-});
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/javascripts/mod_zoomIn1.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_zoomIn1.php	2009-06-20 07:06:16 UTC (rev 4065)
+++ trunk/mapbender/http/javascripts/mod_zoomIn1.php	2009-06-22 10:49:13 UTC (rev 4066)
@@ -16,30 +16,21 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
 ?>
-var zoomin1Id = '<?php echo $e_id; ?>';
-var mod_zoom1_img = new Image(); 
-mod_zoom1_img.src = "<?php  echo $e_src;  ?>";
-var mod_zoom1_img_over = new Image(); 
-mod_zoom1_img_over.src = "<?php  echo preg_replace("/_off/","_over",$e_src);  ?>";
-
-var $zoomin1Button = $("#"+zoomin1Id);
-
-$zoomin1Button.click(function () {
-	zoom("<?php  echo $e_target[0];  ?>", true, 2.0);
-});
-
-function mod_zoomIn1_init(obj){
-	document.getElementById("zoomIn1").src = mod_zoom1_img_over.src;
-	obj.onmouseover = new Function("mod_zoomIn1_over()");
-	obj.onmouseout = new Function("mod_zoomIn1_out()");
-}
-function mod_zoomIn1_over(){
-	document.getElementById("zoomIn1").src = mod_zoom1_img_over.src;
-}
-function mod_zoomIn1_out(){
-	document.getElementById("zoomIn1").src = mod_zoom1_img.src;
-}
-
+$(this).click(function () {
+	if (!options.target) {
+		return;
+	}
+	if (!Mapbender.Modules[options.target]) {
+		return;	
+	}
+	Mapbender.Modules[options.target].zoom(true, 2.0);
+}).mouseover(function () {
+	if (options.src) {
+		this.src = options.src.replace(/_off/, "_over");
+	}
+}).mouseout(function () {
+	if (options.src) {
+		this.src = options.src;
+	}
+});
\ No newline at end of file



More information about the Mapbender_commits mailing list