[richfaces-svn-commits] JBoss Rich Faces SVN: r18675 - in trunk/ui/misc/ui/src/main: resources/META-INF/resources/org.richfaces and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Aug 16 14:18:04 EDT 2010


Author: nbelaevski
Date: 2010-08-16 14:18:03 -0400 (Mon, 16 Aug 2010)
New Revision: 18675

Modified:
   trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
   trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js
   trunk/ui/misc/ui/src/main/templates/jquery.template.xml
Log:
https://jira.jboss.org/browse/RF-8993

Modified: trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
===================================================================
--- trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java	2010-08-16 17:39:22 UTC (rev 18674)
+++ trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java	2010-08-16 18:18:03 UTC (rev 18675)
@@ -34,8 +34,8 @@
 import org.ajax4jsf.javascript.ScriptUtils;
 import org.ajax4jsf.renderkit.RendererUtils;
 import org.richfaces.component.AbstractJQuery;
+import org.richfaces.component.JQueryAttachType;
 import org.richfaces.component.JQueryTiming;
-import org.richfaces.component.JQueryAttachType;
 import org.richfaces.component.util.HtmlUtil;
 
 /**

Modified: trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js
===================================================================
--- trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js	2010-08-16 17:39:22 UTC (rev 18674)
+++ trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js	2010-08-16 18:18:03 UTC (rev 18675)
@@ -4,65 +4,75 @@
 
 (function(jquery, richfaces) {
 
-	var evaluateSelector = function(selector) {
+	var evaluate = function(selector) {
 		var result = selector;
 		try {
 			result = eval(selector);
 		} catch (e) {
 			//do nothing
 		}
-		return result || "";
+		return result;
 	};
 
-	var createHandler = function(handler) {
-		if (typeof handler == 'function') {
-			return handler;
-		} else {
-			return new Function("event", handler);
+	var evaluateJQuery = function(element, selector) {
+		var result = element || evaluate(selector);
+		if (!(result instanceof jquery)) {
+			result = jquery(result || "");
 		}
+		
+		return result;
 	};
-
-	var bindFunction = function(options) {
-
-		var selector = evaluateSelector(options.selector);
-		var query = options.query;
-
-		if (options.event) {
-			var handler = createHandler(query);
-
-			if (options.attachType == 'live') {
-				jQuery(selector).live(options.event, handler);
-			} else if (options.attachType == 'one') {
-				jQuery(selector).one(options.event, handler);
+	
+	var createEventHandlerFunction = function(opts) {
+		return function() {
+			var selector = evaluateJQuery(null, opts.selector);
+			selector[opts.attachType || "bind"](opts.event, null, new Function("event", opts.query));
+		};
+	};
+	
+	var createDirectQueryFunction = function(opts) {
+		var queryFunction = new Function("options", "arguments[1]." + opts.query);
+		
+		return function() {
+			var element;
+			var options;
+			
+			if (arguments.length == 1) {
+				//function(options) { ...query()... }
+				options = arguments[0];
 			} else {
-				jQuery(selector).bind(options.event, handler);
+				//function(element, options) { ...query()... }
+				element = arguments[0];
+				options = arguments[1];
 			}
+			
+			var selector = evaluateJQuery(element, opts.selector);
+			queryFunction.call(this, options, selector);
+		};
+	};
+	
+	var createQueryFunction = function(options) {
+		if (options.event) {
+			return createEventHandlerFunction(options);
 		} else {
-			var f = new Function("__locatedObject", "__locatedObject." + query);
-			f.call(this, jQuery(selector));
-			//TODO return value?
+			return createDirectQueryFunction(options);
 		}
 	};
-
-	var bind = function(options) {
-		if (options.timing == 'immediate') {
-			bindFunction(options);
+	
+	var query = function(options) {
+		if (options.timing == 'domready') {
+			jquery(document).ready(createQueryFunction(options));
 		} else {
-			jQuery(document).ready(function() {
-				bindFunction(options);
-			});
+			createQueryFunction(options).call(this);
 		}
 	};
-
+	
 	richfaces.jQuery = {
+			
+		createFunction: createQueryFunction,	
+			
+		query: query
 
-		bind: bind,
-
-		createBinder: function(options) {
-			return function() {
-				bind(options);
-			};
-		}
 	};
 
 }(jQuery, RichFaces));

Modified: trunk/ui/misc/ui/src/main/templates/jquery.template.xml
===================================================================
--- trunk/ui/misc/ui/src/main/templates/jquery.template.xml	2010-08-16 17:39:22 UTC (rev 18674)
+++ trunk/ui/misc/ui/src/main/templates/jquery.template.xml	2010-08-16 18:18:03 UTC (rev 18675)
@@ -20,10 +20,10 @@
 
 				<c:choose>
 					<c:when test="#{not empty functionName}">
-						#{functionName} = RichFaces.jQuery.createBinder(#{options});
+						#{functionName} = RichFaces.jQuery.createFunction(#{options});
 					</c:when>
 					<c:otherwise>
-						RichFaces.jQuery.bind(#{options});
+						RichFaces.jQuery.query(#{options});
 					</c:otherwise>
 				</c:choose>
 			</script>



More information about the richfaces-svn-commits mailing list