I am trying to add javascript with the "JQBehaviours.js()"
functionality, but it keeps on missing the trailing ";":
the rendered output is this:
<script type="text/javascript" id="31612d17-743e-4dd6-
b567-5685b83bc3a2">
/*<![CDATA[*/
var jQuery = jQuery.noConflict();
jQuery(document).ready(function(){jQuery('#navigationfilter').keyup(
function(){
var count = 0;
jQuery('.navigation a').each(function () {
if(jQuery(this).text().search(new
RegExp(jQuery('#navigationfilter').val(), 'i')) < 0 ){
jQuery(this).parents('.wicket-tree-
content').addClass('hidden');
}else{
jQuery(this).parents('.wicket-tree-
content').removeClass('hidden');
count++;
}
});
//detach children from the navigation, sort them and append
them again
//(we have a <wicket:panel> element around the children)
var hiddenItems = jQuery('.hidden');
hiddenItems.detach();
hiddenItems.sort(
function(a,b) {
var condA = jQuery(a).hasClass('hidden');
var condB = jQuery(b).hasClass('hidden');
var result = 0;
if(condA == condB){
result = -1;
}
if(condA != condB){
result = 1;
}
return result;
});
hiddenItems.appendTo(jQuery('.navigation').children());
});}) /* <- Missing a ";" !? */
/*]]>*/
</script>
The "JAVA" source would be:
<code>
add(JQBehaviors.js("jQuery('#navigationfilter').keyup(\n" +
" function(){\n" +
" var count = 0;\n" +
" jQuery('.navigation a').each(function () {\n"
+
" if(jQuery(this).text().search(new
RegExp(jQuery('#navigationfilter').val(), 'i')) < 0 ){\n" +
" jQuery(this).parents('.wicket-tree-
content').addClass('hidden');\n" +
" }else{\n" +
" jQuery(this).parents('.wicket-tree-
content').removeClass('hidden');\n" +
" count++;\n" +
" }\n" +
" });\n" +
"\n" +
" //detach children from the navigation, sort
them and append them again\n" +
" //(we have a <wicket:panel> element around the
children)\n" +
" var hiddenItems = jQuery('.hidden');\n" +
" hiddenItems.detach();\n" +
" hiddenItems.sort(\n" +
" function(a,b) {\n" +
" var condA =
jQuery(a).hasClass('hidden');\n" +
" var condB =
jQuery(b).hasClass('hidden');\n" +
" var result = 0;\n" +
"\n" +
" if(condA == condB){\n" +
" result = -1;\n" +
" }\n" +
" if(condA != condB){\n" +
" result = 1;\n" +
" }\n" +
"\n" +
" return result;\n" +
" });\n" +
"
hiddenItems.appendTo(jQuery('.navigation').children());\n" +
"})"));
</code>
Why I am trying to do it like this:
1.) I tried some time to write this in the jwicket "jquery" syntax,
but simply wasn't able to translate it :)
2.) When loading this script from a file, jquery is always imported
later. Wicket's Footer js injection isn't working the way it is
described with the way our basepage is used.
add(new JQBehavior(S.id("navigationfilter").to$().keyup(JQuery.
$f("filterList();"))));
and:
@Override
public void renderHead(final IHeaderResponse response) {
super.renderHead(response);
response.renderJavaScriptReference(new
JavaScriptResourceReference(BasePage.class, "js/navfilter.js"));