Author: nbelaevski
Date: 2010-07-10 07:46:53 -0400 (Sat, 10 Jul 2010)
New Revision: 17804
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
root/core/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
Log:
https://jira.jboss.org/browse/RF-8882
Modified: root/core/trunk/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2010-07-10
10:55:46 UTC (rev 17803)
+++
root/core/trunk/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2010-07-10
11:46:53 UTC (rev 17804)
@@ -21,6 +21,7 @@
package org.richfaces.component.util;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.util.HtmlDimensions;
@@ -64,6 +65,10 @@
return HtmlDimensions.formatPx(new Double(decoded.doubleValue() +
doubleDelta.doubleValue()));
}
+ private static String escapeReplacement(String s) {
+ return s.replaceAll("(\\\\|\\$)", "\\\\$1");
+ }
+
public static String expandIdSelector(String selector, UIComponent component,
FacesContext context) {
Matcher matcher = ID_SELECTOR_PATTERN.matcher(selector);
StringBuffer sb = new StringBuffer();
@@ -75,7 +80,7 @@
UIComponent target = RendererUtils.getInstance().findComponentFor(context,
component, unescaped);
if (target != null) {
- matcher.appendReplacement(sb, "#" +
target.getClientId(context).replaceAll(":", "\\\\\\\\:"));
+ matcher.appendReplacement(sb, escapeReplacement("#" +
ScriptUtils.escapeCSSMetachars(target.getClientId(context))));
}
}
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-07-10
10:55:46 UTC (rev 17803)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-07-10
11:46:53 UTC (rev 17804)
@@ -1,16 +1,18 @@
-/**
- * Global object container for RichFaces API.
- * All classes should be defined here.
- * @class
- * @name RichFaces
- * @static
- *
- * */
-window.RichFaces = {};
+if (!window.RichFaces) {
+ /**
+ * Global object container for RichFaces API.
+ * All classes should be defined here.
+ * @class
+ * @name RichFaces
+ * @static
+ *
+ * */
+ window.RichFaces = {};
+}
(function(jQuery, richfaces) {
-
+
// get DOM element by id or DOM element or jQuery object
richfaces.getDomElement = function (source) {
var type = typeof source;
@@ -22,7 +24,7 @@
if (source.nodeType) {
// DOM element
element = source;
- } else
+ } else
if (source instanceof jQuery) {
// jQuery object
element = source.get(0);
@@ -30,7 +32,7 @@
}
return element;
}
-
+
// get RichFaces component object by component id or DOM element or jQuery object
richfaces.$ = function (source) {
var element = richfaces.getDomElement(source);
@@ -39,7 +41,7 @@
return (element["richfaces"] || {})["component"];
}
}
-
+
// find component and call his method
richfaces.invokeMethod = function(source, method) {
var c = richfaces.$(source);
@@ -66,7 +68,7 @@
}
}
}
-
+
//form.js
richfaces.submitForm = function(form, parameters, target) {
if (typeof form === "string") { form = jQuery(form) };
@@ -124,23 +126,23 @@
return out;
};
- //there is the same pattern in server-side code:
+ //there is the same pattern in server-side code:
//org.ajax4jsf.javascript.ScriptUtils.escapeCSSMetachars(String)
var CSS_METACHARS_PATTERN = /([#;&,.+*~':"!^$[\]()=>|\/])/g;
/**
- * Escapes CSS meta-characters in string according to
+ * Escapes CSS meta-characters in string according to
* <a
href="http://api.jquery.com/category/selectors/">jQuery
selectors</a> document.
- *
+ *
* @param s - string to escape meta-characters in
* @return string with meta-characters escaped
*/
richfaces.escapeCSSMetachars = function(s) {
//TODO nick - cache results
-
+
return s.replace(CSS_METACHARS_PATTERN, "\\$1");
};
-
+
richfaces.log = (function(jQuery) {
var LOG_LEVELS = {'debug': 1, 'info': 2, 'warn': 3,
'error': 4};
var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info':
'blue', 'warn': 'gold', 'error': 'red'};
@@ -345,9 +347,9 @@
var interval = options.pollinterval;
var ontimer = options.ontimer;
richfaces.stopPoll(pollId);
-
+
richfaces.setZeroRequestDelay(options);
-
+
pollTracker[pollId] = window.setTimeout(function(){
var pollElement = document.getElementById(pollId);
try {
@@ -365,7 +367,7 @@
delete pollTracker[id];
}
};
-
+
var pushTracker = {};
richfaces.startPush = function(options) {
@@ -375,7 +377,7 @@
var interval = options.interval;
var ondataavailable = options.ondataavailable;
richfaces.setZeroRequestDelay(options);
-
+
richfaces.stopPush(pushId);
pushTracker[pushId] = setTimeout(function() { // TODO: define this function in
richfaces object to avoid definition every time when call startPush
@@ -482,7 +484,7 @@
options.requestDelay = 0;
}
};
-
+
var getGlobalStatusNameVariable = function() {
return richfaces.statusName;
}
@@ -560,7 +562,7 @@
richfaces.ajax = function(source, event, options) {
var sourceId = (typeof source == 'object' && source.id) ? source.id :
source;
-
+
options = options || {};
parameters = options.parameters || {}; // TODO: change "parameters" to
"richfaces.ajax.params"
@@ -608,7 +610,7 @@
parameters['onevent'] = eventsAdapter;
parameters['onerror'] = eventsAdapter;
}
-
+
if (richfaces.queue) {
parameters.queueId = options.queueId;
}
@@ -768,7 +770,7 @@
}
};
}()));
-
+
var ajaxOnComplete = function (data) {
var type = data.type;
var responseXML = data.responseXML;
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2010-07-10
10:55:46 UTC (rev 17803)
+++
root/core/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2010-07-10
11:46:53 UTC (rev 17804)
@@ -66,7 +66,7 @@
}
public void testExpandIdSelector() {
- String selector = ".class_form+#-Test .class2 #_aaaa";
+ String selector = ".class_form+#-Test #form\\:element .class2 #_aaaa";
UIComponent component = new UIComponentBase() {
public String getFamily() {
@@ -77,7 +77,7 @@
if ("-Test".equals(expr)) {
return new UIComponentBase() {
public String getClientId(FacesContext context) {
- return "component1";
+ return "component$1";
}
public String getFamily() {
@@ -103,7 +103,7 @@
};
String string = HtmlUtil.expandIdSelector(selector, component, null);
- assertEquals(".class_form+#component1 .class2 #component2", string);
+ assertEquals(".class_form+#component\\$1 #form\\:element .class2
#component2", string);
String s = ".class_form+.component1 .class2 #1component2";