[yast-devel] WebYaST: problems with jQuery selector name - added safe_id view helper
Hi all, I found a problem in the repositories module that some jQuery commands do not work as expected. The problem happens when jQuery selector contains symbols like %&+#()[]:... Example: $('#my_id') works without problem, but $('#my_another:id') will not find the element with id="my_another:id" The correct syntax is $('#my_another\\:id') - the colon symbol has to be escaped by backslashes. See http://docs.jquery.com/Selectors for more details about jQuery selectors. Unfortunately it doesn't work correctly with '>' character even if it's escaped. More over I found that e.g. {} also have to be escaped although the documentation doesn't include them in the list. And you need to escape backslahes in JavaScript and once more in Ruby, it gets quite complicated... For this reason I have added new safe_id() function in view helper. Internally it uses Base64 encoding with some modifications of the result (no multiline output, removed padding etc...) The result is a [-a-zA-Z0-9_]* string so no HTML or JavaScript escaping is needed and of course it works correctly even with UTF-8 input string. Example usage in a view template: <!-- create a table item with ID based on id variable --> <% my_id = safe_id id -%> <td id="my_table_item_<%= my_id -%>" ... [...] <!-- create a remote function updating the table item --> <%= remote_function(:update => "#my_table_item_#{my_id}", ... %> -- Best Regards Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Mon, Mar 01, 2010 at 02:27:29PM +0100, Ladislav Slezak wrote:
Hi all,
I found a problem in the repositories module that some jQuery commands do not work as expected. The problem happens when jQuery selector contains symbols like %&+#()[]:...
http://www.w3.org/TR/html401/types.html#type-name ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). or, http://www.w3.org/TR/REC-xml/#id The ASCII symbols and punctuation marks, along with a fairly large group of Unicode symbol characters, are excluded from names... This makes me think that people had to solve it in RoR before :) ... and they did, but it works differently than we'd need: http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Infle... "a,hoj".parameterize == "a'hoj".parameterize -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
participants (2)
-
Ladislav Slezak
-
Martin Vidner