Mailinglist Archive: yast-devel (59 mails)

< Previous Next >
[yast-devel] WebYaST: problems with jQuery selector name - added safe_id view helper
  • From: Ladislav Slezak <lslezak@xxxxxxx>
  • Date: Mon, 01 Mar 2010 14:27:29 +0100
  • Message-id: <4B8BC0C1.8000803@xxxxxxx>

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@xxxxxxx
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@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups