[js] add a selector string escaping function
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 08 Oct 2013 14:02:28 +0200
changeset 9284 4c37808fd284
parent 9283 5f2c5eb1a820
child 9285 e7c94121ce9d
[js] add a selector string escaping function will help use id strings in jquery selector expressions, e.g: "foo.[subject]:42" -> "foo\.\[subject\]\:42" Related to #3154531.
web/data/cubicweb.js
--- a/web/data/cubicweb.js	Thu Oct 10 13:26:11 2013 +0200
+++ b/web/data/cubicweb.js	Tue Oct 08 14:02:28 2013 +0200
@@ -45,6 +45,15 @@
         return null;
     },
 
+    // escapes string selectors (e.g. "foo.[subject]:42" -> "foo\.\[subject\]\:42"
+    escape: function(selector) {
+        if (typeof(selector) == 'string') {
+            return  selector.replace( /(:|\.|\[|\])/g, "\\$1" );
+        }
+        // cw.log('non string selector', selector);
+        return '';
+    },
+
     getNode: function (node) {
         if (typeof(node) == 'string') {
             return document.getElementById(node);