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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jun 29 05:28:22 EDT 2010


Author: christoph
Date: 2010-06-29 09:28:22 +0000 (Tue, 29 Jun 2010)
New Revision: 6431

Modified:
   trunk/mapbender/lib/wizard.js
Log:


Modified: trunk/mapbender/lib/wizard.js
===================================================================
--- trunk/mapbender/lib/wizard.js	2010-06-28 08:56:59 UTC (rev 6430)
+++ trunk/mapbender/lib/wizard.js	2010-06-29 09:28:22 UTC (rev 6431)
@@ -2,121 +2,123 @@
 /*
  * Link between various interfaces, imagine a wizard
  */
-$.fn.wizard = function (options) {
-	var args = arguments;
-	return this.each(function () {
-		var getPath = function ($t) {
-			var m = $t.metadata({
-				type: "attr",
-				name: "data"
-			});
-			var p = [];
-			if (m && m.path) {
-				p = m.path.split("/");
-			}
-			o.onClickLink(p);			
-		};
+$.widget("mb.wizard", {
+	_create: function () {
+		var args = arguments;
+		return this.each(function () {
+			var getPath = function ($t) {
+				var m = $t.metadata({
+					type: "attr",
+					name: "data"
+				});
+				var p = [];
+				if (m && m.path) {
+					p = m.path.split("/");
+				}
+				o.onClickLink(p);			
+			};
+			
+			var navigate = function ($t) {
+				if (o.fade) {
+					$t.siblings("div").fadeOut(function () {
+						$t.fadeIn();
+					});
+				}		
+				else {
+					$t.siblings("div").hide();
+					$t.show();
+				}
+			};
+	
+			var clickHandler = function (e, $t) {
+				getPath($t);
+				navigate($t);
+				if (e) {
+					e.preventDefault();
+				}
+			};
 		
-		var navigate = function ($t) {
-			if (o.fade) {
-				$t.siblings("div").fadeOut(function () {
-					$t.fadeIn();
+			var to = function () {
+				if (arguments.length === 2) {
+					var $target = arguments[1];
+					var href = "#" + $target.attr("id");
+					var me = null;
+					var e = null;
+				}
+				else {
+					var href = $(this).attr("href");
+					var $target = $(href);
+					var me = this;
+					var e = arguments[0];
+				}
+				var found = false;
+				var abort = false;
+				$target.parents().each(function () {
+					if (abort || found) {
+						return;
+					}
+					var $currentElement = $(this);
+					// not this target's wizard
+					if ($(this).data("isWizard") && this !== wizardInstance) {
+						abort = true;
+						return;
+					}				
+					// this target's wizard
+					if ($(this).data("isWizard") && this === wizardInstance) {
+						found = true;
+						return;
+					}				
 				});
-			}		
-			else {
-				$t.siblings("div").hide();
-				$t.show();
-			}
-		};
-
-		var clickHandler = function (e, $t) {
-			getPath($t);
-			navigate($t);
-			if (e) {
-				e.preventDefault();
-			}
-		};
+				if (abort || !found) {
+					new Mapbender.Warning("not this target's wizard, or not found, aborting");
+					return;
+				}
 	
-		var to = function () {
-			if (arguments.length === 2) {
-				var $target = arguments[1];
-				var href = "#" + $target.attr("id");
-				var me = null;
-				var e = null;
-			}
-			else {
-				var href = $(this).attr("href");
-				var $target = $(href);
-				var me = this;
-				var e = arguments[0];
-			}
-			var found = false;
-			var abort = false;
-			$target.parents().each(function () {
-				if (abort || found) {
+				var proceed = me === null ? true : o.onBeforeClickLink(e, $(me));
+				if (proceed === false) {
+					new Mapbender.Warning("Clicked link " + href + " in wizard " + wizardInstance.id + " aborted!");
 					return;
 				}
-				var $currentElement = $(this);
-				// not this target's wizard
-				if ($(this).data("isWizard") && this !== wizardInstance) {
-					abort = true;
+				
+				new Mapbender.Warning("Clicked link " + href + " in wizard " + wizardInstance.id);
+				clickHandler(e, $target);
+			};
+	
+			if (typeof options === "string") {
+				if (!$(this).data("isWizard")) {
 					return;
-				}				
-				// this target's wizard
-				if ($(this).data("isWizard") && this === wizardInstance) {
-					found = true;
-					return;
-				}				
-			});
-			if (abort || !found) {
-				new Mapbender.Warning("not this target's wizard, or not found, aborting");
+				}
+				var wizardInstance = this;
+				var o = $(this).data("wizardOptions");
+				if (options === "to" && args.length === 2) {
+					return to(null, args[1]);
+				}
 				return;
 			}
-
-			var proceed = me === null ? true : o.onBeforeClickLink(e, $(me));
-			if (proceed === false) {
-				new Mapbender.Warning("Clicked link " + href + " in wizard " + wizardInstance.id + " aborted!");
-				return;
-			}
+	
+			var wizardInstance = this;
+			var $wiz = $(wizardInstance);
+			$wiz.data("isWizard", true);
+	
+			var o = $.extend({
+				fade: false,
+				onClickLink: function () {
+					return true;
+				},
+				onBeforeClickLink: function () {
+					return true;
+				}
+			}, options || {});
+			$wiz.data("wizardOptions", o);
+	
 			
-			new Mapbender.Warning("Clicked link " + href + " in wizard " + wizardInstance.id);
-			clickHandler(e, $target);
-		};
-
-		if (typeof options === "string") {
-			if (!$(this).data("isWizard")) {
-				return;
+			if (o.startWith) {
+				getPath(o.startWith);
 			}
-			var wizardInstance = this;
-			var o = $(this).data("wizardOptions");
-			if (options === "to" && args.length === 2) {
-				return to(null, args[1]);
-			}
-			return;
-		}
-
-		var wizardInstance = this;
-		var $wiz = $(wizardInstance);
-		$wiz.data("isWizard", true);
-
-		var o = $.extend({
-			fade: false,
-			onClickLink: function () {
-				return true;
-			},
-			onBeforeClickLink: function () {
-				return true;
-			}
-		}, options || {});
-		$wiz.data("wizardOptions", o);
-
-		
-		if (o.startWith) {
-			getPath(o.startWith);
-		}
-
-		$("a.wizard").live("click", function (e) {
-			to.apply($(this), [e]);
-		});
-	});
-};
\ No newline at end of file
+	
+			$("a.wizard").live("click", function (e) {
+				to.apply($(this), [e]);
+			});
+		});		
+	}
+});



More information about the Mapbender_commits mailing list